Explorar o código

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 %!s(int64=6) %!d(string=hai) anos
pai
achega
edf1406d34
Modificáronse 1 ficheiros con 16 adicións e 1 borrados
  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 }