소스 검색

Fix endpoint required default field being skipped

Fixes an issue where required fields where skipped when sending endpoint
creation data to the API, if the required fields had default values.
Sergiu Miclea 6 년 전
부모
커밋
edf1406d34
1개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 16 1
      src/components/organisms/Endpoint/Endpoint.jsx

+ 16 - 1
src/components/organisms/Endpoint/Endpoint.jsx

@@ -154,7 +154,11 @@ class Endpoint extends React.Component<Props, State> {
   }
 
   componentDidMount() {
-    providerStore.getConnectionInfoSchema(this.getEndpointType())
+    const loadSchema = async () => {
+      await providerStore.getConnectionInfoSchema(this.getEndpointType())
+      this.fillRequiredDefaults()
+    }
+    loadSchema()
     KeyboardManager.onEnter('endpoint', () => {
       if (this.isValidateButtonEnabled) this.handleValidateClick()
     }, 2)
@@ -225,6 +229,17 @@ class Endpoint extends React.Component<Props, State> {
     return ''
   }
 
+  fillRequiredDefaults() {
+    let endpoint = { ...this.state.endpoint }
+    let requiredFieldsDefaults = providerStore.connectionInfoSchema.filter(f => f.required && f.default != null)
+    requiredFieldsDefaults.forEach(f => {
+      if (endpoint[f.name] == null) {
+        endpoint[f.name] = f.default
+      }
+    })
+    this.setState({ endpoint })
+  }
+
   handleFieldsChange(items: { field: Field, value: any }[]) {
     let endpoint: any = { ...this.state.endpoint }