Skip to content

Commit

Permalink
[3849] Trees in forms can display the same element many times
Browse files Browse the repository at this point in the history
Bug: #3849
Signed-off-by: Guillaume Coutable <[email protected]>
  • Loading branch information
gcoutable committed Aug 26, 2024
1 parent 5f845ea commit b6395ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ As a result, the following maven modules have been deleted: `sirius-web-sample-a
- https://github.com/eclipse-sirius/sirius-web/issues/3776[#3776] [trees] Restore expand all functionality for ref widget trees
- https://github.com/eclipse-sirius/sirius-web/issues/3824[#3824] [core] Fix representation migration participant execution which was failing when there were many representation migration participant to apply.
- https://github.com/eclipse-sirius/sirius-web/issues/3851[#3851] [trees] Fix an issue where the tree filters menu items were not displayed anymore after a click on the filters menu.
- https://github.com/eclipse-sirius/sirius-web/issues/3849[#3849] [form] Fix the tree representation in form support the display of the same referenced element many times in the tree.

=== New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ const isErrorPayload = (payload: GQLEditTreeCheckboxPayload): payload is GQLErro
const isSuccessPayload = (payload: GQLEditTreeCheckboxPayload): payload is GQLSuccessPayload =>
payload.__typename === 'SuccessPayload';

const getTreeItemId = (parentId: string | null, nodeId: string): string => {
if (parentId) {
return `${parentId}/${nodeId}`;
}
return nodeId;
};

export const editTreeCheckboxMutation = gql`
mutation editTreeCheckbox($input: EditTreeCheckboxInput!) {
editTreeCheckbox(input: $input) {
Expand All @@ -101,7 +108,7 @@ export const editTreeCheckboxMutation = gql`
}
`;

const TreeItem = ({ node, nodes, readOnly, editingContextId, formId, widgetId }: TreeItemProps) => {
const TreeItem = ({ parentId, node, nodes, readOnly, editingContextId, formId, widgetId }: TreeItemProps) => {
const { classes } = useTreeItemWidgetStyles();
const { setSelection } = useSelection();

Expand Down Expand Up @@ -142,14 +149,18 @@ const TreeItem = ({ node, nodes, readOnly, editingContextId, formId, widgetId }:

const handleClick: React.MouseEventHandler<HTMLDivElement> = () => {
if (node.selectable) {
const treePath = node.id.split('/');
const nodeId = treePath[treePath.length - 1];
const newSelection: SelectionEntry = {
id: node.id,
id: nodeId,
kind: node.kind,
};
setSelection({ entries: [newSelection] });
}
};

const treeItemId = getTreeItemId(parentId, node.id);

const label = (
<div className={classes.label} onClick={handleClick}>
{node.checkable ? (
Expand Down Expand Up @@ -177,9 +188,10 @@ const TreeItem = ({ node, nodes, readOnly, editingContextId, formId, widgetId }:

const childNodes = nodes.filter((childNode) => childNode.parentId === node.id);
return (
<MuiTreeItem itemId={node.id} label={label} classes={{ content: classes.content }}>
<MuiTreeItem itemId={treeItemId} label={label} classes={{ content: classes.content }}>
{childNodes.map((childNode) => (
<TreeItem
parentId={treeItemId}
node={childNode}
nodes={nodes}
key={childNode.id}
Expand Down Expand Up @@ -228,6 +240,7 @@ export const TreePropertySection: PropertySectionComponent<GQLTree> = ({
defaultExpandedItems={expandedNodesIds}>
{rootNodes.map((rootNode) => (
<TreeItem
parentId={null}
node={rootNode}
nodes={nodes}
key={rootNode.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GQLMessage } from '@eclipse-sirius/sirius-components-core';
import { GQLTreeNode } from '../form/FormEventFragments.types';

export interface TreeItemProps {
parentId: string | null;
node: GQLTreeNode;
nodes: GQLTreeNode[];
readOnly: boolean;
Expand Down

0 comments on commit b6395ec

Please sign in to comment.