diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index cd1a75bcd65..56b12b205cc 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/TreePropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/TreePropertySection.tsx index e504643bf46..b5c35423d08 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/TreePropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/TreePropertySection.tsx @@ -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) { @@ -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(); @@ -142,14 +149,18 @@ const TreeItem = ({ node, nodes, readOnly, editingContextId, formId, widgetId }: const handleClick: React.MouseEventHandler = () => { 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 = (
{node.checkable ? ( @@ -177,9 +188,10 @@ const TreeItem = ({ node, nodes, readOnly, editingContextId, formId, widgetId }: const childNodes = nodes.filter((childNode) => childNode.parentId === node.id); return ( - + {childNodes.map((childNode) => ( = ({ defaultExpandedItems={expandedNodesIds}> {rootNodes.map((rootNode) => (