diff --git a/src/core_plugins/kibana/public/kibana.js b/src/core_plugins/kibana/public/kibana.js index ee0da07aa8d3e..2b2abcb524b0f 100644 --- a/src/core_plugins/kibana/public/kibana.js +++ b/src/core_plugins/kibana/public/kibana.js @@ -42,6 +42,7 @@ import 'uiExports/docViews'; import 'uiExports/embeddableFactories'; import 'uiExports/inspectorViews'; import 'uiExports/search'; +import 'uiExports/autocompleteProviders'; import 'ui/autoload/all'; import './home'; diff --git a/src/ui/public/kuery/suggestions/escape_kuery.js b/src/ui/public/autocomplete_providers/index.js similarity index 59% rename from src/ui/public/kuery/suggestions/escape_kuery.js rename to src/ui/public/autocomplete_providers/index.js index 1b5e68d406016..ee297d65421db 100644 --- a/src/ui/public/kuery/suggestions/escape_kuery.js +++ b/src/ui/public/autocomplete_providers/index.js @@ -17,22 +17,12 @@ * under the License. */ -export function escapeQuotes(string) { - return string.replace(/"/g, '\\"'); -} - -export const escapeKuery = (string) => escapeNot(escapeAndOr(escapeSpecialCharacters(string))); - -// See the SpecialCharacter rule in kuery.peg -function escapeSpecialCharacters(string) { - return string.replace(/[\\():<>"*]/g, '\\$&'); // $& means the whole matched string -} +const autocompleteProviders = new Map(); -// See the Keyword rule in kuery.peg -function escapeAndOr(string) { - return string.replace(/(\s+)(and|or)(\s+)/ig, '$1\\$2$3'); +export function addAutocompleteProvider(language, provider) { + autocompleteProviders.set(language, provider); } -function escapeNot(string) { - return string.replace(/not(\s+)/ig, '\\$&'); +export function getAutocompleteProvider(language) { + return autocompleteProviders.get(language); } diff --git a/src/ui/public/kuery/index.js b/src/ui/public/kuery/index.js index 48e826e603f94..a7c6518527cc8 100644 --- a/src/ui/public/kuery/index.js +++ b/src/ui/public/kuery/index.js @@ -20,4 +20,3 @@ export * from './ast'; export * from './filter_migration'; export * from './node_types'; -export * from './suggestions'; diff --git a/src/ui/public/kuery/suggestions/conjunction.js b/src/ui/public/kuery/suggestions/conjunction.js deleted file mode 100644 index 2a639e1665674..0000000000000 --- a/src/ui/public/kuery/suggestions/conjunction.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ - -const type = 'conjunction'; - -const conjunctions = { - and: `
Requires both arguments to be true
`, - or: `Requires one or more arguments to be true
` -}; - -function getDescription(conjunction) { - return conjunctions[conjunction]; -} - -export function getSuggestionsProvider() { - return function getConjunctionSuggestions({ text, end }) { - if (!text.endsWith(' ')) return []; - const suggestions = Object.keys(conjunctions).map(conjunction => { - const text = `${conjunction} `; - const description = getDescription(conjunction); - return { type, text, description, start: end, end }; - }); - return suggestions; - }; -} diff --git a/src/ui/public/query_bar/directive/query_bar.js b/src/ui/public/query_bar/directive/query_bar.js index ffed06e9c7b66..e21c849e1d9dd 100644 --- a/src/ui/public/query_bar/directive/query_bar.js +++ b/src/ui/public/query_bar/directive/query_bar.js @@ -17,12 +17,12 @@ * under the License. */ -import { compact, get } from 'lodash'; +import { compact } from 'lodash'; import { uiModules } from '../../modules'; import { callAfterBindingsWorkaround } from '../../compat'; import template from './query_bar.html'; import suggestionTemplate from './suggestion.html'; -import { getSuggestionsProvider } from '../../kuery'; +import { getAutocompleteProvider } from '../../autocomplete_providers'; import './suggestion.less'; import '../../directives/match_pairs'; import './query_popover'; @@ -75,18 +75,25 @@ module.directive('queryBar', function () { } }; - this.updateSuggestions = () => { - const query = get(this, 'localQuery.query'); - if (typeof query === 'undefined') return; + this.updateSuggestions = async () => { + const suggestions = await this.getSuggestions(); + $scope.$apply(() => this.suggestions = suggestions); + }; + + this.getSuggestions = async () => { + const { localQuery: { query, language } } = this; + const recentSearchSuggestions = this.getRecentSearchSuggestions(query); - this.suggestions = this.getRecentSearchSuggestions(query); - if (this.localQuery.language !== 'kuery' || !this.getKuerySuggestions) return; + const autocompleteProvider = getAutocompleteProvider(language); + if (!autocompleteProvider) return recentSearchSuggestions; + + const legacyIndexPatterns = await this.getIndexPatterns(); + const indexPatterns = getFromLegacyIndexPattern(legacyIndexPatterns); + const getAutocompleteSuggestions = autocompleteProvider({ config, indexPatterns }); const { selectionStart, selectionEnd } = $element.find('input')[0]; - this.getKuerySuggestions({ query, selectionStart, selectionEnd }) - .then(suggestions => { - $scope.$apply(() => this.suggestions = [...suggestions, ...this.suggestions]); - }); + const suggestions = await getAutocompleteSuggestions({ query, selectionStart, selectionEnd }); + return [...suggestions, ...recentSearchSuggestions]; }; // TODO: Figure out a better way to set selection @@ -107,6 +114,7 @@ module.directive('queryBar', function () { }; this.getRecentSearchSuggestions = (query) => { + if (!this.persistedLog) return []; const recentSearches = this.persistedLog.get(); const matchingRecentSearches = recentSearches.filter(search => search.includes(query)); return matchingRecentSearches.map(recentSearch => { @@ -133,14 +141,7 @@ module.directive('queryBar', function () { }, true); $scope.$watch('queryBar.indexPatterns', () => { - this.getIndexPatterns().then(indexPatterns => { - - this.getKuerySuggestions = getSuggestionsProvider({ - config, - indexPatterns: getFromLegacyIndexPattern(indexPatterns) - }); - this.updateSuggestions(); - }); + this.updateSuggestions(); }); }) }; diff --git a/src/ui/ui_exports/ui_export_types/index.js b/src/ui/ui_exports/ui_export_types/index.js index 08d03bc04b14b..2247b685bd063 100644 --- a/src/ui/ui_exports/ui_export_types/index.js +++ b/src/ui/ui_exports/ui_export_types/index.js @@ -53,6 +53,7 @@ export { aliases, visualize, search, + autocompleteProviders, } from './ui_app_extensions'; export { diff --git a/src/ui/ui_exports/ui_export_types/ui_app_extensions.js b/src/ui/ui_exports/ui_export_types/ui_app_extensions.js index 738b794cb3107..b41eb7177b4a4 100644 --- a/src/ui/ui_exports/ui_export_types/ui_app_extensions.js +++ b/src/ui/ui_exports/ui_export_types/ui_app_extensions.js @@ -37,6 +37,7 @@ export const visTypes = appExtension; export const visResponseHandlers = appExtension; export const visRequestHandlers = appExtension; export const visEditorTypes = appExtension; +export const autocompleteProviders = appExtension; export const savedObjectTypes = appExtension; export const embeddableFactories = appExtension; export const dashboardPanelActions = appExtension; diff --git a/x-pack/index.js b/x-pack/index.js index f20e87de98984..a98af06dde131 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -22,6 +22,7 @@ import { cloud } from './plugins/cloud'; import { indexManagement } from './plugins/index_management'; import { consoleExtensions } from './plugins/console_extensions'; import { notifications } from './plugins/notifications'; +import { kueryAutocomplete } from './plugins/kuery_autocomplete'; module.exports = function (kibana) { return [ @@ -43,5 +44,6 @@ module.exports = function (kibana) { indexManagement(kibana), consoleExtensions(kibana), notifications(kibana), + kueryAutocomplete(kibana) ]; }; diff --git a/x-pack/package.json b/x-pack/package.json index b8b20808e115e..e3bb76db43ce2 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -44,6 +44,7 @@ "enzyme-adapter-react-16": "^1.1.1", "enzyme-to-json": "3.3.1", "expect.js": "0.3.1", + "fetch-mock": "^5.13.1", "gulp": "3.9.1", "gulp-load-plugins": "1.2.0", "gulp-mocha": "2.2.0", diff --git a/x-pack/plugins/apm/public/services/kuery.js b/x-pack/plugins/apm/public/services/kuery.js index c2fa9c737046c..9b9b00e2970a1 100644 --- a/x-pack/plugins/apm/public/services/kuery.js +++ b/x-pack/plugins/apm/public/services/kuery.js @@ -4,11 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - fromKueryExpression, - toElasticsearchQuery, - getSuggestionsProvider -} from 'ui/kuery'; +import { fromKueryExpression, toElasticsearchQuery } from 'ui/kuery'; +import { getAutocompleteProvider } from 'ui/autocomplete_providers'; export function convertKueryToEsQuery(kuery, indexPattern) { const ast = fromKueryExpression(kuery); @@ -21,16 +18,18 @@ export async function getSuggestions( apmIndexPattern, boolFilter ) { + const autocompleteProvider = getAutocompleteProvider('kuery'); + if (!autocompleteProvider) return []; const config = { get: () => true }; - const getKuerySuggestions = getSuggestionsProvider({ + const getAutocompleteSuggestions = autocompleteProvider({ config, indexPatterns: [apmIndexPattern], boolFilter }); - return getKuerySuggestions({ + return getAutocompleteSuggestions({ query, selectionStart, selectionEnd: selectionStart diff --git a/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js b/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js index 3da539144771e..31c74cbc38ddc 100644 --- a/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js +++ b/x-pack/plugins/dashboard_mode/public/dashboard_viewer.js @@ -25,7 +25,7 @@ import 'uiExports/navbarExtensions'; import 'uiExports/docViews'; import 'uiExports/fieldFormats'; import 'uiExports/search'; - +import 'uiExports/autocompleteProviders'; import _ from 'lodash'; import 'ui/autoload/all'; import 'plugins/kibana/dashboard'; diff --git a/x-pack/plugins/kuery_autocomplete/index.js b/x-pack/plugins/kuery_autocomplete/index.js new file mode 100644 index 0000000000000..d78d89e159021 --- /dev/null +++ b/x-pack/plugins/kuery_autocomplete/index.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { resolve } from 'path'; + + +export const kueryAutocomplete = (kibana) => new kibana.Plugin({ + id: 'kuery_autocomplete', + publicDir: resolve(__dirname, 'public'), + uiExports: { + autocompleteProviders: [ + 'plugins/kuery_autocomplete/autocomplete_providers' + ], + } +}); diff --git a/src/ui/public/kuery/suggestions/__tests__/conjunction.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/conjunction.js similarity index 65% rename from src/ui/public/kuery/suggestions/__tests__/conjunction.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/conjunction.js index e9261d199dd7b..496d15f6b32a9 100644 --- a/src/ui/public/kuery/suggestions/__tests__/conjunction.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/conjunction.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import expect from 'expect.js'; diff --git a/src/ui/public/kuery/suggestions/__tests__/escape_kuery.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/escape_kuery.js similarity index 68% rename from src/ui/public/kuery/suggestions/__tests__/escape_kuery.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/escape_kuery.js index 2a31eb36401e3..1af4b226e38e6 100644 --- a/src/ui/public/kuery/suggestions/__tests__/escape_kuery.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/escape_kuery.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import expect from 'expect.js'; diff --git a/src/ui/public/kuery/suggestions/__tests__/field.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/field.js similarity index 74% rename from src/ui/public/kuery/suggestions/__tests__/field.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/field.js index ca3796ea74ea2..c4d70bcea9190 100644 --- a/src/ui/public/kuery/suggestions/__tests__/field.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/field.js @@ -1,26 +1,13 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import expect from 'expect.js'; import { getSuggestionsProvider } from '../field'; -import indexPatternResponse from '../../__tests__/index_pattern_response.json'; -import { isFilterable } from '../../../index_patterns/static_utils'; +import indexPatternResponse from 'ui/kuery/__tests__/index_pattern_response.json'; +import { isFilterable } from 'ui/index_patterns/static_utils'; describe('Kuery field suggestions', function () { let indexPattern; diff --git a/src/ui/public/kuery/suggestions/__tests__/operator.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/operator.js similarity index 67% rename from src/ui/public/kuery/suggestions/__tests__/operator.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/operator.js index 9df77ec1d122a..aaaa8f2c06079 100644 --- a/src/ui/public/kuery/suggestions/__tests__/operator.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/operator.js @@ -1,25 +1,12 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import expect from 'expect.js'; import { getSuggestionsProvider } from '../operator'; -import indexPatternResponse from '../../__tests__/index_pattern_response.json'; +import indexPatternResponse from 'ui/kuery/__tests__/index_pattern_response.json'; describe('Kuery operator suggestions', function () { let indexPatterns; diff --git a/src/ui/public/kuery/suggestions/__tests__/value.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/value.js similarity index 82% rename from src/ui/public/kuery/suggestions/__tests__/value.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/value.js index 2d5a7ae9c43f5..eafbb140d340a 100644 --- a/src/ui/public/kuery/suggestions/__tests__/value.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/__tests__/value.js @@ -1,27 +1,14 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import expect from 'expect.js'; import sinon from 'sinon'; import fetchMock from 'fetch-mock'; import { getSuggestionsProvider } from '../value'; -import indexPatternResponse from '../../__tests__/index_pattern_response.json'; +import indexPatternResponse from 'ui/kuery/__tests__/index_pattern_response.json'; describe('Kuery value suggestions', function () { let config; diff --git a/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/conjunction.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/conjunction.js new file mode 100644 index 0000000000000..8aa64c13cb956 --- /dev/null +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/conjunction.js @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +const type = 'conjunction'; + +const conjunctions = { + and: `Requires both arguments to be true
`, + or: `Requires one or more arguments to be true
` +}; + +function getDescription(conjunction) { + return conjunctions[conjunction]; +} + +export function getSuggestionsProvider() { + return function getConjunctionSuggestions({ text, end }) { + if (!text.endsWith(' ')) return []; + const suggestions = Object.keys(conjunctions).map(conjunction => { + const text = `${conjunction} `; + const description = getDescription(conjunction); + return { type, text, description, start: end, end }; + }); + return suggestions; + }; +} diff --git a/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/escape_kuery.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/escape_kuery.js new file mode 100644 index 0000000000000..11a418957a657 --- /dev/null +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/escape_kuery.js @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export function escapeQuotes(string) { + return string.replace(/"/g, '\\"'); +} + +export const escapeKuery = (string) => escapeNot(escapeAndOr(escapeSpecialCharacters(string))); + +// See the SpecialCharacter rule in kuery.peg +function escapeSpecialCharacters(string) { + return string.replace(/[\\():<>"*]/g, '\\$&'); // $& means the whole matched string +} + +// See the Keyword rule in kuery.peg +function escapeAndOr(string) { + return string.replace(/(\s+)(and|or)(\s+)/ig, '$1\\$2$3'); +} + +function escapeNot(string) { + return string.replace(/not(\s+)/ig, '\\$&'); +} diff --git a/src/ui/public/kuery/suggestions/field.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/field.js similarity index 60% rename from src/ui/public/kuery/suggestions/field.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/field.js index 07478bb296f4b..7a96fd6baa945 100644 --- a/src/ui/public/kuery/suggestions/field.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/field.js @@ -1,26 +1,13 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { escape, flatten } from 'lodash'; import { escapeKuery } from './escape_kuery'; -import { sortPrefixFirst } from '../../utils/sort_prefix_first'; -import { isFilterable } from '../../index_patterns/static_utils'; +import { sortPrefixFirst } from 'ui/utils/sort_prefix_first'; +import { isFilterable } from 'ui/index_patterns/static_utils'; const type = 'field'; diff --git a/src/ui/public/kuery/suggestions/index.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/index.js similarity index 58% rename from src/ui/public/kuery/suggestions/index.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/index.js index 160b1272e6510..59ee67ff4a8e6 100644 --- a/src/ui/public/kuery/suggestions/index.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/index.js @@ -1,32 +1,20 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { flatten, mapValues, uniq } from 'lodash'; -import { fromKueryExpression } from '../ast'; +import { fromKueryExpression } from 'ui/kuery/ast'; import { getSuggestionsProvider as field } from './field'; import { getSuggestionsProvider as value } from './value'; import { getSuggestionsProvider as operator } from './operator'; import { getSuggestionsProvider as conjunction } from './conjunction'; +import { addAutocompleteProvider } from 'ui/autocomplete_providers'; const cursorSymbol = '@kuery-cursor@'; -export function getSuggestionsProvider({ config, indexPatterns, boolFilter }) { +addAutocompleteProvider('kuery', ({ config, indexPatterns, boolFilter }) => { const getSuggestionsByType = mapValues({ field, value, operator, conjunction }, provider => { return provider({ config, indexPatterns, boolFilter }); }); @@ -48,7 +36,7 @@ export function getSuggestionsProvider({ config, indexPatterns, boolFilter }) { return Promise.all(suggestionsByType) .then(suggestionsByType => dedup(flatten(suggestionsByType))); }; -} +}); function dedup(suggestions) { return uniq(suggestions, ({ type, text, start, end }) => [type, text, start, end].join('|')); diff --git a/src/ui/public/kuery/suggestions/operator.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/operator.js similarity index 70% rename from src/ui/public/kuery/suggestions/operator.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/operator.js index e3c7d781500a4..c5301e7e783e4 100644 --- a/src/ui/public/kuery/suggestions/operator.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/operator.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { flatten } from 'lodash'; diff --git a/src/ui/public/kuery/suggestions/value.js b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/value.js similarity index 71% rename from src/ui/public/kuery/suggestions/value.js rename to x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/value.js index 906f23e5f2b96..e1e96569c7a02 100644 --- a/src/ui/public/kuery/suggestions/value.js +++ b/x-pack/plugins/kuery_autocomplete/public/autocomplete_providers/value.js @@ -1,26 +1,13 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import 'isomorphic-fetch'; import { flatten, memoize } from 'lodash'; import { escapeQuotes } from './escape_kuery'; -import { kfetch } from '../../kfetch'; +import { kfetch } from 'ui/kfetch'; const type = 'value'; diff --git a/x-pack/yarn.lock b/x-pack/yarn.lock index 7ed28c1e372f2..e727a45e6709c 100644 --- a/x-pack/yarn.lock +++ b/x-pack/yarn.lock @@ -2692,6 +2692,14 @@ fd-slicer@~1.1.0: dependencies: pend "~1.2.0" +fetch-mock@^5.13.1: + version "5.13.1" + resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-5.13.1.tgz#955794a77f3d972f1644b9ace65a0fdfd60f1df7" + dependencies: + glob-to-regexp "^0.3.0" + node-fetch "^1.3.3" + path-to-regexp "^1.7.0" + figures@^1.3.5: version "1.7.0" resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" @@ -3084,6 +3092,10 @@ glob-stream@^6.1.0: to-absolute-glob "^2.0.0" unique-stream "^2.0.2" +glob-to-regexp@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" + glob-watcher@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/glob-watcher/-/glob-watcher-0.0.6.tgz#b95b4a8df74b39c83298b0c05c978b4d9a3b710b" @@ -5520,7 +5532,7 @@ nise@^1.2.0: path-to-regexp "^1.7.0" text-encoding "^0.6.4" -node-fetch@^1.0.1: +node-fetch@^1.0.1, node-fetch@^1.3.3: version "1.7.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" dependencies: @@ -8102,9 +8114,6 @@ to-object-path@^0.3.0: to-regex-range@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-2.1.1.tgz#7c80c17b9dfebe599e27367e0d4dd5590141db38" - dependencies: - is-number "^3.0.0" - repeat-string "^1.6.1" to-regex@^3.0.1: version "3.0.1"