Skip to content

feat(react-tree): adds useFlatTreeItems hook to introduce flattening#26856

Merged
bsunderhus merged 11 commits intomicrosoft:masterfrom
bsunderhus:react-tree/feat--useFlatTreeItems
Feb 27, 2023
Merged

feat(react-tree): adds useFlatTreeItems hook to introduce flattening#26856
bsunderhus merged 11 commits intomicrosoft:masterfrom
bsunderhus:react-tree/feat--useFlatTreeItems

Conversation

@bsunderhus
Copy link
Contributor

@bsunderhus bsunderhus commented Feb 15, 2023

New Behavior

  1. Introduces useFlatTreeItems hook to allow the usage of a flat tree structure in the Tree component.
  2. Introduces flattenTree method to allow the usage of a nested tree structure for the consumption of the useFlatTreeItems hook.
  3. Introduces flattenTreeFromElements method to allow the usage of a nested tree structure that derives from Tree and TreeItem elements for the consumption of the useFlatTreeItems hook.
const defaultItems: FlatTreeItemProps[] = [
  {
    id: '1',
    children: <TreeItemLayout>Level 1, item 1</TreeItemLayout>,
  },
  {
    id: '1-1',
    parentId: '1',
    children: <TreeItemLayout>Level 2, item 1</TreeItemLayout>,
  },
  {
    id: '1-2',
    parentId: '1',
    children: <TreeItemLayout>Level 2, item 2</TreeItemLayout>,
  },
  {
    id: '1-3',
    parentId: '1',
    children: <TreeItemLayout>Level 2, item 3</TreeItemLayout>,
  },
  {
    id: '2',
    children: <TreeItemLayout>Level 1, item 2</TreeItemLayout>,
  },
  {
    id: '2-1',
    parentId: '2',
    children: <TreeItemLayout>Level 2, item 1</TreeItemLayout>,
  },
  {
    id: '2-1-1',
    parentId: '2-1',
    children: <TreeItemLayout>Level 3, item 1</TreeItemLayout>,
  },
  {
    id: '2-2',
    parentId: '2',
    children: <TreeItemLayout>Level 2, item 2</TreeItemLayout>,
  },
  {
    id: '2-2-1',
    parentId: '2-2',
    children: <TreeItemLayout>Level 3, item 1</TreeItemLayout>,
  },
  {
    id: '2-2-2',
    parentId: '2-2',
    children: <TreeItemLayout>Level 3, item 2</TreeItemLayout>,
  },
  {
    id: '2-2-3',
    parentId: '2-2',
    children: <TreeItemLayout>Level 3, item 3</TreeItemLayout>,
  },
  {
    id: '3',
    children: <TreeItemLayout>Level 1, item 3</TreeItemLayout>,
  },
];

export const UseFlatTreeItems = () => {
  const [treeProps, flatTreeItems] = useFlatTreeItems_unstable(defaultItems);
  return (
    <Tree {...treeProps} aria-label="Tree">
      {flatTreeItems.map(treeItemProps => (
        <TreeItem {...treeItemProps} key={treeItemProps.id} />
      ))}
    </Tree>
  );
};

@bsunderhus bsunderhus self-assigned this Feb 15, 2023
@fabricteam
Copy link
Collaborator

fabricteam commented Feb 15, 2023

📊 Bundle size report

🤖 This report was generated against 7bf995b3b64f3ffb07291fc6f7efedb00611f2de

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 15, 2023

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 7098af7:

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

@size-auditor
Copy link

size-auditor bot commented Feb 15, 2023

Asset size changes

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

Baseline commit: 7bf995b3b64f3ffb07291fc6f7efedb00611f2de (build)

@bsunderhus bsunderhus force-pushed the react-tree/feat--useFlatTreeItems branch 4 times, most recently from 8d6d89c to 5244cd4 Compare February 17, 2023 12:57
@fabricteam
Copy link
Collaborator

fabricteam commented Feb 20, 2023

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1267 1277 5000
Button mount 910 913 5000
Field mount 1955 1948 5000
FluentProvider mount 1526 1534 5000
FluentProviderWithTheme mount 577 588 10
FluentProviderWithTheme virtual-rerender 538 548 10
FluentProviderWithTheme virtual-rerender-with-unmount 578 565 10
InfoButton mount 521 528 5000
MakeStyles mount 1981 1961 50000
Persona mount 2860 2804 5000
SpinButton mount 2291 2271 5000

@fabricteam
Copy link
Collaborator

