소스 검색

fixed crashing in forms.yaml editor (#2685)

Stefan McShane 3 년 전
부모
커밋
ce646f514a
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 4
      dashboard/src/components/porter-form/field-components/KeyValueArray.tsx

+ 6 - 4
dashboard/src/components/porter-form/field-components/KeyValueArray.tsx

@@ -32,14 +32,17 @@ const KeyValueArray: React.FC<Props> = (props) => {
     props.id,
     props.id,
     {
     {
       initState: () => {
       initState: () => {
-        let values = props.value[0];
+        let values = {}
+        if (props?.value?.length > 0) {
+          values = props.value[0]
+        }
         const normalValues = Object.entries(values?.normal || {});
         const normalValues = Object.entries(values?.normal || {});
         values = omit(values, ["normal", "synced", "build"]);
         values = omit(values, ["normal", "synced", "build"]);
         return {
         return {
           values: hasSetValue(props)
           values: hasSetValue(props)
             ? ([...Object.entries(values), ...normalValues]?.map(([k, v]) => {
             ? ([...Object.entries(values), ...normalValues]?.map(([k, v]) => {
-                return { key: k, value: v };
-              }) as any[])
+              return { key: k, value: v };
+            }) as any[])
             : [],
             : [],
           showEnvModal: false,
           showEnvModal: false,
           showEditorModal: false,
           showEditorModal: false,
@@ -112,7 +115,6 @@ const KeyValueArray: React.FC<Props> = (props) => {
     }
     }
   }, [
   }, [
     props.injectedProps,
     props.injectedProps,
-    props.value[0],
     variables?.clusterId,
     variables?.clusterId,
     variables?.namespace,
     variables?.namespace,
     currentProject?.id,
     currentProject?.id,