From c0ef4fd97d0023ffd9eb23bc56daf3830935cf63 Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Wed, 4 Sep 2024 09:30:17 -0700 Subject: [PATCH 01/10] put in trigger suggest on focus and on type space Signed-off-by: Paul Sebastian --- .../ui/query_editor/editors/default_editor/index.tsx | 2 ++ .../data/public/ui/query_editor/editors/shared.tsx | 2 ++ .../data/public/ui/query_editor/query_editor.tsx | 1 + .../public/code_editor/code_editor.tsx | 11 +++++++++++ 4 files changed, 16 insertions(+) diff --git a/src/plugins/data/public/ui/query_editor/editors/default_editor/index.tsx b/src/plugins/data/public/ui/query_editor/editors/default_editor/index.tsx index b7bb11c18a8d..764b25d4b9ac 100644 --- a/src/plugins/data/public/ui/query_editor/editors/default_editor/index.tsx +++ b/src/plugins/data/public/ui/query_editor/editors/default_editor/index.tsx @@ -55,6 +55,7 @@ export const DefaultInput: React.FC = ({ }} suggestionProvider={{ provideCompletionItems, + triggerCharacters: [' '], }} languageConfiguration={{ autoClosingPairs: [ @@ -65,6 +66,7 @@ export const DefaultInput: React.FC = ({ { open: "'", close: "'" }, ], }} + triggerSuggestOnFocus={true} />
{footerItems && ( diff --git a/src/plugins/data/public/ui/query_editor/editors/shared.tsx b/src/plugins/data/public/ui/query_editor/editors/shared.tsx index 6608b95042de..32cb0aa18a59 100644 --- a/src/plugins/data/public/ui/query_editor/editors/shared.tsx +++ b/src/plugins/data/public/ui/query_editor/editors/shared.tsx @@ -95,6 +95,7 @@ export const SingleLineInput: React.FC = ({ }} suggestionProvider={{ provideCompletionItems, + triggerCharacters: [' '], }} languageConfiguration={{ autoClosingPairs: [ @@ -108,6 +109,7 @@ export const SingleLineInput: React.FC = ({ }, ], }} + triggerSuggestOnFocus={true} />
diff --git a/src/plugins/data/public/ui/query_editor/query_editor.tsx b/src/plugins/data/public/ui/query_editor/query_editor.tsx index 6ef8a256e21d..ce0b5ddb88fe 100644 --- a/src/plugins/data/public/ui/query_editor/query_editor.tsx +++ b/src/plugins/data/public/ui/query_editor/query_editor.tsx @@ -305,6 +305,7 @@ export default class QueryEditorUI extends Component { insertText: s.insertText ?? s.text, range: s.replacePosition ?? defaultRange, detail: s.detail, + command: { id: 'editor.action.triggerSuggest', title: 'Trigger Next Suggestion' }, }; }) : [], diff --git a/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx b/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx index 8996297775c9..137f369c9b9c 100644 --- a/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx +++ b/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx @@ -108,6 +108,11 @@ export interface Props { * Should the editor use the dark theme */ useDarkTheme?: boolean; + + /** + * Whether the suggestion widget/window will be triggered upon clicking into the editor + */ + triggerSuggestOnFocus?: boolean; } export class CodeEditor extends React.Component { @@ -141,6 +146,12 @@ export class CodeEditor extends React.Component { if (this.props.editorDidMount) { this.props.editorDidMount(editor); } + + if (this.props.triggerSuggestOnFocus) { + editor.onDidFocusEditorWidget(() => { + editor.trigger('keyboard', 'editor.action.triggerSuggest', {}); + }); + } }; render() { From 5483f57abbfcc19b0ca49bc1c25cdb1ae8755859 Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Wed, 4 Sep 2024 09:32:21 -0700 Subject: [PATCH 02/10] modify dql suggestions to keep suggestion chaining fluid Signed-off-by: Paul Sebastian --- src/plugins/data/public/antlr/dql/code_completion.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/public/antlr/dql/code_completion.ts b/src/plugins/data/public/antlr/dql/code_completion.ts index a14310f56979..63ede2436385 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.ts @@ -135,7 +135,7 @@ export const getSuggestions = async ({ // check to see if field rule is a candidate. if so, suggest field names if (candidates.rules.has(DQLParser.RULE_field)) { - completions.push(...fetchFieldSuggestions(indexPattern, (f) => `${f}: `)); + completions.push(...fetchFieldSuggestions(indexPattern, (f: any) => `${f}: `)); } interface FoundLastValue { @@ -247,6 +247,7 @@ export const getSuggestions = async ({ cursorLine, cursorColumn + 1 ), + insertText: `${val} `, }; }) ); @@ -266,6 +267,7 @@ export const getSuggestions = async ({ text: tokenSymbolName, type: monaco.languages.CompletionItemKind.Keyword, detail: SuggestionItemDetailsTags.Keyword, + insertText: `${tokenSymbolName} `, }); } }); From 07928e0d5f88b93d5a7aac79244ff5e2a69a1cfc Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:41:14 +0000 Subject: [PATCH 03/10] Changeset file for PR #7991 created/updated --- changelogs/fragments/7991.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/7991.yml diff --git a/changelogs/fragments/7991.yml b/changelogs/fragments/7991.yml new file mode 100644 index 000000000000..c53e4b18eca5 --- /dev/null +++ b/changelogs/fragments/7991.yml @@ -0,0 +1,2 @@ +feat: +- Keep Autocomplete Suggestion Window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file From dc3f22d301a1a1668323931771044e584aab25c2 Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Wed, 4 Sep 2024 14:49:42 -0700 Subject: [PATCH 04/10] user hints Signed-off-by: Paul Sebastian --- .../public/ui/query_editor/_query_editor.scss | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/plugins/data/public/ui/query_editor/_query_editor.scss b/src/plugins/data/public/ui/query_editor/_query_editor.scss index 770160de8c1d..561ea6217f84 100644 --- a/src/plugins/data/public/ui/query_editor/_query_editor.scss +++ b/src/plugins/data/public/ui/query_editor/_query_editor.scss @@ -199,3 +199,24 @@ border: none; } } + +.suggest-widget { + position: relative; + + &.visible::after { + position: absolute; + bottom: -30px; + left: 0; + width: 100%; + height: 30px; + background-color: $euiColorLightestShade; + border: 1px solid $euiColorLightShade; + padding: 5px; + padding-top: 4px; + text-align: left; + color: $euiColorDarkShade; + font-size: small; + content: "Tab to insert, ESC to close window"; + display: block; + } +} From 4cc7be2e022dc86af737cff2f43516173583feab Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Wed, 4 Sep 2024 15:01:23 -0700 Subject: [PATCH 05/10] specify dql operators in details and icon Signed-off-by: Paul Sebastian --- .../data/public/antlr/dql/code_completion.ts | 13 +++++++++++-- src/plugins/data/public/antlr/shared/constants.ts | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/public/antlr/dql/code_completion.ts b/src/plugins/data/public/antlr/dql/code_completion.ts index 63ede2436385..5968d2408c11 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.ts @@ -254,6 +254,8 @@ export const getSuggestions = async ({ } } + const dqlOperators = new Set([DQLParser.AND, DQLParser.OR, DQLParser.NOT]); + // suggest other candidates, mainly keywords [...candidates.tokens.keys()].forEach((token: number) => { // ignore identifier, already handled with field rule @@ -262,11 +264,18 @@ export const getSuggestions = async ({ } const tokenSymbolName = parser.vocabulary.getSymbolicName(token)?.toLowerCase(); + if (tokenSymbolName) { + let type = monaco.languages.CompletionItemKind.Keyword; + let detail = SuggestionItemDetailsTags.Keyword; + if (dqlOperators.has(token)) { + type = monaco.languages.CompletionItemKind.Operator; + detail = SuggestionItemDetailsTags.Operator; + } completions.push({ text: tokenSymbolName, - type: monaco.languages.CompletionItemKind.Keyword, - detail: SuggestionItemDetailsTags.Keyword, + type, + detail, insertText: `${tokenSymbolName} `, }); } diff --git a/src/plugins/data/public/antlr/shared/constants.ts b/src/plugins/data/public/antlr/shared/constants.ts index bd38cedc3822..16fe97b737a0 100644 --- a/src/plugins/data/public/antlr/shared/constants.ts +++ b/src/plugins/data/public/antlr/shared/constants.ts @@ -8,5 +8,6 @@ export const enum SuggestionItemDetailsTags { Keyword = 'Keyword', AggregateFunction = 'Aggregate Function', Value = 'Value', + Operator = 'Operator', } export const quotesRegex = /^'(.*)'$/; From 38b92ff98b8f648105aca9a8479df4bfd2683856 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 22:06:31 +0000 Subject: [PATCH 06/10] Changeset file for PR #7991 created/updated --- changelogs/fragments/7991.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/changelogs/fragments/7991.yml b/changelogs/fragments/7991.yml index c53e4b18eca5..4ee8e1bdc141 100644 --- a/changelogs/fragments/7991.yml +++ b/changelogs/fragments/7991.yml @@ -1,2 +1,6 @@ feat: -- Keep Autocomplete Suggestion Window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file +- Keep Autocomplete Suggestion Window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) +- User hints below the Suggestion Window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) + +fix: +- DQL Autocomplete Operators ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file From 653fd4cf9734185b713993bf0494ae0ae3bb1224 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 22:08:35 +0000 Subject: [PATCH 07/10] Changeset file for PR #7991 created/updated --- changelogs/fragments/7991.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/changelogs/fragments/7991.yml b/changelogs/fragments/7991.yml index 4ee8e1bdc141..1cd0d0460cf4 100644 --- a/changelogs/fragments/7991.yml +++ b/changelogs/fragments/7991.yml @@ -1,6 +1,6 @@ feat: -- Keep Autocomplete Suggestion Window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) -- User hints below the Suggestion Window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) +- Keep Autocomplete suggestion window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) +- User hints below the suggestion window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) fix: -- DQL Autocomplete Operators ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file +- DQL Autocomplete Operators distinguished ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file From 1ffc97218fd46204caa41b9d0758b21797cfd2f4 Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Wed, 4 Sep 2024 15:58:21 -0700 Subject: [PATCH 08/10] update testing constants Signed-off-by: Paul Sebastian --- .../public/antlr/dql/code_completion.test.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/plugins/data/public/antlr/dql/code_completion.test.ts b/src/plugins/data/public/antlr/dql/code_completion.test.ts index 7a4efe719cc1..547ccc615e31 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.test.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.test.ts @@ -174,11 +174,11 @@ const testingIndex = ({ } as unknown) as IndexPattern; const booleanOperatorSuggestions = [ - { text: 'or', type: 17, detail: 'Keyword' }, - { text: 'and', type: 17, detail: 'Keyword' }, + { text: 'or', type: 11, detail: 'Operator', insertText: 'or ' }, + { text: 'and', type: 11, detail: 'Operator', insertText: 'and ' }, ]; -const notOperatorSuggestion = { text: 'not', type: 17, detail: 'Keyword' }; +const notOperatorSuggestion = { text: 'not', type: 11, detail: 'Operator', insertText: 'not ' }; const fieldNameSuggestions: Array<{ text: string; @@ -211,27 +211,31 @@ const carrierValues = [ ]; const allCarrierValueSuggestions = [ - { text: 'Logstash Airways', type: 13, detail: 'Value' }, - { text: 'BeatsWest', type: 13, detail: 'Value' }, + { text: 'Logstash Airways', type: 13, detail: 'Value', insertText: 'Logstash Airways ' }, + { text: 'BeatsWest', type: 13, detail: 'Value', insertText: 'BeatsWest ' }, { text: 'OpenSearch Dashboards Airlines', type: 13, detail: 'Value', + insertText: 'OpenSearch Dashboards Airlines ', }, - { text: 'OpenSearch-Air', type: 13, detail: 'Value' }, + { text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: 'OpenSearch-Air ' }, ]; const carrierWithNotSuggestions = allCarrierValueSuggestions.concat(notOperatorSuggestion); -const logCarrierValueSuggestion = [{ text: 'Logstash Airways', type: 13, detail: 'Value' }]; +const logCarrierValueSuggestion = [ + { text: 'Logstash Airways', type: 13, detail: 'Value', insertText: 'Logstash Airways ' }, +]; const openCarrierValueSuggestion = [ { text: 'OpenSearch Dashboards Airlines', type: 13, detail: 'Value', + insertText: 'OpenSearch Dashboards Airlines ', }, - { text: 'OpenSearch-Air', type: 13, detail: 'Value' }, + { text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: 'OpenSearch-Air ' }, ]; const addPositionToValue = (vals: any, start: number, end: number) => From 346c232eb14d9a1207aa92804eec4417a9eb01c8 Mon Sep 17 00:00:00 2001 From: Paul Sebastian Date: Thu, 5 Sep 2024 14:32:48 -0700 Subject: [PATCH 09/10] modify scss Signed-off-by: Paul Sebastian --- .../data/public/ui/query_editor/_query_editor.scss | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/plugins/data/public/ui/query_editor/_query_editor.scss b/src/plugins/data/public/ui/query_editor/_query_editor.scss index 561ea6217f84..3e9a6ac61c76 100644 --- a/src/plugins/data/public/ui/query_editor/_query_editor.scss +++ b/src/plugins/data/public/ui/query_editor/_query_editor.scss @@ -205,17 +205,16 @@ &.visible::after { position: absolute; - bottom: -30px; + height: auto; + bottom: auto; left: 0; width: 100%; - height: 30px; background-color: $euiColorLightestShade; - border: 1px solid $euiColorLightShade; - padding: 5px; - padding-top: 4px; + border: $euiBorderThin; + padding: $euiSizeXS; text-align: left; color: $euiColorDarkShade; - font-size: small; + font-size: $euiFontSizeXS; content: "Tab to insert, ESC to close window"; display: block; } From ca571d0f9bf816890bc25a960dd918f4daa8254a Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:38:55 +0000 Subject: [PATCH 10/10] Changeset file for PR #7991 created/updated --- changelogs/fragments/7991.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/changelogs/fragments/7991.yml b/changelogs/fragments/7991.yml index 1cd0d0460cf4..f60b36710c5e 100644 --- a/changelogs/fragments/7991.yml +++ b/changelogs/fragments/7991.yml @@ -1,6 +1,2 @@ feat: -- Keep Autocomplete suggestion window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) -- User hints below the suggestion window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) - -fix: -- DQL Autocomplete Operators distinguished ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file +- Keep Autocomplete suggestion window open and put user hints below the suggestion window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991)) \ No newline at end of file