Просмотр исходного кода

Add null safe checking on resource list

jnfrati 4 лет назад
Родитель
Сommit
6e5a224ca4

+ 9 - 2
dashboard/src/components/porter-form/field-components/ResourceList.tsx

@@ -27,8 +27,15 @@ const ResourceList: React.FC<ResourceListField> = (props) => {
   };
 
   useEffect(() => {
+    if (
+      !formState?.variables?.currentChart?.name ||
+      !formState?.variables?.namespace
+    ) {
+      return () => {};
+    }
+
     let { group, version, resource } = props.context.config;
-    let apiEndpoint = `/api/projects/${currentProject.id}/clusters/${currentCluster.id}/namespaces/${formState.variables.namespace}/releases/${formState.variables.currentChart.name}/0/form_stream?`;
+    let apiEndpoint = `/api/projects/${currentProject.id}/clusters/${currentCluster.id}/namespaces/${formState?.variables?.namespace}/releases/${formState?.variables?.currentChart?.name}/0/form_stream?`;
     apiEndpoint += `resource=${resource}&group=${group}&version=${version}`;
 
     const wsConfig = {
@@ -81,7 +88,7 @@ const ResourceList: React.FC<ResourceListField> = (props) => {
     return () => {
       closeAllWebsockets();
     };
-  }, []);
+  }, [formState?.variables?.currentChart, formState?.variables?.namespace]);
 
   return (
     <ResourceListWrapper>