Explorar el Código

update shared status to prevent breakage

Alexander Belanger hace 4 años
padre
commit
c7bdb697a3

+ 36 - 42
dashboard/src/components/ProvisionerStatus.tsx

@@ -11,25 +11,24 @@ type Props = {
 };
 };
 
 
 export interface TFModule {
 export interface TFModule {
-  id: number
-  kind: string
-  status: string
-  created_at: string
-  got_desired: boolean
-  global_errors?: TFResourceError[]
+  id: number;
+  kind: string;
+  status: string;
+  created_at: string;
+  global_errors?: TFResourceError[];
   // optional resources, if not created
   // optional resources, if not created
-  resources?: TFResource[]
+  resources?: TFResource[];
 }
 }
 
 
 export interface TFResourceError {
 export interface TFResourceError {
-  errored_out: boolean
-  error_context?: string
+  errored_out: boolean;
+  error_context?: string;
 }
 }
 
 
 export interface TFResource {
 export interface TFResource {
-  addr: string,
-  provisioned: boolean,
-  errored: TFResourceError,
+  addr: string;
+  provisioned: boolean;
+  errored: TFResourceError;
 }
 }
 
 
 const nameMap: { [key: string]: string } = {
 const nameMap: { [key: string]: string } = {
@@ -75,8 +74,8 @@ const ProvisionerStatus: React.FC<Props> = ({ modules }) => {
   };
   };
 
 
   const renderModules = () => {
   const renderModules = () => {
-    return modules.map(val => {
-      console.log(val)
+    return modules.map((val) => {
+      console.log(val);
       const totalResources = val.resources?.length;
       const totalResources = val.resources?.length;
       const provisionedResources = val.resources?.filter((resource) => {
       const provisionedResources = val.resources?.filter((resource) => {
         return resource.provisioned;
         return resource.provisioned;
@@ -85,39 +84,40 @@ const ProvisionerStatus: React.FC<Props> = ({ modules }) => {
       let errors: string[] = [];
       let errors: string[] = [];
 
 
       if (val.status == "destroyed") {
       if (val.status == "destroyed") {
-        errors.push("Note: this infrastructure was automatically destroyed.")
+        errors.push("Note: this infrastructure was automatically destroyed.");
       }
       }
 
 
-      let hasError = val.resources?.filter((resource) => {
-        if (resource.errored?.errored_out) {
-          errors.push(resource.errored?.error_context)
-        }
+      let hasError =
+        val.resources?.filter((resource) => {
+          if (resource.errored?.errored_out) {
+            errors.push(resource.errored?.error_context);
+          }
 
 
-        return resource.errored?.errored_out
-      }).length > 0
+          return resource.errored?.errored_out;
+        }).length > 0;
 
 
       if (val.global_errors) {
       if (val.global_errors) {
         for (let globalErr of val.global_errors) {
         for (let globalErr of val.global_errors) {
-          errors.push("Global error: " + globalErr.error_context)
-          hasError = true
+          errors.push("Global error: " + globalErr.error_context);
+          hasError = true;
         }
         }
       }
       }
 
 
-      const width = 100 * (provisionedResources / (totalResources * 1.0)) || 0
+      const width = 100 * (provisionedResources / (totalResources * 1.0)) || 0;
 
 
       let error = null;
       let error = null;
 
 
       if (hasError) {
       if (hasError) {
         error = errors.map((error, index) => {
         error = errors.map((error, index) => {
-          return <ExpandedError key={index}>{error}</ExpandedError>
-        })
-      } 
+          return <ExpandedError key={index}>{error}</ExpandedError>;
+        });
+      }
       let loadingFill;
       let loadingFill;
       let status;
       let status;
 
 
       if (hasError || val.status == "destroyed") {
       if (hasError || val.status == "destroyed") {
-        loadingFill = <LoadingFill status="error" width={width + "%"} />
-        status = renderStatus("error")
+        loadingFill = <LoadingFill status="error" width={width + "%"} />;
+        status = renderStatus("error");
       } else if (width == 100) {
       } else if (width == 100) {
         loadingFill = <LoadingFill status="successful" width={width + "%"} />;
         loadingFill = <LoadingFill status="successful" width={width + "%"} />;
         status = renderStatus("successful");
         status = renderStatus("successful");
@@ -130,28 +130,22 @@ const ProvisionerStatus: React.FC<Props> = ({ modules }) => {
         <InfraObject key={val.id}>
         <InfraObject key={val.id}>
           <InfraHeader>
           <InfraHeader>
             <Flex>
             <Flex>
-            {status}
-            {
-              integrationList[val.kind] && <Icon src={integrationList[val.kind].icon} />
-            }
-            {nameMap[val.kind]}
+              {status}
+              {integrationList[val.kind] && (
+                <Icon src={integrationList[val.kind].icon} />
+              )}
+              {nameMap[val.kind]}
             </Flex>
             </Flex>
             <Timestamp>Started {readableDate(val.created_at)}</Timestamp>
             <Timestamp>Started {readableDate(val.created_at)}</Timestamp>
           </InfraHeader>
           </InfraHeader>
           <LoadingBar>{loadingFill}</LoadingBar>
           <LoadingBar>{loadingFill}</LoadingBar>
-          <ErrorWrapper>
-            {error}
-          </ErrorWrapper>
+          <ErrorWrapper>{error}</ErrorWrapper>
         </InfraObject>
         </InfraObject>
       );
       );
     });
     });
   };
   };
 
 
-  return (
-    <StyledProvisionerStatus>
-      {renderModules()}
-    </StyledProvisionerStatus>
-  );
+  return <StyledProvisionerStatus>{renderModules()}</StyledProvisionerStatus>;
 };
 };
 
 
 export default ProvisionerStatus;
 export default ProvisionerStatus;

+ 1 - 1
dashboard/src/main/home/onboarding/steps/ProvisionResources/ProvisionResources.tsx

@@ -50,7 +50,7 @@ const ProvisionResources: React.FC<Props> = ({
   }>(null);
   }>(null);
 
 
   const renderSaveButton = () => {
   const renderSaveButton = () => {
-    if (!infraStatus.hasError) {
+    if (!infraStatus?.hasError) {
       return (
       return (
         <>
         <>
           <Br height="15px" />
           <Br height="15px" />

+ 13 - 6
dashboard/src/main/home/onboarding/steps/ProvisionResources/forms/SharedStatus.tsx

@@ -8,7 +8,7 @@ import api from "shared/api";
 import { useWebsockets } from "shared/hooks/useWebsockets";
 import { useWebsockets } from "shared/hooks/useWebsockets";
 
 
 export const SharedStatus: React.FC<{
 export const SharedStatus: React.FC<{
-  setInfraStatus: (status: string) => void;
+  setInfraStatus: (status: { hasError: boolean; description?: string }) => void;
   project_id: number;
   project_id: number;
   filter: string[];
   filter: string[];
 }> = ({ setInfraStatus, project_id, filter }) => {
 }> = ({ setInfraStatus, project_id, filter }) => {
@@ -88,7 +88,9 @@ export const SharedStatus: React.FC<{
         tfModules.filter((val) => val.status == "created").length ==
         tfModules.filter((val) => val.status == "created").length ==
         tfModules.length
         tfModules.length
       ) {
       ) {
-        setInfraStatus("created");
+        setInfraStatus({
+          hasError: false,
+        });
         return;
         return;
       }
       }
 
 
@@ -96,7 +98,9 @@ export const SharedStatus: React.FC<{
         tfModules.filter((val) => val.status == "error").length ==
         tfModules.filter((val) => val.status == "error").length ==
         tfModules.length
         tfModules.length
       ) {
       ) {
-        setInfraStatus("error");
+        setInfraStatus({
+          hasError: true,
+        });
         return;
         return;
       }
       }
 
 
@@ -130,11 +134,15 @@ export const SharedStatus: React.FC<{
       }
       }
 
 
       if (numModulesSuccessful == tfModules.length) {
       if (numModulesSuccessful == tfModules.length) {
-        setInfraStatus("created");
+        setInfraStatus({
+          hasError: false,
+        });
       } else if (numModulesErrored + numModulesSuccessful == tfModules.length) {
       } else if (numModulesErrored + numModulesSuccessful == tfModules.length) {
         // otherwise, if all modules are either in an error state or successful,
         // otherwise, if all modules are either in an error state or successful,
         // set the status to error
         // set the status to error
-        setInfraStatus("error");
+        setInfraStatus({
+          hasError: true,
+        });
       }
       }
     }
     }
   }, [tfModules]);
   }, [tfModules]);
@@ -295,7 +303,6 @@ export const SharedStatus: React.FC<{
           id: infra.id,
           id: infra.id,
           kind: infra.kind,
           kind: infra.kind,
           status: infra.status,
           status: infra.status,
-          got_desired: false,
           created_at: infra.created_at,
           created_at: infra.created_at,
         };
         };