From c9f6c40356013db10854daa1a08b57a6df0e710f Mon Sep 17 00:00:00 2001
From: postrowinski
Date: Thu, 13 Apr 2023 14:27:55 +0200
Subject: [PATCH] add warning info about too many relations
---
mwdb/web/src/components/RelationsPlot.jsx | 84 ++++++++++++++++++++---
1 file changed, 75 insertions(+), 9 deletions(-)
diff --git a/mwdb/web/src/components/RelationsPlot.jsx b/mwdb/web/src/components/RelationsPlot.jsx
index 8e6e0511c..16049b41a 100644
--- a/mwdb/web/src/components/RelationsPlot.jsx
+++ b/mwdb/web/src/components/RelationsPlot.jsx
@@ -1,4 +1,11 @@
-import React, { Suspense, useState, useLayoutEffect, useContext } from "react";
+import React, {
+ Suspense,
+ useState,
+ useLayoutEffect,
+ useContext,
+ useEffect,
+} from "react";
+import { isEmpty } from "lodash";
import { useSearchParams } from "react-router-dom";
import { APIContext } from "@mwdb-web/commons/api";
@@ -8,6 +15,12 @@ import { Tag } from "@mwdb-web/commons/ui";
const DagreD3Plot = React.lazy(() => import("./DagreD3Plot"));
+const nodeStatuses = {
+ initial: "initial",
+ showGraph: "showGraph",
+ showWarning: "showWarning",
+};
+
function RelationsNode(props) {
const typeMapping = {
file: "file",
@@ -66,6 +79,31 @@ function RelationsNode(props) {
);
}
+function RelationToManyNode({ setNodesStatus, nodesLength }) {
+ console.log({ setNodesStatus, nodesLength });
+ return (
+ <>
+
+ The relationships for a given object will amount to{" "}
+ {nodesLength} {" "}
+ elements, displaying such a quantity of connections may affect
+ the application's performance.
+
+
+ setNodesStatus(nodeStatuses.showGraph)}
+ >
+ Show relations anyway
+
+
+ >
+ );
+}
+
function RelationsPlot(props) {
const api = useContext(APIContext);
const [searchParams, setSearchParams] = useSearchParams();
@@ -75,6 +113,8 @@ function RelationsPlot(props) {
width: "100%",
};
+ const [nodesStatus, setNodesStatus] = useState("initial");
+
const [nodes, setNodes] = useState({
nodes: [],
edges: [],
@@ -187,16 +227,42 @@ function RelationsPlot(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ useEffect(() => {
+ const limit = 500;
+ if (!isEmpty(nodes.nodes) || !isEmpty(nodes.edges)) {
+ const elementsLength = Math.max(
+ nodes.nodes.length,
+ nodes.edges.length
+ );
+ setNodesStatus(
+ elementsLength < limit
+ ? nodeStatuses.showGraph
+ : nodeStatuses.showWarning
+ );
+ }
+ }, [nodes]);
+
return (
}>
-
+ {nodesStatus === nodeStatuses.showGraph && (
+
+ )}
+ {nodesStatus === nodeStatuses.showWarning && (
+
+ )}
);
}