From b59d3ef1472b88cf19d131fc40ee6e18703711b1 Mon Sep 17 00:00:00 2001 From: Lanny W Date: Sat, 23 Nov 2024 21:24:23 -0600 Subject: [PATCH 1/2] intialize from no sample selected state to optimize performance --- .../SchemaIO/components/TreeSelectionView.tsx | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx b/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx index 74a187d764..68d8730566 100644 --- a/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx +++ b/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx @@ -39,12 +39,7 @@ export default function TreeSelectionView(props: ViewPropsType) { const { view = {} } = schema; if (data == undefined) { - const sampleIds = view?.data.flatMap(([parentId, children]) => { - return children.map((childId) => - typeof childId === "string" ? childId : childId[0] - ); - }); - onChange(path, sampleIds); + onChange(path, []); } const structure = view?.data || []; @@ -78,7 +73,7 @@ export default function TreeSelectionView(props: ViewPropsType) { const initialCollapsedState: CollapsedState = React.useMemo(() => { const state: CollapsedState = {}; structure.forEach(([parentId]) => { - state[parentId] = false; // start as expanded + state[parentId] = true; // start as expanded }); return state; }, [structure]); @@ -87,7 +82,7 @@ export default function TreeSelectionView(props: ViewPropsType) { initialCollapsedState ); - const [allCollapsed, setAllCollapsed] = React.useState(false); + const [allCollapsed, setAllCollapsed] = React.useState(true); const handleExpandCollapseAll = () => { setCollapsedState((prevState) => { @@ -209,17 +204,6 @@ export default function TreeSelectionView(props: ViewPropsType) { return idx === -1 ? 0 : idx + 1; }; - // On init, all samples are selected by default - useEffect(() => { - const sampleIds = view?.data.flatMap(([parentId, children]) => { - return children.map((childId) => - typeof childId === "string" ? childId : childId[0] - ); - }); - onChange(path, sampleIds); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - // this only runs when data and checkboxstate are different // meaning the user selected samples from the grid // we will handle the state change of checkedState here From 14bcfcda77ba8abb606379e7ca5c44c07f5dcf67 Mon Sep 17 00:00:00 2001 From: Lanny W Date: Sun, 24 Nov 2024 13:57:33 -0600 Subject: [PATCH 2/2] cleanup --- .../src/plugins/SchemaIO/components/TreeSelectionView.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx b/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx index 68d8730566..e8c20164a1 100644 --- a/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx +++ b/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx @@ -73,7 +73,7 @@ export default function TreeSelectionView(props: ViewPropsType) { const initialCollapsedState: CollapsedState = React.useMemo(() => { const state: CollapsedState = {}; structure.forEach(([parentId]) => { - state[parentId] = true; // start as expanded + state[parentId] = true; // start as folded }); return state; }, [structure]); @@ -92,7 +92,7 @@ export default function TreeSelectionView(props: ViewPropsType) { }); return newState; }); - setAllCollapsed(!allCollapsed); // Toggle the expand/collapse state + setAllCollapsed(!allCollapsed); }; const handleCheckboxChange = (id: string, isChecked: boolean) => { @@ -178,7 +178,7 @@ export default function TreeSelectionView(props: ViewPropsType) { const isSample = !structure.some(([parentId]) => parentId === key) && key !== "selectAll"; - return isSample && updatedState[key].checked; // Only checked samples + return isSample && updatedState[key].checked; }); // We update the actual output value (ctx.params.value \ data) here. @@ -188,7 +188,6 @@ export default function TreeSelectionView(props: ViewPropsType) { }); }; - // Function to handle expand/collapse toggle const handleToggleCollapse = (id: string) => { setCollapsedState((prevState) => ({ ...prevState,