-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1906 +/- ##
==========================================
+ Coverage 39.20% 42.16% +2.96%
==========================================
Files 146 166 +20
Lines 4857 5319 +462
Branches 1164 1292 +128
==========================================
+ Hits 1904 2243 +339
- Misses 2939 3060 +121
- Partials 14 16 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at the filters being used for allTargetLabelsFromTargets
and allSourceLabelsFromTargets
-- they don't look right.
Those could really be simplied to just:
xyz = allLabelsFromTargets.filter(
(label) => getParsedLabel(label?.label)?.labelType === "target" // or "source"
);
Next, both the defaultTargetsAndTargetsLabels
and defaultSourcesAndSourcesLabels
can be deduped and sorted the same way for a consistent list experience.
Finally, any insight as to why the TargetLabel
names are completely ignored and just a parsed bit of the label is used?
const labelsSeen = new Set(); | ||
const uniqueTargetsAndLabels = defaultTargetsAndTargetsLabels.filter( | ||
(target) => { | ||
if (labelsSeen.has(target.label)) { | ||
return false; | ||
} | ||
labelsSeen.add(target.label); | ||
return true; | ||
} | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think you can just do the same thing as is done for defaultSourcesAndSourcesLabels
and then sort based on the label as it is done now.
So more like...
const defaultTargetsAndTargetsLabels = [
...new Set(defaultTargets.concat(allTargetLabelsFromTargets))
].sort((t1, t2) => {
if (t1.label > t2.label) return 1;
if (t1.label < t2.label) return -1;
return 0;
});
Then the existing use of defaultTargetsAndTargetsLabels
all stay the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this doesn't fix the dupe issue since the objects from the two arrays are constructed separately. Set isn't working how we'd expect here. Need to do the concat before the set I think.
f4b91a4
to
1db9932
Compare
+1 Just pushed this suggested update.
I think the idea was to keep a mapping back to the names original form so that we have a display value & one that we can pass to the hub when updating the relevant resources. |
48bc75b
to
1ecef94
Compare
Signed-off-by: Ian Bolton <[email protected]>
1ecef94
to
49c2ccb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
...new Set(defaultSources.concat(allSourceLabelsFromTargets)), | ||
]; | ||
const defaultSourcesAndSourcesLabels = Array.from( | ||
new Map( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM -- more obvious what you're doing there now!
Resolves https://issues.redhat.com/browse/MTA-2795