From 52d76e4b52ea9c3a2f84af49463c26b1a9f052b8 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 10 Jun 2024 20:20:11 -0400 Subject: [PATCH] :bug: Remove duplicate targets in advanced options screen (#1906) Resolves https://issues.redhat.com/browse/MTA-2795 - Resolves any potential duplicates between hardcoded default targets / sources labels & parsed labels from targets. 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 e281acdccd..8efc561b35 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 (