mirror of
				https://github.com/chartdb/chartdb.git
				synced 2025-11-04 05:53:15 +00:00 
			
		
		
		
	fix: preserve group expanded state when toggling table visibility in canvas filter
This commit is contained in:
		@@ -301,14 +301,24 @@ export const CanvasFilter: React.FC<CanvasFilterProps> = ({ onClose }) => {
 | 
				
			|||||||
        t,
 | 
					        t,
 | 
				
			||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Initialize expanded state with all schemas expanded
 | 
					    // Initialize expanded state with all schemas expanded only when grouping changes
 | 
				
			||||||
    useMemo(() => {
 | 
					    useEffect(() => {
 | 
				
			||||||
        const initialExpanded: Record<string, boolean> = {};
 | 
					        setExpanded((prevExpanded) => {
 | 
				
			||||||
        treeData.forEach((node) => {
 | 
					            const newExpanded: Record<string, boolean> = {};
 | 
				
			||||||
            initialExpanded[node.id] = true;
 | 
					
 | 
				
			||||||
 | 
					            // Preserve existing expanded states for nodes that still exist
 | 
				
			||||||
 | 
					            treeData.forEach((node) => {
 | 
				
			||||||
 | 
					                if (node.id in prevExpanded) {
 | 
				
			||||||
 | 
					                    newExpanded[node.id] = prevExpanded[node.id];
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // Default new nodes to expanded
 | 
				
			||||||
 | 
					                    newExpanded[node.id] = true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return newExpanded;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        setExpanded(initialExpanded);
 | 
					    }, [groupBy, treeData]);
 | 
				
			||||||
    }, [treeData]);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Filter tree data based on search query
 | 
					    // Filter tree data based on search query
 | 
				
			||||||
    const filteredTreeData: TreeNode<NodeType, NodeContext>[] = useMemo(() => {
 | 
					    const filteredTreeData: TreeNode<NodeType, NodeContext>[] = useMemo(() => {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user