Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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