Skip to content

Commit

Permalink
Implement saved queries and filters (#39140) (#43720)
Browse files Browse the repository at this point in the history
Introduces "saved queries". Saved queries are a new saved object type similar to saved searches but more limited in scope. They allow users to store the the query string in the query bar and optionally the set of filters and timefilter in order to reload them anywhere a query is expected: Discover, Visualize, Dashboard, anywhere that uses our full SearchBar component.
  • Loading branch information
Bargs authored Aug 21, 2019
1 parent 9452f98 commit b97a95b
Show file tree
Hide file tree
Showing 62 changed files with 2,610 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Boom from 'boom';
import { getProperty, IndexMapping } from '../../../mappings';

const TOP_LEVEL_FIELDS = ['_id'];
const TOP_LEVEL_FIELDS = ['_id', '_score'];

export function getSortingParams(
mappings: IndexMapping,
Expand Down
19 changes: 19 additions & 0 deletions src/legacy/core_plugins/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import { resolve } from 'path';
import { Legacy } from '../../../../kibana';
import { mappings } from './mappings';
import { SavedQuery } from './public';

// eslint-disable-next-line import/no-default-export
export default function DataPlugin(kibana: any) {
Expand All @@ -35,6 +37,23 @@ export default function DataPlugin(kibana: any) {
uiExports: {
injectDefaultVars: () => ({}),
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings,
savedObjectsManagement: {
query: {
icon: 'search',
defaultSearchField: 'title',
isImportableAndExportable: true,
getTitle(obj: SavedQuery) {
return obj.attributes.title;
},
getInAppUrl(obj: SavedQuery) {
return {
path: `/app/kibana#/discover?_a=(savedQuery:'${encodeURIComponent(obj.id)}')`,
uiCapabilitiesPath: 'discover.show',
};
},
},
},
},
};

Expand Down
50 changes: 50 additions & 0 deletions src/legacy/core_plugins/data/mappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const mappings = {
query: {
properties: {
title: {
type: 'text',
},
description: {
type: 'text',
},
query: {
properties: {
language: {
type: 'keyword',
},
query: {
type: 'keyword',
index: false,
},
},
},
filters: {
type: 'object',
enabled: false,
},
timefilter: {
type: 'object',
enabled: false,
},
},
},
};
1 change: 1 addition & 0 deletions src/legacy/core_plugins/data/public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

@import './filter/filter_bar/index';

@import './search/search_bar/index';
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export {
StaticIndexPattern,
} from './index_patterns';
export { Query, QueryBar, QueryBarInput } from './query';
export { SearchBar, SearchBarProps } from './search';
export { SearchBar, SearchBarProps, SavedQueryAttributes, SavedQuery } from './search';

/** @public static code */
export * from '../common';
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DataPlugin implements Plugin<DataSetup, void, DataPluginSetupDepend
indexPatterns: indexPatternsService.indexPatterns,
}),
query: this.query.setup(),
search: this.search.setup(),
search: this.search.setup(savedObjectsClient),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ describe('QueryBar', () => {
indexPatterns={[mockIndexPattern]}
store={createMockStorage()}
intl={null as any}
onChange={noop}
isDirty={false}
/>
);

Expand All @@ -125,6 +127,8 @@ describe('QueryBar', () => {
store={createMockStorage()}
disableAutoFocus={true}
intl={null as any}
onChange={noop}
isDirty={false}
/>
);

Expand All @@ -136,6 +140,8 @@ describe('QueryBar', () => {
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
onSubmit={noop}
onChange={noop}
isDirty={false}
appName={'discover'}
store={createMockStorage()}
intl={null as any}
Expand All @@ -151,6 +157,8 @@ describe('QueryBar', () => {
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
onSubmit={noop}
onChange={noop}
isDirty={false}
appName={'discover'}
store={createMockStorage()}
intl={null as any}
Expand All @@ -167,6 +175,8 @@ describe('QueryBar', () => {
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
onSubmit={noop}
onChange={noop}
isDirty={false}
appName={'discover'}
screenTitle={'Another Screen'}
store={createMockStorage()}
Expand All @@ -187,6 +197,8 @@ describe('QueryBar', () => {
uiSettings={setupMock.uiSettings}
query={kqlQuery}
onSubmit={noop}
onChange={noop}
isDirty={false}
appName={'discover'}
screenTitle={'Another Screen'}
indexPatterns={[mockIndexPattern]}
Expand All @@ -206,6 +218,8 @@ describe('QueryBar', () => {
uiSettings={setupMock.uiSettings}
query={kqlQuery}
onSubmit={noop}
onChange={noop}
isDirty={false}
appName={'discover'}
screenTitle={'Another Screen'}
indexPatterns={[mockIndexPattern]}
Expand All @@ -225,6 +239,8 @@ describe('QueryBar', () => {
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
onSubmit={noop}
onChange={noop}
isDirty={false}
appName={'discover'}
screenTitle={'Another Screen'}
store={createMockStorage()}
Expand Down
Loading

0 comments on commit b97a95b

Please sign in to comment.