From 27611e51b187128a523c972c1f99d57ebe1be23a Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Thu, 11 Nov 2021 14:53:20 -0800 Subject: [PATCH 1/7] Do not add space 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 eab8ce60b..323708e37 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -309,7 +309,7 @@ const onItemSelect = async ({ setQuery, item }, dslService: DSLService) => { currIndex = item.itemName; getFields(dslService); } - setQuery(item.label + ' '); + setQuery(item.label); }; type AutocompleteItem = { @@ -387,6 +387,7 @@ export function Autocomplete({ getSources() { return [ { + sourceId: 'querySuggestions', async getItems({ query }) { const suggestions = await getSuggestions(query, dslService); return suggestions; From 2087b33af20dd3384e7fe1b77c93129b9486477a Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Thu, 11 Nov 2021 15:17:40 -0800 Subject: [PATCH 2/7] Suggest all nuber types for fields Signed-off-by: Eugene Lee --- .../components/common/search/autocomplete.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index 323708e37..1e23ac20d 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -68,6 +68,18 @@ const statsCommands = [ { label: 'stddev_pop(' }, ]; +const numberTypes = [ + 'long', + 'integer', + 'short', + 'byte', + 'double', + 'float', + 'half_float', + 'scaled_float', + 'unsigned_long' +]; + // Function to create the array of objects to be suggested const fillSuggestions = (str: string, word: string, items: any) => { const lowerWord = word.toLowerCase(); @@ -167,7 +179,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => { } else { const numberFields = fieldsFromBackend.filter( (field: { label: string, type: string }) => - field.label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(field.label.toLowerCase()) && (field.type === 'float' || field.type === 'integer') + field.label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(field.label.toLowerCase()) && numberTypes.includes(field.type) ); for (let i = 0; i < numberFields.length; i++) { var field: {label: string} = numberFields[i]; From 69b3f65e85ca5d59cc8f206a31bdd66a0a5ccd9a Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Thu, 11 Nov 2021 22:43:33 -0800 Subject: [PATCH 3/7] Suggest on selection Signed-off-by: Eugene Lee --- .../public/components/common/search/autocomplete.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index eab8ce60b..bfdc94adf 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -375,6 +375,7 @@ export function Autocomplete({ >( { onStateChange: ({ state }) => { + openOnFocus: true setAutocompleteState({ ...state, }); @@ -399,6 +400,8 @@ export function Autocomplete({ }, dslService ); + $("#autocomplete-textarea").blur(); + $("#autocomplete-textarea").focus(); } }, ]; From d4869151900f8aafcb23d84010f2a789b57362d9 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Thu, 11 Nov 2021 22:54:19 -0800 Subject: [PATCH 4/7] Re add auto space after selection Signed-off-by: Eugene Lee --- .../public/components/common/search/autocomplete.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index 733ab3f7a..ac5b36dcb 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -321,7 +321,7 @@ const onItemSelect = async ({ setQuery, item }, dslService: DSLService) => { currIndex = item.itemName; getFields(dslService); } - setQuery(item.label); + setQuery(item.label + ' '); }; type AutocompleteItem = { From dc44ed672303b57e51321983353613eff29a5348 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Fri, 12 Nov 2021 00:00:12 -0800 Subject: [PATCH 5/7] Remove unnecessary imports Signed-off-by: Eugene Lee --- .../public/components/common/search/search.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/dashboards-observability/public/components/common/search/search.tsx b/dashboards-observability/public/components/common/search/search.tsx index 8cd24cfc4..84d288abf 100644 --- a/dashboards-observability/public/components/common/search/search.tsx +++ b/dashboards-observability/public/components/common/search/search.tsx @@ -13,7 +13,6 @@ import './search.scss'; import React, { useState } from 'react'; import PropTypes from 'prop-types'; -import { isEmpty } from 'lodash'; import { EuiFlexGroup, EuiButton, @@ -21,7 +20,6 @@ import { EuiPopover, EuiButtonEmpty, EuiPopoverFooter, - EuiIcon, EuiButtonIcon, } from '@elastic/eui'; import _ from 'lodash'; From a0e09095d769e183b6e0a8313992313afe437312 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Fri, 12 Nov 2021 00:01:19 -0800 Subject: [PATCH 6/7] Suggest first commands on click Signed-off-by: Eugene Lee --- .../public/components/common/search/autocomplete.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index ac5b36dcb..c07e8e987 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -386,8 +386,8 @@ export function Autocomplete({ React.KeyboardEvent >( { + openOnFocus: true, onStateChange: ({ state }) => { - openOnFocus: true setAutocompleteState({ ...state, }); @@ -395,7 +395,7 @@ export function Autocomplete({ }, initialState: { ...autocompleteState, - query, + query: '', }, getSources() { return [ From 075f39c24fcfef266193dc2c2d7e2768878a93ff Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Fri, 12 Nov 2021 09:31:41 -0800 Subject: [PATCH 7/7] Auto-select first suggestion Signed-off-by: Eugene Lee --- .../public/components/common/search/autocomplete.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/dashboards-observability/public/components/common/search/autocomplete.tsx b/dashboards-observability/public/components/common/search/autocomplete.tsx index c07e8e987..f992f01ad 100644 --- a/dashboards-observability/public/components/common/search/autocomplete.tsx +++ b/dashboards-observability/public/components/common/search/autocomplete.tsx @@ -387,6 +387,7 @@ export function Autocomplete({ >( { openOnFocus: true, + defaultActiveItemId: 0, onStateChange: ({ state }) => { setAutocompleteState({ ...state,