-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1139] Implement TreePropertySection on the frontend
Bug: #1139 Signed-off-by: Pierre-Charles David <[email protected]>
- Loading branch information
Showing
9 changed files
with
238 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
frontend/src/properties/propertysections/TreePropertySection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { makeStyles } from '@material-ui/core'; | ||
import { ClassNameMap } from '@material-ui/core/styles/withStyles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; | ||
import { TreeItem } from '@material-ui/lab'; | ||
import TreeView from '@material-ui/lab/TreeView'; | ||
import { httpOrigin } from 'common/URL'; | ||
import { TreeNode } from 'form/Form.types'; | ||
import React from 'react'; | ||
import { SelectionEntry } from 'workbench/Workbench.types'; | ||
import { TreePropertySectionProps } from './TreePropertySection.types'; | ||
|
||
const useTreeWidgetStyles = makeStyles((theme) => ({ | ||
nodeLabel: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
columnGap: theme.spacing(1), | ||
}, | ||
})); | ||
|
||
const renderTree = (styles: ClassNameMap, nodes: TreeNode[], onClick): JSX.Element => { | ||
const renderTreeItem = (node: TreeNode): JSX.Element => { | ||
const children = nodes.filter((g) => g.parentId === node.id); | ||
|
||
const label = ( | ||
<div className={styles.nodeLabel} onClick={() => onClick(node)}> | ||
<img height="16" width="16" title={node.label} alt={node.label} src={httpOrigin + node.imageURL}></img> | ||
<Typography>{node.label}</Typography> | ||
</div> | ||
); | ||
|
||
return ( | ||
<TreeItem key={node.id} nodeId={node.id} label={label}> | ||
{children.map(renderTreeItem)} | ||
</TreeItem> | ||
); | ||
}; | ||
|
||
return <>{...nodes.filter((f) => f.parentId == null).map(renderTreeItem)}</>; | ||
}; | ||
|
||
export const TreePropertySection = ({ widget, setSelection }: TreePropertySectionProps) => { | ||
const styles: ClassNameMap = useTreeWidgetStyles(); | ||
const updateSelection = (node: TreeNode) => { | ||
if (node.selectable) { | ||
const newSelection: SelectionEntry = { | ||
id: node.id, | ||
label: node.label, | ||
kind: node.kind, | ||
}; | ||
setSelection({ entries: [newSelection] }); | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<Typography>{widget.label}</Typography> | ||
<TreeView | ||
defaultCollapseIcon={<ExpandMoreIcon />} | ||
defaultExpanded={widget.expandedNodesIds} | ||
defaultExpandIcon={<ChevronRightIcon />} | ||
> | ||
{renderTree(styles, widget.nodes, updateSelection)} | ||
</TreeView> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.