From 9501eac255e22c3e27273ef234d0f2a7f27d9c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=8F=E5=92=8C?= Date: Mon, 27 Nov 2023 16:35:28 +0800 Subject: [PATCH] PullRequest: 243 feat: dataArchiveTask support edit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'feat/dev-4.2.2-task-1124 of git@code.alipay.com:oceanbase/oceanbase-developer-center.git into dev-4.2.2 https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/243 Signed-off-by: 晓康 * feat: dataArchiveTask support edit * feat: dataArchiveTask support edit (default value) --- .../DataArchiveTask/CreateModal/index.tsx | 128 +++++++++++++++--- .../Task/component/ActionBar/index.tsx | 13 +- .../Task/component/DatabaseSelect/index.tsx | 3 + src/store/modal.ts | 6 +- 4 files changed, 127 insertions(+), 23 deletions(-) diff --git a/src/component/Task/DataArchiveTask/CreateModal/index.tsx b/src/component/Task/DataArchiveTask/CreateModal/index.tsx index 50c2ef971..d3ccf9d95 100644 --- a/src/component/Task/DataArchiveTask/CreateModal/index.tsx +++ b/src/component/Task/DataArchiveTask/CreateModal/index.tsx @@ -15,9 +15,9 @@ */ import { getTableListByDatabaseName } from '@/common/network/table'; -import { createTask } from '@/common/network/task'; +import { createTask, getCycleTaskDetail } from '@/common/network/task'; import Crontab from '@/component/Crontab'; -import { CrontabDateType, ICrontab } from '@/component/Crontab/interface'; +import { CrontabDateType, ICrontab, CrontabMode } from '@/component/Crontab/interface'; import FormItemPanel from '@/component/FormItemPanel'; import DescriptionInput from '@/component/Task/component/DescriptionInput'; import { @@ -30,22 +30,25 @@ import { TaskPageScope, TaskPageType, TaskType, + IDataArchiveJobParameters, } from '@/d.ts'; import { openTasksPage } from '@/store/helper/page'; import type { ModalStore } from '@/store/modal'; import { useDBSession } from '@/store/sessionManager/hooks'; import { isClient } from '@/util/env'; import { formatMessage } from '@/util/intl'; -import { mbToKb } from '@/util/utils'; +import { mbToKb, kbToMb } from '@/util/utils'; import { FieldTimeOutlined } from '@ant-design/icons'; import { Button, Checkbox, DatePicker, Drawer, Form, Modal, Radio, Space } from 'antd'; import { inject, observer } from 'mobx-react'; import React, { useEffect, useRef, useState } from 'react'; +import moment from 'moment'; import DatabaseSelect from '../../component/DatabaseSelect'; import ArchiveRange from './ArchiveRange'; import styles from './index.less'; import VariableConfig from './VariableConfig'; import ThrottleFormItem from '../../component/ThrottleFormItem'; +import { timeUnitOptions } from './VariableConfig'; export enum IArchiveRange { PORTION = 'portion', ALL = 'all', @@ -67,7 +70,13 @@ export const InsertActionOptions = [ export const variable = { name: '', format: '', - pattern: [null], + pattern: [ + { + operator: '', + step: '', + unit: '', + }, + ], }; const defaultValue = { triggerStrategy: TaskExecStrategy.START_NOW, @@ -98,7 +107,7 @@ const getVariables = ( try { _pattern = pattern ?.map((item) => { - return `${item.operator}${item.step}${item.unit}`; + return `${item.operator}${item.step ?? 0}${item.unit}`; }) ?.join(' '); } catch (error) {} @@ -108,9 +117,41 @@ const getVariables = ( }; }); }; + +const getVariableValue = ( + value: { + name: string; + pattern: string; + }[], +) => { + var reg = /([+-])?(\d+)?(.+)?/; + return value?.map(({ name, pattern }) => { + const [format, _pattern] = pattern?.split('|'); + let patternValue = { + operator: '', + step: '', + unit: '', + }; + if (_pattern) { + const res = _pattern?.match(reg); + const operator = res[1] ?? ''; + const step = res[2] ?? ''; + const unit = timeUnitOptions.map((item) => item.value).includes(res[3]) ? res[3] : ''; + patternValue = { + operator, + step, + unit, + }; + } + return { + name, + format, + pattern: [patternValue], + }; + }); +}; const CreateModal: React.FC = (props) => { const { modalStore, projectId } = props; - const [formData, setFormData] = useState(null); const [hasEdit, setHasEdit] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false); const [crontab, setCrontab] = useState(null); @@ -127,15 +168,57 @@ const CreateModal: React.FC = (props) => { setValue: (value: ICrontab) => void; resetFields: () => void; }>(); - const { dataArchiveVisible, SQLPlanEditId } = modalStore; - const isEdit = !!SQLPlanEditId; - const setFormStatus = (fieldName: string, errorMessage: string) => { - form.setFields([ - { - name: [fieldName], - errors: errorMessage ? [errorMessage] : [], - }, - ]); + const { dataArchiveVisible, dataArchiveEditId } = modalStore; + const isEdit = !!dataArchiveEditId; + const loadEditData = async (editId: number) => { + const data = await getCycleTaskDetail(editId); + const { + jobParameters, + description, + triggerConfig: { triggerStrategy, cronExpression, hours, days, startAt }, + } = data; + + const { + targetDataBaseId, + sourceDatabaseId, + deleteAfterMigration, + migrationInsertAction, + rateLimit, + tables, + variables, + } = jobParameters; + + const formData = { + databaseId: sourceDatabaseId, + targetDatabase: targetDataBaseId, + rowLimit: rateLimit?.rowLimit, + dataSizeLimit: kbToMb(rateLimit?.dataSizeLimit), + deleteAfterMigration, + migrationInsertAction, + tables, + variables: getVariableValue(variables), + archiveRange: IArchiveRange.PORTION, + triggerStrategy, + startAt: undefined, + description, + }; + + if (![TaskExecStrategy.START_NOW, TaskExecStrategy.START_AT].includes(triggerStrategy)) { + formData.triggerStrategy = TaskExecStrategy.TIMER; + const crontab = { + mode: triggerStrategy === TaskExecStrategy.CRON ? CrontabMode.custom : CrontabMode.default, + dateType: triggerStrategy as any, + cronString: cronExpression, + hour: hours, + dayOfMonth: days, + dayOfWeek: days, + }; + setCrontab(crontab); + } + if (triggerStrategy === TaskExecStrategy.START_AT) { + formData.startAt = moment(startAt); + } + form.setFieldsValue(formData); }; const handleCancel = (hasEdit: boolean) => { if (hasEdit) { @@ -226,7 +309,7 @@ const CreateModal: React.FC = (props) => { const parameters = { type: TaskType.MIGRATION, operationType: isEdit ? TaskOperationType.UPDATE : TaskOperationType.CREATE, - taskId: SQLPlanEditId, + taskId: dataArchiveEditId, scheduleTaskParameters: { sourceDatabaseId: databaseId, targetDataBaseId: targetDatabase, @@ -289,7 +372,6 @@ const CreateModal: React.FC = (props) => { setHasEdit(true); }; const handleReset = () => { - setFormData(null); form?.resetFields(); crontabRef.current?.resetFields(); }; @@ -301,9 +383,18 @@ const CreateModal: React.FC = (props) => { useEffect(() => { if (database?.id) { loadTables(); - form.setFieldValue('tables', [null]); + if (!isEdit) { + form.setFieldValue('tables', [null]); + } } }, [database?.id]); + + useEffect(() => { + if (dataArchiveEditId) { + loadEditData(dataArchiveEditId); + } + }, [dataArchiveEditId]); + return ( = (props) => { = inject( const editCycleTask = async () => { props?.onClose?.(); - props.modalStore.changeCreateSQLPlanTaskModal(true, task?.id); + if (task?.type === TaskType.DATA_ARCHIVE) { + props.modalStore.changeDataArchiveModal(true, task?.id); + } else { + props.modalStore.changeCreateSQLPlanTaskModal(true, task?.id); + } }; const disableCycleTask = async () => { @@ -529,7 +533,8 @@ const ActionBar: React.FC = inject( _executeBtn.tooltip = formatMessage( { - id: 'odc.TaskManagePage.component.TaskTools.ScheduledExecutionTimeExecutiontime', + id: + 'odc.TaskManagePage.component.TaskTools.ScheduledExecutionTimeExecutiontime', }, { executionTime: executionTime }, @@ -694,8 +699,8 @@ const ActionBar: React.FC = inject( } else { tools = [viewBtn]; } - // 仅 sql 计划支持编辑 - if (task?.type !== TaskType.SQL_PLAN) { + // 仅 sql 计划 & 数据归档支持编辑 + if (![TaskType.SQL_PLAN, TaskType.DATA_ARCHIVE].includes(task?.type)) { tools = tools.filter((item) => item.key !== 'edit'); } return tools; diff --git a/src/component/Task/component/DatabaseSelect/index.tsx b/src/component/Task/component/DatabaseSelect/index.tsx index f607cb5cd..65d7c9059 100644 --- a/src/component/Task/component/DatabaseSelect/index.tsx +++ b/src/component/Task/component/DatabaseSelect/index.tsx @@ -29,6 +29,7 @@ import { toInteger } from 'lodash'; interface IProps { type: TaskType; label?: string; + disabled?: boolean; name?: string; projectId?: number; extra?: string; @@ -47,6 +48,7 @@ const DatabaseSelect: React.FC = (props) => { projectId, extra = '', width = '320px', + disabled = false, onChange, } = props; const [database, setDatabase] = useState([]); @@ -158,6 +160,7 @@ const DatabaseSelect: React.FC = (props) => { >