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

BREAKING: refactor useTable to be composable #24947

Merged
merged 2 commits into from
Oct 4, 2022

Conversation

ling1726
Copy link
Member

@ling1726 ling1726 commented Sep 26, 2022

⚠️ BREAKING CHANGE

This PR refactors the useTable API to be more composable. The useTable hook now accepts plugins that will modify/enhance the state.

Due to typescript limitations, the state is completely typed on our side and any extension that's not an officially supported plugin will need to extend types in userland. The main benefit is that future features for the table can be more SOLID through the implementation of plugins.

The plugins in theory can be order dependent, however there is no plugin that has this limitation.

Current Behavior

All functionality was configured on the single useTable hook.

const {
    rows,
    sort: { getSortDirection, toggleColumnSort },
  } = useTable({ columns, items, defaultSortState: { sortColumn: 'file', sortDirection: 'ascending' } });

New Behavior

Functionality should be composed from the useTable hook using other react hooks that are plugins for the table state. Unless the relevant hook plugin is used, the user will have default state which is essentially a more complex noop

const {
    getRows,
    sort: { getSortDirection, toggleColumnSort, sort },
  } = useTable(
    {
      columns,
      items,
    },
    [useSort({ defaultSortState: { sortColumn: 'file', sortDirection: 'ascending' } })],
  );

Prototypes of other plugins such as pagination and column sizing can be found in #24944

Related Issue(s)

Fixes #24226

@fabricteam
Copy link
Collaborator

fabricteam commented Sep 26, 2022

📊 Bundle size report

Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
189.188 kB
52.396 kB
react-components
react-components: FluentProvider & webLightTheme
33.4 kB
11.008 kB
react-portal-compat
PortalCompatProvider
5.857 kB
1.978 kB
🤖 This report was generated against 5129090c2dedbaf91b8441898788413992c556e3

@size-auditor
Copy link

size-auditor bot commented Sep 26, 2022

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 5129090c2dedbaf91b8441898788413992c556e3 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Sep 26, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1573 1556 5000
Button mount 1100 1067 5000
FluentProvider mount 1841 1789 5000
FluentProviderWithTheme mount 660 662 10
FluentProviderWithTheme virtual-rerender 612 670 10
FluentProviderWithTheme virtual-rerender-with-unmount 654 669 10
MakeStyles mount 2150 2119 50000
SpinButton mount 3069 3017 5000

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 26, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit edf133a:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@ling1726 ling1726 force-pushed the feat/use-table-break-up branch 3 times, most recently from a06d38c to 3366f29 Compare September 26, 2022 13:30
@ling1726 ling1726 force-pushed the feat/use-table-break-up branch from 3366f29 to 382488a Compare September 26, 2022 13:42
@ling1726 ling1726 marked this pull request as ready for review September 26, 2022 14:05
@ling1726 ling1726 requested a review from a team as a code owner September 26, 2022 14:05
};

export function useSelection<TItem>(options: UseSelectionOptions) {
// eslint-disable-next-line react-hooks/rules-of-hooks
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Would be nice to add a comment here explaining why this is not a big deal.

};

export function useSort<TItem>(options: UseSortOptions) {
// eslint-disable-next-line react-hooks/rules-of-hooks
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Would be nice to add a comment here explaining why this is not a big deal.

@ling1726 ling1726 enabled auto-merge (squash) September 29, 2022 10:42
@ling1726 ling1726 disabled auto-merge September 29, 2022 14:18
@ling1726 ling1726 merged commit 3355905 into microsoft:master Oct 4, 2022
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Oct 5, 2022
* master: (62 commits)
  chore(migrate-converged): add functionality to execute various v9 package file restructuring tasks (microsoft#24458)
  chore(react-dialog): updates stories (microsoft#25070)
  refactor Progress to remove label and description slots (microsoft#25067)
  fix(SplitButton): Remove borders from hover and pressed state in primary split buttons (microsoft#25059)
  chore(react-persona): Add vr, conformance, and unit tests (microsoft#25007)
  (docs): update Icon docs with examples (microsoft#24768)
  Split button/primary hc fix (microsoft#25066)
  chore(react-utilities): restricts trigger API types (microsoft#25044)
  Add utilities export @fluentui/style-utilities v8 (microsoft#25065)
  chore: migrate whole repo to webpack 5 (microsoft#24542)
  applying package updates
  BREAKING: refactor `useTable` to be composable (microsoft#24947)
  Added shims to shim packages (microsoft#25048)
  Add Progress SPEC (microsoft#24418)
  applying package updates
  chore(react-persona): Add bundle-size command for bundle-size fixtures (microsoft#25055)
  fix(Button): Remove margin added to buttons by Safari (microsoft#25052)
  fix: Menu triggers no longer take focus when they are mounted (microsoft#25016)
  chore: deletes react-trigger package (microsoft#25042)
  Fixed a minor typo: immmediately => immediately (microsoft#25036)
  ...
NotWoods pushed a commit to NotWoods/fluentui that referenced this pull request Nov 18, 2022
* BREAKING: refactor `useTable` to be composable

* Add docs about eslint ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table/DataGrid: Composable logic
5 participants