Преглед на файлове

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 }