From 3e6204e917d5dadf99cf2803cffc8b9bcec96078 Mon Sep 17 00:00:00 2001 From: Eric NGUYEN Date: Fri, 23 Sep 2022 09:34:46 +0200 Subject: [PATCH] Implement HideChildrenInTreeview --- src/Components/ElementsSidebar/ElementsSidebar.tsx | 2 +- src/Interfaces/IAvailableContainer.ts | 3 +++ src/Interfaces/IContainerProperties.ts | 3 +++ src/utils/default.ts | 2 ++ src/utils/itertools.ts | 6 +++++- test-server/node-http.js | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Components/ElementsSidebar/ElementsSidebar.tsx b/src/Components/ElementsSidebar/ElementsSidebar.tsx index cf8d45b..38532d9 100644 --- a/src/Components/ElementsSidebar/ElementsSidebar.tsx +++ b/src/Components/ElementsSidebar/ElementsSidebar.tsx @@ -124,7 +124,7 @@ export function ElementsSidebar(props: IElementsSidebarProps): JSX.Element { isOpenClasses = props.isHistoryOpen ? 'right-64' : 'right-0'; } - const it = MakeIterator(props.mainContainer); + const it = MakeIterator(props.mainContainer, true); const containers = [...it]; function Row({ index, style diff --git a/src/Interfaces/IAvailableContainer.ts b/src/Interfaces/IAvailableContainer.ts index 8847f97..89a9127 100644 --- a/src/Interfaces/IAvailableContainer.ts +++ b/src/Interfaces/IAvailableContainer.ts @@ -96,6 +96,9 @@ export interface IAvailableContainer { */ Pattern?: string + /** Hide the children in the treeview */ + HideChildrenInTreeview?: boolean + /** if true, show the dimension of the container */ ShowSelfDimensions?: boolean diff --git a/src/Interfaces/IContainerProperties.ts b/src/Interfaces/IContainerProperties.ts index 6e5c668..a9da2ea 100644 --- a/src/Interfaces/IContainerProperties.ts +++ b/src/Interfaces/IContainerProperties.ts @@ -57,6 +57,9 @@ export interface IContainerProperties { /** Horizontal alignment, also determines the visual location of x {Left = 0, Center, Right } */ xPositionReference: XPositionReference + /** Hide the children in the treeview */ + hideChildrenInTreeview: boolean + /** if true, show the dimension of the container */ showSelfDimensions: boolean diff --git a/src/utils/default.ts b/src/utils/default.ts index 45047bf..bf86825 100644 --- a/src/utils/default.ts +++ b/src/utils/default.ts @@ -128,6 +128,7 @@ export const DEFAULT_MAINCONTAINER_PROPS: IContainerProperties = { isAnchor: false, isFlex: false, xPositionReference: XPositionReference.Left, + hideChildrenInTreeview: false, showChildrenDimensions: true, // TODO: put the dimension at the top (see pdf) showSelfDimensions: true, // TODO: put the dimension at the bottom (see pdf) isDimensionBorrower: true, // second dimensions from the bottom @@ -173,6 +174,7 @@ export function GetDefaultContainerProps(type: string, xPositionReference: containerConfig.XPositionReference ?? XPositionReference.Left, minWidth: containerConfig.MinWidth ?? 1, maxWidth: containerConfig.MaxWidth ?? Number.MAX_SAFE_INTEGER, + hideChildrenInTreeview: containerConfig.HideChildrenInTreeview ?? false, showChildrenDimensions: containerConfig.ShowChildrenDimensions ?? false, showSelfDimensions: containerConfig.ShowSelfDimensions ?? false, markPositionToDimensionBorrower: containerConfig.MarkPositionToDimensionBorrower ?? false, diff --git a/src/utils/itertools.ts b/src/utils/itertools.ts index b664ca7..90aa9ba 100644 --- a/src/utils/itertools.ts +++ b/src/utils/itertools.ts @@ -3,7 +3,7 @@ import { IContainerModel } from '../Interfaces/IContainerModel'; /** * Returns a Generator iterating of over the children depth-first */ -export function * MakeIterator(root: IContainerModel): Generator { +export function * MakeIterator(root: IContainerModel, enableHideChildrenInTreeview = false): Generator { const queue: IContainerModel[] = [root]; const visited = new Set(queue); while (queue.length > 0) { @@ -11,6 +11,10 @@ export function * MakeIterator(root: IContainerModel): Generator= 0; i--) { const child = container.children[i]; if (visited.has(child)) { diff --git a/test-server/node-http.js b/test-server/node-http.js index 84d8e89..7f0cc34 100644 --- a/test-server/node-http.js +++ b/test-server/node-http.js @@ -81,6 +81,7 @@ const GetSVGLayoutConfiguration = () => { stroke: 'red', fill: '#d3c9b7', }, + HideChildrenInTreeview: true, ShowSelfDimensions: true, IsDimensionBorrower: true, Category: "Stuff"