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

[POC] Minimal migration to MUI TreeView v7 #632

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 119 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"peerDependencies": {
"@mui/system": "^5.15.15",
"@mui/x-tree-view": "^6.17.0",
"@mui/x-tree-view": "^7.22.0",
"papaparse": "^5.4.1",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
Expand Down
34 changes: 9 additions & 25 deletions src/components/treeViewFinder/TreeViewFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ import {
ModalProps,
} from '@mui/material';

import { TreeItem, TreeView, TreeViewClasses } from '@mui/x-tree-view';
import {
Check as CheckIcon,
ChevronRight as ChevronRightIcon,
ExpandMore as ExpandMoreIcon,
} from '@mui/icons-material';
import { TreeItem, SimpleTreeView, SimpleTreeViewClasses } from '@mui/x-tree-view';
import { Check as CheckIcon } from '@mui/icons-material';
import { makeComposeClasses, toNestedGlobalSelectors } from '../../utils/styles';
import { CancelButton } from '../inputs/reactHookForm/utils/CancelButton';

Expand Down Expand Up @@ -85,7 +81,7 @@ export interface TreeViewFinderProps {
selected?: string[];
expanded?: string[];
multiSelect?: boolean;
classes?: Partial<TreeViewClasses>;
classes?: Partial<SimpleTreeViewClasses>;
className?: string;

// dialog props
Expand Down Expand Up @@ -324,10 +320,6 @@ function TreeViewFinderComponant(props: TreeViewFinderProps) {
</div>
);
};
const showChevron = (node: TreeViewFinderNodeProps) => {
// by defaut show Chevron if childrenCount is null or undefined otherwise only if > 0
return !!(node.childrenCount == null || (node.childrenCount && node.childrenCount > 0));
};

const renderTree = (node: TreeViewFinderNodeProps) => {
if (!node) {
Expand All @@ -346,14 +338,8 @@ function TreeViewFinderComponant(props: TreeViewFinderProps) {
return (
<TreeItem
key={node.id}
nodeId={node.id}
itemId={node.id}
label={renderTreeItemLabel(node)}
expandIcon={
showChevron(node) ? <ChevronRightIcon className={composeClasses(classes, cssIcon)} /> : null
}
collapseIcon={
showChevron(node) ? <ExpandMoreIcon className={composeClasses(classes, cssIcon)} /> : null
}
ref={(element) => {
if (selectedProp?.includes(node.id)) {
scrollRef.current.push(element);
Expand Down Expand Up @@ -404,17 +390,15 @@ function TreeViewFinderComponant(props: TreeViewFinderProps) {
{contentText ?? intl.formatMessage({ id: 'treeview_finder/contentText' }, { multiSelect })}
</DialogContentText>

<TreeView
// Controlled props
expanded={expanded}
// events
onNodeToggle={handleNodeToggle}
onNodeSelect={handleNodeSelect}
<SimpleTreeView
expandedItems={expanded}
onExpandedItemsChange={handleNodeToggle}
onItemSelectionToggle={handleNodeSelect}
// Uncontrolled props
{...getTreeViewSelectionProps()}
>
{data && Array.isArray(data) ? data.sort(sortMethod).map((child) => renderTree(child)) : null}
</TreeView>
</SimpleTreeView>
</DialogContent>
<DialogActions>
<CancelButton
Expand Down
Loading