Skip to content

Commit

Permalink
[Unified search] Optimise the bundle size unified search plugin (elas…
Browse files Browse the repository at this point in the history
…tic#130662)

* feat: move autocomplete logic from data plugin to unified search

* minor fix after comments

* updated Documentation: data.autocomplete -> unifiedSearch.autocomplete

* changed renameFromRoot order for autocomplete

* removed extra renameFromRoot in config deprecations, updated test

* added configPath for unified search plugin

* Update kibana.json

* updated path to autocomplete

* fix conflict

* fix conflict

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* fix Linting

* Merge branch 'issue-move-autocomplete-to-unified-search' into issue-change-index-pattern-to-data-view

* feat: replace static import to dynamic import for es-query in autocomplete

* feat: add unifiedSearch to uptime plugin

* refact scss

* feat: add comment for filter lazy loading

* fix css issue

* feat: rollback filter bar changes

* update limits

* rollback scss files and update limites

* fix: restored index.scss file
  • Loading branch information
nlatipov authored and Esteban Beltran committed May 4, 2022
1 parent 52b1f02 commit 0c7b98f
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pageLoadAssetSize:
sessionView: 77750
cloudSecurityPosture: 19109
visTypeGauge: 24113
unifiedSearch: 104869
unifiedSearch: 71059
data: 454087
expressionXY: 26500
eventAnnotation: 19334
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { IFieldType, indexPatterns as indexPatternsUtils } from '@kbn/data-plugin/public';
import { flatten } from 'lodash';
import { escapeKuery } from './lib/escape_kuery';
import { sortPrefixFirst } from './sort_prefix_first';
import { QuerySuggestionField, QuerySuggestionTypes } from '../query_suggestion_provider';
import { KqlQuerySuggestionProvider } from './types';
Expand All @@ -27,7 +26,7 @@ const keywordComparator = (first: IFieldType, second: IFieldType) => {
export const setupGetFieldSuggestions: KqlQuerySuggestionProvider<QuerySuggestionField> = (
core
) => {
return ({ indexPatterns }, { start, end, prefix, suffix, nestedPath = '' }) => {
return async ({ indexPatterns }, { start, end, prefix, suffix, nestedPath = '' }) => {
const allFields = flatten(
indexPatterns.map((indexPattern) => {
return indexPattern.fields.filter(indexPatternsUtils.isFilterable);
Expand All @@ -42,7 +41,7 @@ export const setupGetFieldSuggestions: KqlQuerySuggestionProvider<QuerySuggestio
);
});
const sortedFields = sortPrefixFirst(matchingFields.sort(keywordComparator), search, 'name');

const { escapeKuery } = await import('@kbn/es-query');
const suggestions: QuerySuggestionField[] = sortedFields.map((field) => {
const remainingPath =
field.subType && field.subType.nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { CoreSetup } from '@kbn/core/public';
import { $Keys } from 'utility-types';
import { flatten, uniqBy } from 'lodash';
import { fromKueryExpression } from '@kbn/es-query';
import { setupGetFieldSuggestions } from './field';
import { setupGetValueSuggestions } from './value';
import { setupGetOperatorSuggestions } from './operator';
Expand Down Expand Up @@ -38,11 +37,12 @@ export const setupKqlQuerySuggestionProvider = (
conjunction: setupGetConjunctionSuggestions(core),
};

const getSuggestionsByType = (
const getSuggestionsByType = async (
cursoredQuery: string,
querySuggestionsArgs: QuerySuggestionGetFnArgs
): Array<Promise<QuerySuggestion[]>> | [] => {
): Promise<Array<Promise<QuerySuggestion[]>> | []> => {
try {
const { fromKueryExpression } = await import('@kbn/es-query');
const cursorNode = fromKueryExpression(cursoredQuery, {
cursorSymbol,
parseCursor: true,
Expand All @@ -56,13 +56,13 @@ export const setupKqlQuerySuggestionProvider = (
}
};

return (querySuggestionsArgs) => {
return async (querySuggestionsArgs): Promise<QuerySuggestion[]> => {
const { query, selectionStart, selectionEnd } = querySuggestionsArgs;
const cursoredQuery = `${query.substr(0, selectionStart)}${cursorSymbol}${query.substr(
selectionEnd
)}`;

return Promise.all(getSuggestionsByType(cursoredQuery, querySuggestionsArgs)).then(
return Promise.all(await getSuggestionsByType(cursoredQuery, querySuggestionsArgs)).then(
(suggestionsByType) => dedup(flatten(suggestionsByType))
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
* Side Public License, v 1.
*/

import { escapeKuery } from '@kbn/es-query';

/**
* Escapes backslashes and double-quotes. (Useful when putting a string in quotes to use as a value
* in a KQL expression. See the QuotedCharacter rule in kuery.peg.)
*/
export function escapeQuotes(str: string) {
return str.replace(/[\\"]/g, '\\$&');
}

// Re-export this function from the @kbn/es-query package to avoid refactoring
export { escapeKuery };
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Side Public License, v 1.
*/

import { CoreSetup } from '@kbn/core/public';
import { KueryNode } from '@kbn/es-query';
import type { KueryNode } from '@kbn/es-query';
import type { CoreSetup } from '@kbn/core/public';
import type { UnifiedSearchPublicPluginStart } from '../../../types';
import { QuerySuggestionBasic, QuerySuggestionGetFnArgs } from '../query_suggestion_provider';
import type { QuerySuggestionBasic, QuerySuggestionGetFnArgs } from '../query_suggestion_provider';

export type KqlQuerySuggestionProvider<T = QuerySuggestionBasic> = (
core: CoreSetup<object, UnifiedSearchPublicPluginStart>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { CoreSetup } from '@kbn/core/public';
import dateMath from '@kbn/datemath';
import { buildQueryFromFilters } from '@kbn/es-query';
import { memoize } from 'lodash';
import {
IIndexPattern,
Expand Down Expand Up @@ -124,6 +123,7 @@ export const setupValueSuggestionProvider = (
const timeFilter = useTimeRange
? getAutocompleteTimefilter(timefilter, indexPattern)
: undefined;
const { buildQueryFromFilters } = await import('@kbn/es-query');
const filterQuery = timeFilter ? buildQueryFromFilters([timeFilter], indexPattern).filter : [];
const filters = [...(boolFilter ? boolFilter : []), ...filterQuery];
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,6 @@ export function FilterItem(props: FilterItemProps) {
</EuiPopover>
);
}

// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default FilterItem;
3 changes: 2 additions & 1 deletion src/plugins/unified_search/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginInitializerContext } from '@kbn/core/public';
import { ConfigSchema } from '../config';
export type { IndexPatternSelectProps } from './index_pattern_select';
Expand All @@ -28,7 +29,7 @@ export type {
AutocompleteStart,
} from './autocomplete';

export { QuerySuggestionTypes } from './autocomplete';
export { QuerySuggestionTypes } from './autocomplete/providers/query_suggestion_provider';

import { UnifiedSearchPublicPlugin } from './plugin';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/unified_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { APPLY_FILTER_TRIGGER } from '@kbn/data-plugin/public';
import { ConfigSchema } from '../config';
import { setIndexPatterns, setTheme, setOverlays, setAutocomplete } from './services';
import { AutocompleteService } from './autocomplete';
import { AutocompleteService } from './autocomplete/autocomplete_service';
import { createSearchBar } from './search_bar';
import { createIndexPatternSelect } from './index_pattern_select';
import type {
Expand Down

0 comments on commit 0c7b98f

Please sign in to comment.