Skip to content

Commit aa9d0dc

Browse files
authored
[Engage-118] Fix Tree View with new location in mui 6 (bcgov#148)
1 parent 987a586 commit aa9d0dc

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

met-web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@mui/lab": "^5.0.0-alpha.91",
1515
"@mui/material": "^5.6.1",
1616
"@mui/x-date-pickers": "^5.0.5",
17+
"@mui/x-tree-view": "^8.22.0",
1718
"@reduxjs/toolkit": "^1.8.1",
1819
"@testing-library/react": "^16.3.0",
1920
"@testing-library/user-event": "^13.5.0",

met-web/src/components/admin/engagement/form/EngagementWidgets/Documents/StyledTreeItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { styled } from '@mui/material/styles';
3-
import TreeItem, { TreeItemProps } from '@mui/lab/TreeItem';
3+
import { TreeItem, TreeItemProps } from '@mui/x-tree-view/TreeItem';
44
import { MetBody } from 'components/shared/common';
55
import { If, Then, Else } from 'react-if';
66
import { Link, Box } from '@mui/material';
@@ -10,7 +10,7 @@ import { SvgIconProps } from '@mui/material';
1010
type DocumentTreeItemProps = TreeItemProps & {
1111
labelIcon: React.ElementType<SvgIconProps>;
1212
labelUrl?: string;
13-
nodeId: string;
13+
itemId: string;
1414
};
1515

1616
type StyledTreeItemProps = TreeItemProps & {
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as React from 'react';
2-
import TreeView from '@mui/lab/TreeView';
2+
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
33
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
44
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
55
import { If, Then, Else } from 'react-if';
66
import { DocumentItem, DOCUMENT_TYPE } from 'models/document';
77
import { StyledTreeItem } from './StyledTreeItem';
8-
import { TreeItemProps } from '@mui/lab/TreeItem';
8+
import { TreeItemProps } from '@mui/x-tree-view/TreeItem';
99
import FolderOutlinedIcon from '@mui/icons-material/FolderOutlined';
1010
import DescriptionOutlinedIcon from '@mui/icons-material/DescriptionOutlined';
1111

@@ -15,26 +15,29 @@ type DocumentTreeProps = TreeItemProps & {
1515

1616
export default function DocumentTree({ documentItem }: DocumentTreeProps) {
1717
return (
18-
<TreeView
18+
<SimpleTreeView
1919
aria-label="documentTree"
20-
defaultExpanded={['3']}
21-
defaultCollapseIcon={<ArrowDropDownIcon sx={{ height: '35px', width: '35px' }} />}
22-
defaultExpandIcon={<ArrowRightIcon sx={{ height: '35px', width: '35px' }} />}
23-
defaultEndIcon={<div style={{ width: 24 }} />}
20+
defaultExpandedItems={['3']}
21+
slots={{
22+
collapseIcon: () => <ArrowDropDownIcon sx={{ height: '35px', width: '35px' }} />,
23+
expandIcon: () => <ArrowRightIcon sx={{ height: '35px', width: '35px' }} />,
24+
endIcon: () => <div style={{ width: 24 }} />,
25+
}}
2426
sx={{ flexGrow: 1, maxWidth: 1000, overflowY: 'auto' }}
2527
>
2628
<If condition={documentItem.type === 'folder'}>
2729
<Then>
2830
<StyledTreeItem
2931
labelUrl={documentItem.url}
30-
nodeId={`${documentItem.id}`}
32+
itemId={`${documentItem.id}`}
3133
labelText={documentItem.title}
3234
labelIcon={FolderOutlinedIcon}
3335
>
3436
{documentItem.children?.map((document: DocumentItem) => {
3537
return (
3638
<StyledTreeItem
37-
nodeId={`${document.id}`}
39+
key={document.id}
40+
itemId={`${document.id}`}
3841
innerDocument
3942
labelText={document.title}
4043
labelIcon={
@@ -50,13 +53,13 @@ export default function DocumentTree({ documentItem }: DocumentTreeProps) {
5053
</Then>
5154
<Else>
5255
<StyledTreeItem
53-
nodeId={`${documentItem.id}`}
56+
itemId={`${documentItem.id}`}
5457
labelText={documentItem.title}
5558
labelIcon={DescriptionOutlinedIcon}
5659
labelUrl={documentItem.url}
5760
/>
5861
</Else>
5962
</If>
60-
</TreeView>
63+
</SimpleTreeView>
6164
);
6265
}

met-web/src/components/public/engagement/view/widgets/DocumentWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const DocumentWidget = ({ widget }: DocumentWidgetProps) => {
5656
{documents.map((document: DocumentItem) => {
5757
return (
5858
<Grid key={document.id} container item spacing={1} rowSpacing={1} xs={12} paddingTop={2}>
59-
<DocumentTree nodeId={`${document.id}`} documentItem={document} />
59+
<DocumentTree itemId={`${document.id}`} documentItem={document} />
6060
</Grid>
6161
);
6262
})}

0 commit comments

Comments
 (0)