Skip to content

feat: Add support for onToggleSort to DataTable #5991

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

veryfancy
Copy link
Contributor

@veryfancy veryfancy commented Apr 30, 2025

Add support for onToggleSort prop to DataTable.

Changelog

New

  • Add support for onToggleSort prop to DataTable.

Changed

Removed

Rollout strategy

  • Minor release

Testing & Reviewing

Merge checklist

@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 21:20
@veryfancy veryfancy requested a review from a team as a code owner April 30, 2025 21:20
@veryfancy veryfancy requested a review from jonrohan April 30, 2025 21:20
Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: 97d1050

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

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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

@veryfancy veryfancy self-assigned this Apr 30, 2025
@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Apr 30, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a callback to notify consumers when a sortable column header is clicked.

  • Introduces an optional onToggleSort prop in DataTableProps.
  • Invokes onToggleSort with the column ID and new direction on header clicks.
  • Covers the new behavior with a unit test and a Storybook story.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/react/src/DataTable/DataTable.tsx Added onToggleSort prop and callback invocation in header logic
packages/react/src/DataTable/tests/DataTable.test.tsx New test verifying onToggleSort calls with correct parameters
packages/react/src/DataTable/DataTable.features.stories.tsx Added WithSortEvents Storybook example using onToggleSort
.changeset/salty-bikes-learn.md Changelog entry for the onToggleSort addition
Comments suppressed due to low confidence (2)

packages/react/src/DataTable/tests/DataTable.test.tsx:891

  • [nitpick] The variable name handler is generic; consider renaming it to onToggleSortMock or onToggleSortHandler to clarify its purpose.
const handler = jest.fn()

packages/react/src/DataTable/tests/DataTable.test.tsx:921

  • Consider adding an assertion to verify that clicking the same column header a second time toggles back to ASC, e.g., a third click on 'First' calls onToggleSort('first', 'ASC').
expect(handler).toHaveBeenCalledTimes(2)

Copy link
Contributor

github-actions bot commented Apr 30, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 99.04 KB (0%)
packages/react/dist/browser.umd.js 99.13 KB (0%)

@github-actions github-actions bot temporarily deployed to storybook-preview-5991 April 30, 2025 21:33 Inactive
@github-actions github-actions bot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels May 1, 2025
@primer-integration
Copy link

👋 Hi from github/github! Your integration PR is ready: https://github.com/github/github/pull/375773

@primer-integration
Copy link

🟢 golden-jobs completed with status success.

@github-actions github-actions bot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: failing Changes in this PR cause breaking changes in gh/gh labels May 1, 2025
@veryfancy
Copy link
Contributor Author

Int tests were failing due to a date-related Flake, not this change. (Although the failing test used DataTable, which sparked extra investigation! 😅 )

Copy link
Member

@francinelucca francinelucca left a comment

Choose a reason for hiding this comment

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

Thanks so much for the contribution and for adding stories and tests! 🙏
Just oneeee tiny request

* the column id that is now sorted and the direction after the toggle
* (never `"NONE"`).
*/
onToggleSort?: (columnId: ObjectPaths<Data> | string | number, direction: Exclude<SortDirection, 'NONE'>) => void
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to resolve a merge conflict, too, and opted to force-push a single commit.

@veryfancy veryfancy force-pushed the datatable-onToggleSort branch from 3d64be9 to b9faddb Compare May 6, 2025 16:10
Copy link
Contributor

github-actions bot commented May 6, 2025

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label May 6, 2025
@veryfancy veryfancy force-pushed the datatable-onToggleSort branch from b9faddb to 97d1050 Compare May 6, 2025 16:18
@github-actions github-actions bot added integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels May 6, 2025
Copy link
Contributor

github-actions bot commented May 6, 2025

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

Copy link
Member

@francinelucca francinelucca left a comment

Choose a reason for hiding this comment

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

@francinelucca francinelucca added this pull request to the merge queue May 6, 2025
Merged via the queue into main with commit f1fedf3 May 6, 2025
45 checks passed
@francinelucca francinelucca deleted the datatable-onToggleSort branch May 6, 2025 17:15
@primer primer bot mentioned this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants