Kaynağa Gözat

fix: persist hidden nodes on rotate

Shivam 2 yıl önce
ebeveyn
işleme
74671012cb

+ 3 - 1
src/components/Graph/index.tsx

@@ -47,6 +47,7 @@ const GraphComponent = ({
 }: LayoutProps) => {
 }: LayoutProps) => {
   const [minScale, setMinScale] = React.useState(0.4);
   const [minScale, setMinScale] = React.useState(0.4);
   const setGraphValue = useGraph(state => state.setGraphValue);
   const setGraphValue = useGraph(state => state.setGraphValue);
+  const setLoading = useGraph(state => state.setLoading);
   const setConfig = useConfig(state => state.setConfig);
   const setConfig = useConfig(state => state.setConfig);
   const centerView = useConfig(state => state.centerView);
   const centerView = useConfig(state => state.centerView);
   const loading = useGraph(state => state.loading);
   const loading = useGraph(state => state.loading);
@@ -85,12 +86,13 @@ const GraphComponent = ({
         const MIN_SCALE = Math.round((450_000 / areaSize) * 100) / 100;
         const MIN_SCALE = Math.round((450_000 / areaSize) * 100) / 100;
         const scale = MIN_SCALE > 2 ? 1 : MIN_SCALE <= 0 ? 0.1 : MIN_SCALE;
         const scale = MIN_SCALE > 2 ? 1 : MIN_SCALE <= 0 ? 0.1 : MIN_SCALE;
 
 
+        setLoading(true);
         setMinScale(scale);
         setMinScale(scale);
         setSize({ width: layout.width + 400, height: layout.height + 400 });
         setSize({ width: layout.width + 400, height: layout.height + 400 });
 
 
         requestAnimationFrame(() => {
         requestAnimationFrame(() => {
           setTimeout(() => {
           setTimeout(() => {
-            setGraphValue("loading", false);
+            setLoading(false);
             setTimeout(() => changeRatio > 100 && centerView(), 0);
             setTimeout(() => changeRatio > 100 && centerView(), 0);
           }, 0);
           }, 0);
         });
         });

+ 2 - 1
src/containers/Editor/LiveEditor/GraphCanvas.tsx

@@ -11,6 +11,7 @@ export const GraphCanvas = ({ isWidget = false }: { isWidget?: boolean }) => {
 
 
   const collapsedNodes = useGraph(state => state.collapsedNodes);
   const collapsedNodes = useGraph(state => state.collapsedNodes);
   const collapsedEdges = useGraph(state => state.collapsedEdges);
   const collapsedEdges = useGraph(state => state.collapsedEdges);
+  const loading = useGraph(state => state.loading);
 
 
   React.useEffect(() => {
   React.useEffect(() => {
     const nodeList = collapsedNodes.map(id => `[id$="node-${id}"]`);
     const nodeList = collapsedNodes.map(id => `[id$="node-${id}"]`);
@@ -26,7 +27,7 @@ export const GraphCanvas = ({ isWidget = false }: { isWidget?: boolean }) => {
       selectedNodes.forEach(node => node.classList.add("hide"));
       selectedNodes.forEach(node => node.classList.add("hide"));
       selectedEdges.forEach(edge => edge.classList.add("hide"));
       selectedEdges.forEach(edge => edge.classList.add("hide"));
     }
     }
-  }, [collapsedNodes, collapsedEdges]);
+  }, [collapsedNodes, collapsedEdges, loading]);
 
 
   return (
   return (
     <>
     <>

+ 2 - 0
src/hooks/store/useGraph.tsx

@@ -17,6 +17,7 @@ export type Graph = typeof initialStates;
 
 
 interface GraphActions {
 interface GraphActions {
   setGraphValue: (key: keyof Graph, value: any) => void;
   setGraphValue: (key: keyof Graph, value: any) => void;
+  setLoading: (loading: boolean) => void;
   expandNodes: (nodeId: string) => void;
   expandNodes: (nodeId: string) => void;
   collapseNodes: (nodeId: string) => void;
   collapseNodes: (nodeId: string) => void;
   collapseGraph: () => void;
   collapseGraph: () => void;
@@ -32,6 +33,7 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({
       collapsedEdges: [],
       collapsedEdges: [],
       [key]: value,
       [key]: value,
     }),
     }),
+  setLoading: loading => set({ loading }),
   expandNodes: nodeId => {
   expandNodes: nodeId => {
     const [childrenNodes, matchingNodes] = getOutgoers(
     const [childrenNodes, matchingNodes] = getOutgoers(
       nodeId,
       nodeId,