[Console] Avoid duplicate suggestions in autocomplete#201766
[Console] Avoid duplicate suggestions in autocomplete#201766sabarasaba merged 4 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/kibana-management (Team:Kibana Management) |
| } | ||
| autoCompleteSet.push(term); | ||
| // Make sure we don't have duplicates | ||
| if (!_.find(autoCompleteSet, { name: term.name })) { |
There was a problem hiding this comment.
I wonder if it would make more sense to use a Set here so that items can be added without needing to loop over the array. Does the array get big? Do we have any performance concerns with this code?
There was a problem hiding this comment.
Yeah I think we can reduce complexity if we avoid the find, I ended up going for a map rather than a set to avoid having to serialize the term with JSON.stringify. It doesnt get big at all afaict, mostly autocomplete terms are in the order of <=20 or so, so should be pretty safe performance wise
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Async chunks
History
cc @sabarasaba |
| autoCompleteSet.push(term); | ||
|
|
||
| // Add the term to the autoCompleteSet if it doesn't already exist | ||
| if (!autoCompleteSet.has(term.name)) { |
There was a problem hiding this comment.
Any reason to avoid using a Set instead of a Map? This comparation won't be needed
There was a problem hiding this comment.
Nevermind, I just read [this] explanation that you give to Matt in this same PR. It makes sense. Approving.
|
Starting backport for target branches: 8.16, 8.17, 8.x https://github.com/elastic/kibana/actions/runs/12084340732 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
(cherry picked from commit 82de734) # Conflicts: # test/functional/apps/console/_autocomplete.ts
(cherry picked from commit 82de734) # Conflicts: # test/functional/apps/console/_autocomplete.ts
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
(cherry picked from commit 82de734) # Conflicts: # test/functional/apps/console/_autocomplete.ts
#202481) # Backport This will backport the following commits from `main` to `8.17`: - [[Console] Avoid duplicate suggestions in autocomplete (#201766)](#201766) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ignacio Rivas","email":"rivasign@gmail.com"},"sourceCommit":{"committedDate":"2024-11-29T11:58:39Z","message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana Management","release_note:skip","backport missing","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"number":201766,"url":"https://github.com/elastic/kibana/pull/201766","mergeCommit":{"message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201766","number":201766,"mergeCommit":{"message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
#202482) # Backport This will backport the following commits from `main` to `8.16`: - [[Console] Avoid duplicate suggestions in autocomplete (#201766)](#201766) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ignacio Rivas","email":"rivasign@gmail.com"},"sourceCommit":{"committedDate":"2024-11-29T11:58:39Z","message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana Management","release_note:skip","backport missing","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"number":201766,"url":"https://github.com/elastic/kibana/pull/201766","mergeCommit":{"message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201766","number":201766,"mergeCommit":{"message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
…#202484) # Backport This will backport the following commits from `main` to `8.x`: - [[Console] Avoid duplicate suggestions in autocomplete (#201766)](#201766) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ignacio Rivas","email":"rivasign@gmail.com"},"sourceCommit":{"committedDate":"2024-11-29T11:58:39Z","message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana Management","release_note:skip","backport missing","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"number":201766,"url":"https://github.com/elastic/kibana/pull/201766","mergeCommit":{"message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201766","number":201766,"mergeCommit":{"message":"[Console] Avoid duplicate suggestions in autocomplete (#201766)","sha":"82de734e6c7b67d90213b7058b1109f9f375710e"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/202482","number":202482,"state":"OPEN"},{"branch":"8.17","label":"v8.17.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/202481","number":202481,"state":"OPEN"}]}] BACKPORT-->
Fixes: #201670
Summary
The duplicate options are the ones being suggested by both the "script processor" and the "script" global defined within console. Previously in the ace editor these were being internally deduped by brace but this isnt a thing with monaco.
This PR fixes the issue by deduping the entries before returning the autocomplete suggestions.
How to test
Using the following command, trigger the autocomplete within the
scriptbody: