Skip to content

Commit

Permalink
🐛 Remove duplicate targets in advanced options screen (#1906)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ibolton336 authored Jun 11, 2024
1 parent 2d55320 commit 52d76e4
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions client/src/app/pages/applications/analysis-wizard/set-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Form
Expand Down

0 comments on commit 52d76e4

Please sign in to comment.