Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Remove duplicate targets in advanced options screen #1906

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Changes from 1 commit
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
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(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Solution: Concatenates two arrays and processes them to ensure uniqueness based on the label property by transforming each item into key-value pairs, storing them in a new Map to overwrite duplicates, and then converting the map's values back into an array.

defaultSources
.concat(allSourceLabelsFromTargets)
.map((item) => [item.label, item])
).values()
).sort((t1, t2) => universalComparator(t1.label, t2.label));

return (
<Form
Expand Down
Loading