Explorar el Código

Added usePrevious to not refresh the jobs if it's the same chart

jnfrati hace 4 años
padre
commit
fd287abed7

+ 14 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/jobs/useJobs.ts

@@ -5,6 +5,7 @@ import { Context } from "shared/Context";
 import { NewWebsocketOptions, useWebsockets } from "shared/hooks/useWebsockets";
 import { NewWebsocketOptions, useWebsockets } from "shared/hooks/useWebsockets";
 import { ChartType } from "shared/types";
 import { ChartType } from "shared/types";
 import yaml from "js-yaml";
 import yaml from "js-yaml";
+import { usePrevious } from "shared/hooks/usePrevious";
 
 
 const PORTER_IMAGE_TEMPLATES = [
 const PORTER_IMAGE_TEMPLATES = [
   "porterdev/hello-porter-job",
   "porterdev/hello-porter-job",
@@ -26,6 +27,8 @@ export const useJobs = (chart: ChartType) => {
     "loading" | "successful" | string
     "loading" | "successful" | string
   >("");
   >("");
 
 
+  const previousChart = usePrevious(chart, null);
+
   const {
   const {
     newWebsocket,
     newWebsocket,
     openWebsocket,
     openWebsocket,
@@ -203,6 +206,17 @@ export const useJobs = (chart: ChartType) => {
         closeAllWebsockets();
         closeAllWebsockets();
       };
       };
     }
     }
+
+    if (
+      previousChart?.name === chart?.name &&
+      previousChart?.namespace === chart?.namespace
+    ) {
+      return () => {
+        isSubscribed = false;
+        closeAllWebsockets();
+      };
+    }
+
     setStatus("loading");
     setStatus("loading");
     const newestImage = chart?.config?.image?.repository;
     const newestImage = chart?.config?.image?.repository;