From 300e2392d0853ae2b8cf5fd2fefee417f9b0b0b5 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Mon, 15 Nov 2021 11:39:29 -0800 Subject: [PATCH 1/3] Autocomplete for data values Signed-off-by: Eugene Lee --- .../public/components/common/search/autocomplete.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index 88a3b7033..b60a06927 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -216,7 +216,6 @@ const getSuggestions = async (str: string, dslService: DSLService) => { currFieldType = fieldsFromBackend.find((field: {label: string, type: string}) => field.label === currField)?.type; return fullSuggestions.filter((suggestion: { label: string }) => suggestion.label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(suggestion.label.toLowerCase())); } else if (nextWhere === splittedModel.length - 2) { - if (isEmpty(prefix)) { if (!currFieldType) { console.error('Current field type is undefined') return []; @@ -226,8 +225,6 @@ const getSuggestions = async (str: string, dslService: DSLService) => { prefix, await getDataValues(currIndex, currField, currFieldType, dslService) ); - } - return []; } else if (nextWhere === splittedModel.length - 3 || nextStats === splittedModel.length - 5 || nextWhere === splittedModel.length - 5) { return [{ label: str + '|', input: str, suggestion: '|', itemName: '|' }].filter( ({ label }) => label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(label.toLowerCase()) From 42cafeda2fe04e2c16028764b023e84e7e2d9c05 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Mon, 15 Nov 2021 11:48:32 -0800 Subject: [PATCH 2/3] Fetch data values earlier and save them Signed-off-by: Eugene Lee --- .../components/common/search/autocomplete.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index b60a06927..cbf3f6502 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -17,13 +17,12 @@ import { import { EuiTextArea } from '@elastic/eui'; import { IQueryBarProps } from './search'; import { getDataValueQuery } from './queries/data_queries'; -import { isEmpty } from 'lodash'; import DSLService from 'public/services/requests/dsl'; import { uiSettingsService } from '../../../../common/utils'; let currIndex: string = ''; let currField: string = ''; -let currFieldType: string | undefined = ''; +let currFieldType: string = ''; let inFieldsCommaLoop: boolean = false; let inMatch: boolean = false; @@ -34,6 +33,7 @@ const indexList: string[] = []; const fieldList: string[] = []; const fieldsFromBackend: fieldItem[] = []; const indicesFromBackend: indexItem[] = []; +const dataValuesFromBackend: dataItem[] = []; const firstCommand = [{ label: 'source' }]; @@ -119,6 +119,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => { nextWhere = Number.MAX_SAFE_INTEGER; nextStats = Number.MAX_SAFE_INTEGER; currField = ''; + currFieldType = ''; return fillSuggestions(str, prefix, pipeCommands); } else if (splittedModel[splittedModel.length - 2].includes(',')) { if (inFieldsCommaLoop) { @@ -152,7 +153,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => { } else if (inMatch && fieldList.includes(splittedModel[splittedModel.length - 2])) { inMatch = true; currField = splittedModel[splittedModel.length - 2]; - currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type; + currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type || ''; return [{ label: str + ',', input: str, suggestion: ',', itemName: ','}].filter( ({ suggestion }) => suggestion.startsWith(prefix) && prefix !== suggestion ); @@ -213,17 +214,14 @@ const getSuggestions = async (str: string, dslService: DSLService) => { itemName: '=', }); currField = splittedModel[splittedModel.length - 2]; - currFieldType = fieldsFromBackend.find((field: {label: string, type: string}) => field.label === currField)?.type; + currFieldType = fieldsFromBackend.find((field: {label: string, type: string}) => field.label === currField)?.type || ''; + await getDataValues(currIndex, currField, currFieldType, dslService); return fullSuggestions.filter((suggestion: { label: string }) => suggestion.label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(suggestion.label.toLowerCase())); } else if (nextWhere === splittedModel.length - 2) { - if (!currFieldType) { - console.error('Current field type is undefined') - return []; - } return fillSuggestions( str, prefix, - await getDataValues(currIndex, currField, currFieldType, dslService) + dataValuesFromBackend ); } else if (nextWhere === splittedModel.length - 3 || nextStats === splittedModel.length - 5 || nextWhere === splittedModel.length - 5) { return [{ label: str + '|', input: str, suggestion: '|', itemName: '|' }].filter( @@ -286,7 +284,7 @@ const getDataValues = async ( dslService: DSLService ) => { const res = (await dslService.fetch(getDataValueQuery(index, field)))?.aggregations?.top_tags?.buckets || []; - const dataValuesFromBackend: dataItem[] = []; + dataValuesFromBackend.length = 0; res.forEach((e: any) => { if (fieldType === 'string') { dataValuesFromBackend.push({ label: '"' + e.key + '"', doc_count: e.doc_count }); From 70dd3226b8868e29d0d56b4610be88bb6580c986 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Mon, 15 Nov 2021 12:28:20 -0800 Subject: [PATCH 3/3] Fetch dataValues for match early Signed-off-by: Eugene Lee --- .../public/components/common/search/autocomplete.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index cbf3f6502..5ab89bdfc 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -130,7 +130,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => { return fillSuggestions( str, prefix, - await getDataValues(currIndex, currField, currFieldType, dslService) + dataValuesFromBackend ); } return fullSuggestions; @@ -154,6 +154,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => { inMatch = true; currField = splittedModel[splittedModel.length - 2]; currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type || ''; + await getDataValues(currIndex, currField, currFieldType, dslService) return [{ label: str + ',', input: str, suggestion: ',', itemName: ','}].filter( ({ suggestion }) => suggestion.startsWith(prefix) && prefix !== suggestion );