Просмотр исходного кода

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 лет назад
Родитель
Сommit
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 }