Skip to content

Commit

Permalink
[8.x] [Console] Avoid duplicate suggestions in autocomplete (#201766) (
Browse files Browse the repository at this point in the history
…#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":"[email protected]"},"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-->
  • Loading branch information
sabarasaba authored Dec 3, 2024
1 parent e48e833 commit 5716092
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/plugins/console/public/lib/autocomplete/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,24 @@ export function populateContext(tokenPath, context, editor, includeAutoComplete,
editor
);
if (includeAutoComplete) {
let autoCompleteSet = [];
let autoCompleteSet = new Map();
_.each(walkStates, function (ws) {
const contextForState = passThroughContext(context, ws.contextExtensionList);
_.each(ws.components, function (component) {
_.each(component.getTerms(contextForState, editor), function (term) {
if (!_.isObject(term)) {
term = { name: term };
}
autoCompleteSet.push(term);

// Add the term to the autoCompleteSet if it doesn't already exist
if (!autoCompleteSet.has(term.name)) {
autoCompleteSet.set(term.name, term);
}
});
});
});
autoCompleteSet = _.uniq(autoCompleteSet);
// Convert Map values to an array of objects
autoCompleteSet = Array.from(autoCompleteSet.values());
context.autoCompleteSet = autoCompleteSet;
}

Expand Down
22 changes: 22 additions & 0 deletions test/functional/apps/console/_autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.console.clearEditorText();
});

it('should not show duplicate suggestions', async () => {
await PageObjects.console.enterText(`POST _ingest/pipeline/_simulate
{
"pipeline": {
"processors": [
{
"script": {`);
await PageObjects.console.pressEnter();
await PageObjects.console.sleepForDebouncePeriod();
await PageObjects.console.enterText(`"`);
expect(PageObjects.console.isAutocompleteVisible()).to.be.eql(true);

// Iterate on the first 10 suggestions (the ones that are only visible without scrolling)
const suggestions = [];
for (let i = 0; i < 10; i++) {
suggestions.push(await PageObjects.console.getAutocompleteSuggestion(i));
}

// and expect the array to not have duplicates
expect(suggestions).to.eql(_.uniq(suggestions));
});

it('HTTP methods', async () => {
const suggestions = {
G: ['GET'],
Expand Down

0 comments on commit 5716092

Please sign in to comment.