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

fix: Display all options for CollectionPreferences content display #2807

Merged

Conversation

youdz
Copy link
Contributor

@youdz youdz commented Oct 4, 2024

Description

Currently in the CollectionPreferences, if the preferences.contentDisplay prop includes 3 values but the contentDisplayPreference lists 50 options, we only display the 3 options. This seems like a clear bug, as the list of full options with label should probably be the source of truth on which ones to allow the customer to toggle and order.

This PR ensures options present in contentDisplayPreference but not in preferences.contentDisplay are displayed last and made visible: false. Given that this is a cheap bug fix, I figured I could open a PR and discuss directly here, and if I missed something and it is expected behavior then I lost very little time.

Note that in order to ensure the "missing" options can be toggled and reordered, the preferences.contentDisplay value needs to be updated. A common solution for this is to use an effect, but I believe this is an anti-pattern that results in effect hell. Instead, I decided to only add the missing options to the value right before calling onChange, so this is easily traceable and debuggable.

Related links, issue #, if available: None

How has this been tested?

Tested using the longOptionsList example in the CollectionPreferences demo page passing

contentDisplay: [
  { id: 'id_3', visible: true },
  { id: 'id_1', visible: true },
]

Before
Screenshot 2024-10-03 at 20 49 10

After
All 50 options displayed, toggleable and reorderable

I also ran unit tests to ensure backward compatibility, and added five new tests for the expected behavior as it's very easy to miss. The fact that no test failed seems to confirm the current behavior is not intended.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@youdz youdz requested a review from a team as a code owner October 4, 2024 00:49
@youdz youdz requested review from gethinwebster and removed request for a team October 4, 2024 00:49
@youdz youdz changed the title fix: Display all options for CollectionPreferences content display [Do not merge, has bug] fix: Display all options for CollectionPreferences content display Oct 4, 2024
@youdz
Copy link
Contributor Author

youdz commented Oct 4, 2024

I just realized I missed an update, the non-value options are not editable. My bad, I'll update the PR.

EDIT: Updated, the appended options can be toggled and reordered correctly. Live announcements are also correct.

@youdz youdz force-pushed the eudes/content-display-options-fix branch from 858bb68 to db05485 Compare October 4, 2024 13:32
@youdz youdz changed the title [Do not merge, has bug] fix: Display all options for CollectionPreferences content display fix: Display all options for CollectionPreferences content display Oct 4, 2024
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.20%. Comparing base (a0670ee) to head (4c4e416).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2807      +/-   ##
==========================================
- Coverage   96.20%   96.20%   -0.01%     
==========================================
  Files         761      761              
  Lines       21447    21451       +4     
  Branches     6940     6941       +1     
==========================================
+ Hits        20633    20636       +3     
- Misses        806      807       +1     
  Partials        8        8              

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

return [sorted, filtered];
}, [columnFilteringText, options, value]);

const addMissingOptionsInValue = () => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this pattern of having to call this addMissingOptionsInValue function in multiple places before calling onChange, could we instead use sortedOptions directly in place of value throughout this component? Or create a function that wraps onChange and does the addMissing in just one place?

Copy link
Contributor Author

@youdz youdz Oct 15, 2024

Choose a reason for hiding this comment

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

Good call, I was deep in the weeds when I wrote this and reading it again, it does look weird. I'll fix that and submit a new revision right now.

EDIT: We end up with the trimming to { id, visible } being inline, but I think that's fair as one of the two places it's used does it directly baked into the toggle logic.

@youdz youdz force-pushed the eudes/content-display-options-fix branch from db05485 to bc999a3 Compare October 15, 2024 14:19
@youdz
Copy link
Contributor Author

youdz commented Oct 15, 2024

New revision is rebased on latest main, and addresses @gethinwebster's comment.

gethinwebster
gethinwebster previously approved these changes Oct 17, 2024
@gethinwebster gethinwebster added this pull request to the merge queue Oct 18, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 18, 2024
…2807)

Co-authored-by: Gethin Webster <gethinw@amazon.de>
Co-authored-by: Gethin Webster <gethinw@amazon.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 18, 2024
@gethinwebster gethinwebster added this pull request to the merge queue Oct 18, 2024
Merged via the queue into cloudscape-design:main with commit b69c9b2 Oct 18, 2024
36 of 38 checks passed
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