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

Conversation

ibolton336
Copy link
Member

@ibolton336 ibolton336 commented May 9, 2024

Resolves https://issues.redhat.com/browse/MTA-2795

  • Resolves any potential duplicates between hardcoded default targets / sources labels & parsed labels from targets.

Copy link

codecov bot commented May 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 42.16%. Comparing base (b654645) to head (1c88bea).
Report is 158 commits behind head on main.

Files Patch % Lines
...pages/applications/analysis-wizard/set-options.tsx 0.00% 10 Missing ⚠️
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     
Flag Coverage Δ
client 42.16% <0.00%> (+2.96%) ⬆️
server ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@sjd78 sjd78 left a 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?

Comment on lines 80 to 72
const labelsSeen = new Set();
const uniqueTargetsAndLabels = defaultTargetsAndTargetsLabels.filter(
(target) => {
if (labelsSeen.has(target.label)) {
return false;
}
labelsSeen.add(target.label);
return true;
}
);

Copy link
Member

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.

Copy link
Member Author

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.

@sjd78 sjd78 added this to the v0.5.0 milestone May 23, 2024
@ibolton336 ibolton336 force-pushed the remove-dupe-targets branch 2 times, most recently from f4b91a4 to 1db9932 Compare June 10, 2024 19:15
@ibolton336
Copy link
Member Author

Have a look at the filters being used for allTargetLabelsFromTargets and allSourceLabelsFromTargets -- they don't look right.

+1 Just pushed this suggested update.

Finally, any insight as to why the TargetLabel names are completely ignored and just a parsed bit of the label is used?

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.

Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

LGTM

@sjd78 sjd78 requested a review from rszwajko June 10, 2024 19:33
...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.

Copy link
Member

@sjd78 sjd78 left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants