From 303ee1bf15189f641f77c8eb55a6ccd9fc851d25 Mon Sep 17 00:00:00 2001 From: Devosend Date: Thu, 21 Apr 2022 15:28:48 +0800 Subject: [PATCH] [Fix][UI][V1.0.0-Beta]Fix data not update bug for workflow version switch (#9642) --- .../definition/components/use-table.ts | 230 +++++++++--------- .../definition/components/version-modal.tsx | 11 +- 2 files changed, 127 insertions(+), 114 deletions(-) diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-table.ts b/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-table.ts index c56854dcf..29b9de021 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-table.ts +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-table.ts @@ -35,118 +35,8 @@ export function useTable( const { t } = useI18n() const router: Router = useRouter() - const columns: TableColumns = [ - { - title: '#', - key: 'id', - width: 50, - render: (_row, index) => index + 1 - }, - { - title: t('project.workflow.version'), - key: 'version', - render: (_row) => { - if (_row.version === variables.row.version) { - return h( - NTag, - { type: 'success', size: 'small' }, - { - default: () => - `V${_row.version} ${t('project.workflow.current_version')}` - } - ) - } else { - return `V${_row.version}` - } - } - }, - { - title: t('project.workflow.description'), - key: 'description' - }, - { - title: t('project.workflow.create_time'), - key: 'operateTime' - }, - { - title: t('project.workflow.operation'), - key: 'operation', - className: styles.operation, - render: (_row) => { - return h(NSpace, null, { - default: () => [ - h( - NPopconfirm, - { - onPositiveClick: () => { - handleSwitchVersion(_row.version) - } - }, - { - trigger: () => - h( - NTooltip, - {}, - { - trigger: () => - h( - NButton, - { - circle: true, - type: 'info', - size: 'tiny', - disabled: _row.version === variables.row.version - }, - { - icon: () => h(ExclamationCircleOutlined) - } - ), - default: () => t('project.workflow.switch_version') - } - ), - default: () => t('project.workflow.confirm_switch_version') - } - ), - h( - NPopconfirm, - { - onPositiveClick: () => { - handleDeleteVersion(_row.version) - } - }, - { - trigger: () => - h( - NTooltip, - {}, - { - trigger: () => - h( - NButton, - { - circle: true, - type: 'error', - size: 'tiny', - disabled: _row.version === variables.row.version - }, - { - icon: () => h(DeleteOutlined) - } - ), - default: () => t('project.workflow.delete') - } - ), - default: () => t('project.workflow.delete_confirm') - } - ) - ] - }) - } - } - ] - const variables = reactive({ - columns, + columns: [], row: {} as any, tableData: [], page: ref(1), @@ -156,6 +46,118 @@ export function useTable( loadingRef: ref(false) }) + const createColumns = (variables: any) => { + variables.columns = [ + { + title: '#', + key: 'id', + width: 50, + render: (_row, index) => index + 1 + }, + { + title: t('project.workflow.version'), + key: 'version', + render: (_row) => { + if (_row.version === variables.row.version) { + return h( + NTag, + { type: 'success', size: 'small' }, + { + default: () => + `V${_row.version} ${t('project.workflow.current_version')}` + } + ) + } else { + return `V${_row.version}` + } + } + }, + { + title: t('project.workflow.description'), + key: 'description' + }, + { + title: t('project.workflow.create_time'), + key: 'operateTime' + }, + { + title: t('project.workflow.operation'), + key: 'operation', + className: styles.operation, + render: (_row) => { + return h(NSpace, null, { + default: () => [ + h( + NPopconfirm, + { + onPositiveClick: () => { + handleSwitchVersion(_row.version) + } + }, + { + trigger: () => + h( + NTooltip, + {}, + { + trigger: () => + h( + NButton, + { + circle: true, + type: 'info', + size: 'tiny', + disabled: _row.version === variables.row.version + }, + { + icon: () => h(ExclamationCircleOutlined) + } + ), + default: () => t('project.workflow.switch_version') + } + ), + default: () => t('project.workflow.confirm_switch_version') + } + ), + h( + NPopconfirm, + { + onPositiveClick: () => { + handleDeleteVersion(_row.version) + } + }, + { + trigger: () => + h( + NTooltip, + {}, + { + trigger: () => + h( + NButton, + { + circle: true, + type: 'error', + size: 'tiny', + disabled: _row.version === variables.row.version + }, + { + icon: () => h(DeleteOutlined) + } + ), + default: () => t('project.workflow.delete') + } + ), + default: () => t('project.workflow.delete_confirm') + } + ) + ] + }) + } + } + ] as TableColumns + } + const getTableData = (row: any) => { if (variables.loadingRef) return variables.loadingRef = true @@ -178,9 +180,9 @@ export function useTable( const handleSwitchVersion = (version: number) => { switchVersion(variables.projectCode, variables.row.code, version).then( () => { + variables.row.version = version window.$message.success(t('project.workflow.success')) ctx.emit('updateList') - getTableData(variables.row) } ) } @@ -190,6 +192,9 @@ export function useTable( () => { window.$message.success(t('project.workflow.success')) ctx.emit('updateList') + if (variables.tableData.length === 1 && variables.page > 1) { + variables.page -= 1 + } getTableData(variables.row) } ) @@ -197,6 +202,7 @@ export function useTable( return { variables, + createColumns, getTableData } } diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/version-modal.tsx b/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/version-modal.tsx index 3d761296c..3db070c41 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/version-modal.tsx +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/version-modal.tsx @@ -41,7 +41,7 @@ export default defineComponent({ props, emits: ['update:show', 'update:row', 'updateList'], setup(props, ctx) { - const { variables, getTableData } = useTable(ctx) + const { variables, createColumns, getTableData } = useTable(ctx) const { importState } = useForm() const { handleImportDefinition } = useModal(importState, ctx) @@ -66,9 +66,16 @@ export default defineComponent({ watch( () => props.show, - () => requestData() + () => { + createColumns(variables) + requestData() + } ) + watch(useI18n().locale, () => { + createColumns(variables) + }) + return { hideModal, handleImport,