Perf Analysis (@fluentui/react-northstar)

⚠️ No perf measurements available

@fabricteam
Copy link
Collaborator

fabricteam commented Feb 20, 2023

🕵 fluentuiv9 No visual regressions between this PR and main

@fabricteam
Copy link
Collaborator

fabricteam commented Feb 20, 2023

🕵 FluentUI-v0 No visual regressions between this PR and main

@fabricteam
Copy link
Collaborator

fabricteam commented Feb 20, 2023

Perf Analysis (@fluentui/react)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
BaseButton mount 1477 1476 5000
Breadcrumb mount 3623 3635 1000
Checkbox mount 3309 3248 5000
CheckboxBase mount 2884 2965 5000
ChoiceGroup mount 5534 5551 5000
ComboBox mount 1569 1537 1000
CommandBar mount 11882 11938 1000
ContextualMenu mount 16911 16992 1000
DefaultButton mount 1767 1738 5000
DetailsRow mount 4299 4310 5000
DetailsRowFast mount 4391 4430 5000
DetailsRowNoStyles mount 4165 4104 5000
Dialog mount 3794 3827 1000
DocumentCardTitle mount 727 713 1000
Dropdown mount 4031 4011 5000
FocusTrapZone mount 2471 2533 5000
FocusZone mount 2469 2493 5000
GroupedList mount 63870 70233 2
GroupedList virtual-rerender 29973 29800 2
GroupedList virtual-rerender-with-unmount 112664 111706 2
GroupedListV2 mount 722 707 2
GroupedListV2 virtual-rerender 678 670 2
GroupedListV2 virtual-rerender-with-unmount 697 708 2
IconButton mount 2451 2457 5000
Label mount 910 914 5000
Layer mount 5494 5458 5000
Link mount 999 1026 5000
MenuButton mount 2124 2084 5000
MessageBar mount 2931 2893 5000
Nav mount 4028 4118 1000
OverflowSet mount 1701 1673 5000
Panel mount 3152 3164 1000
Persona mount 1663 1649 1000
Pivot mount 2047 2040 1000
PrimaryButton mount 1912 1979 5000
Rating mount 8723 8857 5000
SearchBox mount 1855 1854 5000
Shimmer mount 3600 3517 5000
Slider mount 2706 2658 5000
SpinButton mount 5765 5815 5000
Spinner mount 1006 986 5000
SplitButton mount 3875 3910 5000
Stack mount 1012 1039 5000
StackWithIntrinsicChildren mount 2899 2830 5000
StackWithTextChildren mount 6054 6014 5000
SwatchColorPicker mount 12932 13022 5000
TagPicker mount 3278 3182 5000
TeachingBubble mount 109797 111292 5000
Text mount 987 1015 5000
TextField mount 1991 2035 5000
ThemeProvider mount 1940 1930 5000
ThemeProvider virtual-rerender 1350 1375 5000
ThemeProvider virtual-rerender-with-unmount 2726 2738 5000
Toggle mount 1423 1405 5000
buttonNative mount 695 677 5000

@bsunderhus bsunderhus force-pushed the react-tree/feat--useFlatTreeItems branch 3 times, most recently from 36a55d0 to 784735c Compare February 24, 2023 16:51
@bsunderhus bsunderhus force-pushed the react-tree/feat--useFlatTreeItems branch 4 times, most recently from 3fba050 to 1c49e6e Compare February 25, 2023 21:01
@bsunderhus bsunderhus marked this pull request as ready for review February 25, 2023 21:02
@bsunderhus bsunderhus requested a review from a team as a code owner February 25, 2023 21:02
@bsunderhus bsunderhus force-pushed the react-tree/feat--useFlatTreeItems branch from 48219fb to ebec91e Compare February 27, 2023 12:21
@bsunderhus bsunderhus enabled auto-merge (squash) February 27, 2023 16:57
@bsunderhus bsunderhus force-pushed the react-tree/feat--useFlatTreeItems branch from ead0739 to 4893db4 Compare February 27, 2023 17:09
@bsunderhus bsunderhus force-pushed the react-tree/feat--useFlatTreeItems branch from 4893db4 to 7098af7 Compare February 27, 2023 17:35
@bsunderhus bsunderhus merged commit a55428d into microsoft:master Feb 27, 2023
@bsunderhus bsunderhus deleted the react-tree/feat--useFlatTreeItems branch February 27, 2023 18:12
@bsunderhus bsunderhus mentioned this pull request Mar 13, 2023
22 tasks
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.

3 participants