You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by so...@apache.org on 2022/11/04 05:38:48 UTC

[dolphinscheduler] branch dev updated: [Feature][UI] Added form request parser. (#12691)

This is an automated email from the ASF dual-hosted git repository.

songjian pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new e702beced5 [Feature][UI] Added form request parser. (#12691)
e702beced5 is described below

commit e702beced5edb567c5f14bec19be3b1697890145
Author: songjianet <17...@qq.com>
AuthorDate: Fri Nov 4 13:38:40 2022 +0800

    [Feature][UI] Added form request parser. (#12691)
---
 .../components/dynamic-dag/task/use-form-field.ts  |  2 +-
 .../{use-form-structure.ts => use-form-request.ts} | 24 +++++++++++++++++-----
 .../dynamic-dag/task/use-form-structure.ts         |  2 +-
 .../dynamic-dag/task/use-form-validate.ts          |  2 +-
 .../components/dynamic-dag/task/use-task-form.ts   | 14 ++++++-------
 5 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts
index 0b195253e1..f4289158b6 100644
--- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts
+++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts
@@ -18,7 +18,7 @@
 import { ref } from 'vue'
 import type { Ref } from 'vue'
 
-export function useFormField(forms: any) {
+export function useFormField(forms: Array<any>) {
   const model: any = {}
 
   const setField = (value: string, type: string): Ref<null | string> => {
diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts
similarity index 64%
copy from dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts
copy to dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts
index dd6aa63c09..26cd524a94 100644
--- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts
+++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts
@@ -15,11 +15,25 @@
  * limitations under the License.
  */
 
-export function useFormStructure(forms: any) {
-  return forms.map((f: any) => {
-    delete f.validate
-    delete f.api
+import { axios } from '@/service/service'
 
-    return f
+const reqFunction = (url: string, method: string) => {
+  return axios({
+    url,
+    method
   })
+}
+
+export function useFormRequest(apis: any, forms: Array<any>) {
+  forms.map(f => {
+    if (f.api) {
+      reqFunction(apis[f.api].url, apis[f.api].method).then((res: any) => {
+        f.options = res.map((r: any) => {
+          return { label: r, value: r }
+        })
+      })
+    }
+  })
+
+  return forms
 }
\ No newline at end of file
diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts
index dd6aa63c09..34166ac653 100644
--- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts
+++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-export function useFormStructure(forms: any) {
+export function useFormStructure(forms: Array<any>) {
   return forms.map((f: any) => {
     delete f.validate
     delete f.api
diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts
index b829a5279b..c0a0c8210d 100644
--- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts
+++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts
@@ -18,7 +18,7 @@
 import { useI18n } from 'vue-i18n'
 import type { FormItemRule } from 'naive-ui'
 
-export function useFormValidate(forms: any) {
+export function useFormValidate(forms: Array<any>) {
   const { t } = useI18n()
   const validate: any = {}
 
diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts
index cefa0d839e..68d9ae752b 100644
--- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts
+++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts
@@ -20,6 +20,7 @@ import { useDynamicLocales } from './use-dynamic-locales'
 import { useFormField } from './use-form-field'
 import { useFormValidate } from './use-form-validate'
 import { useFormStructure } from './use-form-structure'
+import { useFormRequest } from './use-form-request'
 
 const data = {
   task: 'shell',
@@ -49,13 +50,12 @@ const data = {
       script: 'Script'
     }
   },
-  apis: [
-    {
-      name: 'getWorkerGroupList',
-      uri: '/worker-groups/all',
+  apis: {
+    getWorkerGroupList: {
+      url: '/worker-groups/all',
       method: 'get'
     }
-  ],
+  },
   forms: [
     {
       label: 'task_components.node_name',
@@ -121,10 +121,10 @@ export function useTaskForm() {
     rules: {}
   })
 
+  useDynamicLocales(data.locales)
   variables.model = useFormField(data.forms)
   variables.rules = useFormValidate(data.forms)
-  useDynamicLocales(data.locales)
-  variables.formStructure = useFormStructure(data.forms)
+  variables.formStructure = useFormStructure(useFormRequest(data.apis, data.forms))
 
   return {
     variables