Răsfoiți Sursa

Merge pull request #530 from smiclea/fix-required-defaults

Fix endpoint required default field being skipped CORWEB-233
Nashwan Azhari 6 ani în urmă
părinte
comite
fdcd7e8f3e
1 a modificat fișierele cu 16 adăugiri și 1 ștergeri
  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 }