Skip to content

Commit

Permalink
limit schema size
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaLysiuk committed Jan 3, 2024
1 parent 183c4ed commit b564cd9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/editor/src/Relation/PanZoom/PanZoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import {
} from "@/Relation/PanZoom/LinesDiagram/LinesDiagram";
import { nodeFilter } from "@/Relation/shared/nodeFilter";
import { useClickDetector } from "@/shared/hooks/useClickDetector";

const MAX_SCHEMA_SIZE = 40000;

export const PanZoom: React.FC<{
nodes: ParserField[];
hide?: boolean;
Expand Down Expand Up @@ -74,7 +77,15 @@ export const PanZoom: React.FC<{
}, [nodes, baseTypesOn, inputsOn, libraryNodesOn]);

const downloadPng = useCallback(() => {
if (viewportParams?.height) {
if (viewportParams?.height && viewportParams?.width) {
if (viewportParams.height * viewportParams.width > MAX_SCHEMA_SIZE) {
createToast({
message:
"Schema is too big to be printed as a whole. Please focus some nodes or hide part of them before printing.",
variant: "error",
});
return;
}
setLoading(true);
const ctx = getContext();
setParamsBeforeExport({
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/shared/dialogs/ImportSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ImportSchema: React.FC<{
try {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
createToast({
message: `Please add https:// or http:// at the beggining of your URL we don't want to guess it.`,
message: `Please add https:// or http:// at the beginning of your URL we don't want to guess it.`,
variant: "error",
});
return false;
Expand Down Expand Up @@ -149,7 +149,7 @@ export const ImportSchema: React.FC<{
variant: "error",
})
: createToast({
message: "Unkown import error",
message: "Unknown import error",
variant: "error",
});
});
Expand Down Expand Up @@ -184,7 +184,7 @@ export const ImportSchema: React.FC<{
variant: "error",
})
: createToast({
message: "Unkown import error",
message: "Unknown import error",
variant: "error",
});
});
Expand Down

0 comments on commit b564cd9

Please sign in to comment.