From 8e144557302e3241daa099dce5c0c3f4b2e25b26 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Wed, 27 Nov 2024 09:45:21 +0100 Subject: [PATCH] Use map for deduping rather than lodash --- .../console/public/lib/autocomplete/engine.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/plugins/console/public/lib/autocomplete/engine.js b/src/plugins/console/public/lib/autocomplete/engine.js index e0c20d1afa745..8f9235ceb0a0f 100644 --- a/src/plugins/console/public/lib/autocomplete/engine.js +++ b/src/plugins/console/public/lib/autocomplete/engine.js @@ -119,7 +119,7 @@ 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) { @@ -127,14 +127,16 @@ export function populateContext(tokenPath, context, editor, includeAutoComplete, if (!_.isObject(term)) { term = { name: term }; } - // Make sure we don't have duplicates - if (!_.find(autoCompleteSet, { name: term.name })) { - 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; }