From 49c2ccbce74fdab1c6d228cb9d2195316c88d3f3 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Thu, 9 May 2024 10:10:50 -0400 Subject: [PATCH] :bug: Remove duplicate targets in advanced options screen Signed-off-by: Ian Bolton --- .../analysis-wizard/set-options.tsx | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/client/src/app/pages/applications/analysis-wizard/set-options.tsx b/client/src/app/pages/applications/analysis-wizard/set-options.tsx index e281acdcc..8efc561b3 100644 --- a/client/src/app/pages/applications/analysis-wizard/set-options.tsx +++ b/client/src/app/pages/applications/analysis-wizard/set-options.tsx @@ -54,28 +54,29 @@ export const SetOptions: React.FC = () => { // Remove duplicates from array of objects based on label value (label.label) .filter((v, i, a) => a.findIndex((v2) => v2.label === v.label) === i); - const allTargetLabelsFromTargets = allLabelsFromTargets.filter((label) => { - const parsedLabel = getParsedLabel(label?.label); - if (parsedLabel.labelType === "target") { - return parsedLabel.labelValue; - } - }); + const allTargetLabelsFromTargets = allLabelsFromTargets.filter( + (label) => getParsedLabel(label?.label).labelType === "target" + ); - const allSourceLabelsFromTargets = allLabelsFromTargets.filter((label) => { - const parsedLabel = getParsedLabel(label?.label); - if (parsedLabel.labelType === "source") { - return parsedLabel.labelValue; - } - }); + const allSourceLabelsFromTargets = allLabelsFromTargets.filter( + (label) => getParsedLabel(label?.label).labelType === "source" + ); - const defaultTargetsAndTargetsLabels = [ - ...defaultTargets, - ...allTargetLabelsFromTargets, - ].sort((t1, t2) => universalComparator(t1.label, t2.label)); + const defaultTargetsAndTargetsLabels = Array.from( + new Map( + defaultTargets + .concat(allTargetLabelsFromTargets) + .map((item) => [item.label, item]) + ).values() + ).sort((t1, t2) => universalComparator(t1.label, t2.label)); - const defaultSourcesAndSourcesLabels = [ - ...new Set(defaultSources.concat(allSourceLabelsFromTargets)), - ]; + const defaultSourcesAndSourcesLabels = Array.from( + new Map( + defaultSources + .concat(allSourceLabelsFromTargets) + .map((item) => [item.label, item]) + ).values() + ).sort((t1, t2) => universalComparator(t1.label, t2.label)); return (