Skip to content

Commit 8aa515e

Browse files
committed
feat: early return for unsupported data limit
1 parent 6941d58 commit 8aa515e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/constants/graph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export const NODE_DIMENSIONS = {
22
ROW_HEIGHT: 24, // Regular row height
33
PARENT_HEIGHT: 36, // Height for parent nodes
44
} as const;
5+
6+
export const SUPPORTED_LIMIT = +(process.env.NEXT_PUBLIC_NODE_LIMIT as string);

src/features/editor/views/GraphView/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,10 @@ const GraphCanvas = ({ isWidget }: GraphProps) => {
136136
);
137137
};
138138

139-
const SUPPORTED_LIMIT = +(process.env.NEXT_PUBLIC_NODE_LIMIT as string);
140-
141139
export const GraphView = ({ isWidget = false }: GraphProps) => {
142140
const setViewPort = useGraph(state => state.setViewPort);
143141
const viewPort = useGraph(state => state.viewPort);
144-
const aboveSupportedLimit = useGraph(state => state.nodes.length > SUPPORTED_LIMIT);
142+
const aboveSupportedLimit = useGraph(state => state.aboveSupportedLimit);
145143
const loading = useGraph(state => state.loading);
146144
const gesturesEnabled = useConfig(state => state.gesturesEnabled);
147145
const rulersEnabled = useConfig(state => state.rulersEnabled);

src/features/editor/views/GraphView/stores/useGraph.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ViewPort } from "react-zoomable-ui/dist/ViewPort";
22
import type { CanvasDirection } from "reaflow/dist/layout/elkLayout";
33
import { create } from "zustand";
4+
import { SUPPORTED_LIMIT } from "../../../../../constants/graph";
45
import useJson from "../../../../../store/useJson";
56
import type { EdgeData, NodeData } from "../../../../../types/graph";
67
import { 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

2628
const initialStates: Graph = {
@@ -37,6 +39,7 @@ const initialStates: Graph = {
3739
collapsedParents: [],
3840
selectedNode: null,
3941
path: "",
42+
aboveSupportedLimit: false,
4043
};
4144

4245
interface 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

Comments
 (0)