jusrhee 4 лет назад
Родитель
Сommit
cb79e33843

+ 20 - 20
dashboard/src/components/porter-form/PorterFormContextProvider.tsx

@@ -45,7 +45,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
     state: PorterFormState,
     state: PorterFormState,
     action: PorterFormAction
     action: PorterFormAction
   ): PorterFormState => {
   ): PorterFormState => {
-    switch (action.type) {
+    switch (action?.type) {
       case "init-field":
       case "init-field":
         if (!(action.id in state.components)) {
         if (!(action.id in state.components)) {
           return {
           return {
@@ -125,7 +125,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
     data?.tabs?.map((tab) =>
     data?.tabs?.map((tab) =>
       tab.sections?.map((section) =>
       tab.sections?.map((section) =>
         section.contents?.map((field) => {
         section.contents?.map((field) => {
-          if (field.type == "variable") {
+          if (field?.type == "variable") {
             ret[field.variable] = field.settings?.default;
             ret[field.variable] = field.settings?.default;
           }
           }
         })
         })
@@ -140,11 +140,11 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
       tab.sections?.map((section, j) =>
       tab.sections?.map((section, j) =>
         section.contents?.map((field, k) => {
         section.contents?.map((field, k) => {
           if (
           if (
-            field.type == "heading" ||
-            field.type == "subtitle" ||
-            field.type == "resource-list" ||
-            field.type == "service-ip-list" ||
-            field.type == "velero-create-backup"
+            field?.type == "heading" ||
+            field?.type == "subtitle" ||
+            field?.type == "resource-list" ||
+            field?.type == "service-ip-list" ||
+            field?.type == "velero-create-backup"
           )
           )
             return;
             return;
           if (
           if (
@@ -223,7 +223,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
               ...section,
               ...section,
               contents: section.contents
               contents: section.contents
                 ?.map((field: any) => {
                 ?.map((field: any) => {
-                  if (field.type == "number-input") {
+                  if (field?.type == "number-input") {
                     return {
                     return {
                       ...field,
                       ...field,
                       type: "input",
                       type: "input",
@@ -233,7 +233,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
                       },
                       },
                     };
                     };
                   }
                   }
-                  if (field.type == "string-input") {
+                  if (field?.type == "string-input") {
                     return {
                     return {
                       ...field,
                       ...field,
                       type: "input",
                       type: "input",
@@ -243,7 +243,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
                       },
                       },
                     };
                     };
                   }
                   }
-                  if (field.type == "string-input-password") {
+                  if (field?.type == "string-input-password") {
                     return {
                     return {
                       ...field,
                       ...field,
                       type: "input",
                       type: "input",
@@ -253,7 +253,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
                       },
                       },
                     };
                     };
                   }
                   }
-                  if (field.type == "provider-select") {
+                  if (field?.type == "provider-select") {
                     return {
                     return {
                       ...field,
                       ...field,
                       type: "select",
                       type: "select",
@@ -263,7 +263,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
                       },
                       },
                     };
                     };
                   }
                   }
-                  if (field.type == "env-key-value-array") {
+                  if (field?.type == "env-key-value-array") {
                     return {
                     return {
                       ...field,
                       ...field,
                       type: "key-value-array",
                       type: "key-value-array",
@@ -275,7 +275,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
                       },
                       },
                     };
                     };
                   }
                   }
-                  if (field.type == "variable") return null;
+                  if (field?.type == "variable") return null;
                   return field;
                   return field;
                 })
                 })
                 .filter((x) => x != null),
                 .filter((x) => x != null),
@@ -335,11 +335,11 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
       tab.sections?.map((section) =>
       tab.sections?.map((section) =>
         section.contents?.map((field) => {
         section.contents?.map((field) => {
           if (
           if (
-            field.type == "heading" ||
-            field.type == "subtitle" ||
-            field.type == "resource-list" ||
-            field.type == "service-ip-list" ||
-            field.type == "velero-create-backup"
+            field?.type == "heading" ||
+            field?.type == "subtitle" ||
+            field?.type == "resource-list" ||
+            field?.type == "service-ip-list" ||
+            field?.type == "velero-create-backup"
           )
           )
             return;
             return;
           // fields that have defaults can't be required since we can always
           // fields that have defaults can't be required since we can always
@@ -398,9 +398,9 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
     data?.tabs?.map((tab) =>
     data?.tabs?.map((tab) =>
       tab.sections?.map((section) =>
       tab.sections?.map((section) =>
         section.contents?.map((field) => {
         section.contents?.map((field) => {
-          if (finalFunctions[field.type])
+          if (finalFunctions[field?.type])
             varList.push(
             varList.push(
-              finalFunctions[field.type](
+              finalFunctions[field?.type](
                 state.variables,
                 state.variables,
                 field,
                 field,
                 state.components[field.id]?.state,
                 state.components[field.id]?.state,

+ 1 - 1
dashboard/src/components/porter-form/PorterFormWrapper.tsx

@@ -38,7 +38,7 @@ const PorterFormWrapper: React.FunctionComponent<PropsType> = ({
   isLaunch,
   isLaunch,
 }) => {
 }) => {
   const hashCode = (s: string) => {
   const hashCode = (s: string) => {
-    return s.split("").reduce(function (a, b) {
+    return s?.split("").reduce(function (a, b) {
       a = (a << 5) - a + b.charCodeAt(0);
       a = (a << 5) - a + b.charCodeAt(0);
       return a & a;
       return a & a;
     }, 0);
     }, 0);

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

@@ -42,7 +42,7 @@ const ArrayInput: React.FC<ArrayInputField> = (props) => {
   const renderInputList = (values: string[]) => {
   const renderInputList = (values: string[]) => {
     return (
     return (
       <>
       <>
-        {values.map((value: string, i: number) => {
+        {values?.map((value: string, i: number) => {
           return (
           return (
             <InputWrapper>
             <InputWrapper>
               <Input
               <Input
@@ -53,7 +53,7 @@ const ArrayInput: React.FC<ArrayInputField> = (props) => {
                   e.persist();
                   e.persist();
                   setVars((prev) => {
                   setVars((prev) => {
                     return {
                     return {
-                      [props.variable]: prev[props.variable].map(
+                      [props.variable]: prev[props.variable]?.map(
                         (t: string, j: number) => {
                         (t: string, j: number) => {
                           return i == j ? e.target.value : t;
                           return i == j ? e.target.value : t;
                         }
                         }

+ 11 - 0
dashboard/src/components/porter-form/field-components/Checkbox.tsx

@@ -59,11 +59,22 @@ export const getFinalVariablesForCheckbox: GetFinalVariablesFunction = (
   vars,
   vars,
   props: CheckboxField
   props: CheckboxField
 ) => {
 ) => {
+  // Read from revision values if unrendered (and therefore not in form state)
+  if (vars[props.variable] === null || vars[props.variable] === undefined) {
+    if (props.value[0] === false) {
+      return { [props.variable]: false };
+    } else if (props.value[0] === true) {
+      return { [props.variable]: true };
+    }
+  }
+
+  // Read from form state if set by user
   if (vars[props.variable] === false) {
   if (vars[props.variable] === false) {
     return { [props.variable]: false };
     return { [props.variable]: false };
   } else if (vars[props.variable] === true) {
   } else if (vars[props.variable] === true) {
     return { [props.variable]: true };
     return { [props.variable]: true };
   }
   }
+
   return {
   return {
     [props.variable]: props.value ? props.value[0] : !!props.settings?.default,
     [props.variable]: props.value ? props.value[0] : !!props.settings?.default,
   };
   };