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

Improve Table component API #960

Merged
merged 15 commits into from
Jun 9, 2021
Merged

Improve Table component API #960

merged 15 commits into from
Jun 9, 2021

Conversation

robinmetral
Copy link
Contributor

@robinmetral robinmetral commented Jun 2, 2021

Purpose

As a follow-up to #852 there were a few things we wanted to address around the Table component, as breaking changes for v3:

  • the custom onSortBy method's nextDirection argument moved to the third position (index, nextDirection, rows 👉 index, rows, nextDirection) and can now be undefined (instead of null in the previous implementation). This improves the implementation with TypeScript since it becomes an optional parameter.
  • for sortable columns (when headers have the sortable prop), the previously optional sortLabel prop is now enforced. This is an accessibility requirement. If a sortLabel is not provided, the column will not be sortable.
    • I refactored some of the logic around this part of the code to make sure that sortable params are consistently applied. If either of the sortable and sortLabel props are missing, we should not apply the sorting event handlers, styles, etc.
  • the TableHeader, TableRow and TableCell components are no longer exported from Circuit. They are only used internally by the Table component and should not be used directly.
  • default test-ids are no longer built into the component. They can still be passed manually. We could also recommend querying by role in tests

BONUS (non-breaking): fixed a table header height bug on mobile when words would wrap and rows would become misaligned.

Approach and changes

☝️

Definition of done

  • Development completed
  • Reviewers assigned
  • Unit and integration tests
  • Meets minimum browser support
  • Meets accessibility requirements

Robin Metral added 8 commits June 1, 2021 15:21
nextDirection is now optional (instad of null) and therefore moved to the third argument
This commit also fixes a TS error where sortLabel was not declared on the Cell type.

It does not differentiate between header and body cells (same as before), which means that users might think that sorting-related props like sortLabel are available on body cells, where they are not. Unfortunately, making the types stricter here will require a larger refactoring around the table utils which are currently shared by the header and body cells alike.
This commit also includes a refactoring around how the sort options are handled, because we want to prevent the column from sorting if a sortLabel is not set. The main change is a new getSortParams util that is called in TableHead before the params are passed to the Table Header.
We should only export the main Table component and relevant types
This reverts commit a94f6a3.

The testids are still set as defaults used in other Table components for testing, so it makes seense to keep it in the TableCell as well.
@changeset-bot
Copy link

changeset-bot bot commented Jun 2, 2021

🦋 Changeset detected

Latest commit: 719818d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sumup/circuit-ui Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jun 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/sumup/oss-circuit-ui/24GvtW5xYoSx5vth3PwUVyfyqtnQ
✅ Preview: https://oss-circuit-ui-git-table-breaking-changes-sumup.vercel.app

@sumup-clark
Copy link

sumup-clark bot commented Jun 2, 2021

Hey @robinmetral,
we are super excited that you are contributing! 🎉There's one more thing you need to do. Please accept our Contributor License Agreement. It helps you and us to collaborate on clear terms and focus on what we love most: code.

Thanks!

@codecov
Copy link

codecov bot commented Jun 2, 2021

Codecov Report

Merging #960 (719818d) into next (f3fd131) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next     #960      +/-   ##
==========================================
- Coverage   91.55%   91.52%   -0.04%     
==========================================
  Files         163      162       -1     
  Lines        2984     2973      -11     
  Branches      759      757       -2     
==========================================
- Hits         2732     2721      -11     
  Misses        223      223              
  Partials       29       29              
Impacted Files Coverage Δ
...omponents/Table/components/SortArrow/SortArrow.tsx 100.00% <ø> (ø)
...components/Table/components/TableCell/TableCell.ts 100.00% <ø> (ø)
.../components/Table/components/TableRow/TableRow.tsx 100.00% <ø> (ø)
packages/circuit-ui/components/Table/Table.tsx 94.62% <100.00%> (ø)
...omponents/Table/components/TableBody/TableBody.tsx 100.00% <100.00%> (ø)
...omponents/Table/components/TableHead/TableHead.tsx 91.17% <100.00%> (ø)
...nents/Table/components/TableHeader/TableHeader.tsx 100.00% <100.00%> (ø)
packages/circuit-ui/components/Table/utils.ts 93.54% <100.00%> (+1.24%) ⬆️

@robinmetral robinmetral changed the title Table breaking changes Improve Table component API Jun 9, 2021
@robinmetral robinmetral merged commit 1a1a364 into next Jun 9, 2021
@robinmetral robinmetral deleted the table-breaking-changes branch June 9, 2021 09:24
@github-actions github-actions bot mentioned this pull request Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants