11import type { ViewPort } from "react-zoomable-ui/dist/ViewPort" ;
22import type { CanvasDirection } from "reaflow/dist/layout/elkLayout" ;
33import { create } from "zustand" ;
4+ import { SUPPORTED_LIMIT } from "../../../../../constants/graph" ;
45import useJson from "../../../../../store/useJson" ;
56import type { EdgeData , NodeData } from "../../../../../types/graph" ;
67import { parser } from "../lib/jsonParser" ;
@@ -21,6 +22,7 @@ export interface Graph {
2122 collapsedParents : string [ ] ;
2223 selectedNode : NodeData | null ;
2324 path : string ;
25+ aboveSupportedLimit : boolean ;
2426}
2527
2628const initialStates : Graph = {
@@ -37,6 +39,7 @@ const initialStates: Graph = {
3739 collapsedParents : [ ] ,
3840 selectedNode : null ,
3941 path : "" ,
42+ aboveSupportedLimit : false ,
4043} ;
4144
4245interface GraphActions {
@@ -75,16 +78,32 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({
7578 const { nodes, edges } = parser ( data ?? useJson . getState ( ) . json ) ;
7679
7780 if ( get ( ) . collapseAll ) {
78- set ( { nodes, edges, ...options } ) ;
81+ if ( nodes . length > SUPPORTED_LIMIT ) {
82+ return set ( { aboveSupportedLimit : true , ...options , loading : false } ) ;
83+ }
84+
85+ set ( { nodes, edges, aboveSupportedLimit : false , ...options } ) ;
7986 get ( ) . collapseGraph ( ) ;
8087 } else {
88+ if ( nodes . length > SUPPORTED_LIMIT ) {
89+ return set ( {
90+ aboveSupportedLimit : true ,
91+ collapsedParents : [ ] ,
92+ collapsedNodes : [ ] ,
93+ collapsedEdges : [ ] ,
94+ ...options ,
95+ loading : false ,
96+ } ) ;
97+ }
98+
8199 set ( {
82100 nodes,
83101 edges,
84102 collapsedParents : [ ] ,
85103 collapsedNodes : [ ] ,
86104 collapsedEdges : [ ] ,
87105 graphCollapsed : false ,
106+ aboveSupportedLimit : false ,
88107 ...options ,
89108 } ) ;
90109 }
0 commit comments