Skip to content

Commit

Permalink
intialize from no sample selected state to optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lanzhenw committed Nov 24, 2024
1 parent b26d1d9 commit b59d3ef
Showing 1 changed file with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
Expand Down Expand Up @@ -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]);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b59d3ef

Please sign in to comment.