Skip to content

Commit

Permalink
Merge branch 'dev-4.2.3' of code.alipay.com:oceanbase/oceanbase-devel…
Browse files Browse the repository at this point in the history
…oper-center into dev-4.2.3
  • Loading branch information
HSunboy committed Nov 13, 2023
2 parents bdc5e71 + dc9e95c commit 199a10a
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 296 deletions.
8 changes: 8 additions & 0 deletions src/common/network/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ export async function getSubTask(id: number): Promise<IResponseData<ISubTaskReco
return res?.data;
}

/*
* 切换表名
*/
export async function swapTableName(taskId: number): Promise<boolean> {
const res = await request.post(`/api/v2/osc/swapTable/${taskId}`);
return !!res?.data;
}

/**
* 获取数据源用户列表
*/
Expand Down
24 changes: 24 additions & 0 deletions src/component/Task/AlterDdlTask/CreateModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ enum SqlType {
CREATE = 'CREATE',
ALTER = 'ALTER',
}

export enum SwapTableType {
AUTO = 'AUTO',
MANUAL = 'MANUAL',
}

export enum ClearStrategy {
ORIGIN_TABLE_RENAME_AND_RESERVED = 'ORIGIN_TABLE_RENAME_AND_RESERVED',
ORIGIN_TABLE_DROP = 'ORIGIN_TABLE_DROP',
Expand Down Expand Up @@ -105,6 +111,7 @@ const CreateDDLTaskModal: React.FC<IProps> = (props) => {
sqlType,
sqlContent,
swapTableNameRetryTimes,
swapTableType,
lockTableTimeOutSeconds,
originTableCleanStrategy,
errorStrategy,
Expand All @@ -121,6 +128,7 @@ const CreateDDLTaskModal: React.FC<IProps> = (props) => {
swapTableNameRetryTimes,
originTableCleanStrategy,
lockUsers,
swapTableType,
};
const data = {
projectId,
Expand Down Expand Up @@ -507,6 +515,22 @@ const CreateDDLTaskModal: React.FC<IProps> = (props) => {
</Radio>
</Radio.Group>
</Form.Item>
<Form.Item
label="表名切换方式"
name="swapTableType"
initialValue={SwapTableType.AUTO}
rules={[
{
required: true,
message: '请选择表名切换方式',
},
]}
>
<Radio.Group>
<Radio value={SwapTableType.AUTO}>自动切换</Radio>
<Radio value={SwapTableType.MANUAL}>手工切换</Radio>
</Radio.Group>
</Form.Item>
</FormItemPanel>
<DescriptionInput />
</Form>
Expand Down
9 changes: 8 additions & 1 deletion src/component/Task/AlterDdlTask/DetailContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getFormatDateTime } from '@/util/utils';
import React from 'react';
import { Typography } from 'antd';
import { SimpleTextItem } from '../../component/SimpleTextItem';
import { ClearStrategy } from '../CreateModal';
import { ClearStrategy, SwapTableType } from '../CreateModal';
import { getDataSourceModeConfigByConnectionMode } from '@/common/datasource';
const { Text } = Typography;
interface IDDLAlterParamters {
Expand All @@ -40,6 +40,7 @@ interface IDDLAlterParamters {
lockTableTimeOutSeconds: number;
swapTableNameRetryTimes: number;
originTableCleanStrategy: ClearStrategy;
swapTableType: SwapTableType;
}
const ErrorStrategyText = {
ABORT: formatMessage({
Expand All @@ -61,6 +62,11 @@ const ClearStrategyMap = {
}), //重命名不处理
};

const SwapTableTypeMap = {
[SwapTableType.AUTO]: '自动切换',
[SwapTableType.MANUAL]: '手工切换',
};

const SQLContentSection = ({ task }) => {
return (
<SimpleTextItem
Expand Down Expand Up @@ -199,6 +205,7 @@ export function getItems(
//执行方式
taskExecStrategyMap[task?.executionStrategy],
],
['表名切换方式', SwapTableTypeMap[task?.parameters?.swapTableType] ?? '-'],
isTimerExecution ? timerExecutionItem : null,
[
formatMessage({
Expand Down
46 changes: 35 additions & 11 deletions src/component/Task/component/CommonDetailModal/TaskProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@
* limitations under the License.
*/

import { getSubTask } from '@/common/network/task';
import { getSubTask, swapTableName } from '@/common/network/task';
import Action from '@/component/Action';
import DisplayTable from '@/component/DisplayTable';
import { SQLContent } from '@/component/SQLContent';
import StatusLabel from '@/component/Task/component/Status';
import { TaskDetail, TaskRecordParameters } from '@/d.ts';
import { formatMessage } from '@/util/intl';
import { Drawer, Space } from 'antd';
import { Drawer, Space, message } from 'antd';
import React, { useEffect, useState } from 'react';
import { SimpleTextItem } from '../SimpleTextItem';
import styles from './index.less';
import { getDataSourceModeConfigByConnectionMode } from '@/common/datasource';

const getColumns = (params: { onOpenDetail: (id: number) => void }) => {
const getColumns = (params: {
onOpenDetail: (id: number) => void;
onSwapTable: (id: number) => void;
}) => {
return [
{
dataIndex: 'resultJson',
Expand All @@ -52,16 +55,28 @@ const getColumns = (params: { onOpenDetail: (id: number) => void }) => {
dataIndex: 'action',
title: formatMessage({ id: 'odc.component.CommonDetailModal.TaskProgress.Operation' }), //操作
ellipsis: true,
width: 92,
width: 120,
render: (_, record) => {
const resultJson = JSON.parse(record?.resultJson);
return (
<Action.Link
onClick={async () => {
params?.onOpenDetail(record?.id);
}}
>
{formatMessage({ id: 'odc.component.CommonDetailModal.TaskProgress.View' }) /*查看*/}
</Action.Link>
<>
<Action.Link
onClick={async () => {
params?.onOpenDetail(record?.id);
}}
>
{formatMessage({ id: 'odc.component.CommonDetailModal.TaskProgress.View' }) /*查看*/}
</Action.Link>
{resultJson?.manualSwapTableEnabled && (
<Action.Link
onClick={async () => {
params?.onSwapTable(record?.id);
}}
>
表名切换
</Action.Link>
)}
</>
);
},
},
Expand All @@ -83,6 +98,14 @@ const TaskProgress: React.FC<IProps> = (props) => {
setSubTasks(res?.contents?.[0].tasks);
};

const handleSwapTable = async (id: number) => {
const res = await swapTableName(id);
if (res) {
message.success('开始表名切换');
loadData();
}
};

useEffect(() => {
loadData();
}, []);
Expand All @@ -105,6 +128,7 @@ const TaskProgress: React.FC<IProps> = (props) => {
rowKey="id"
columns={getColumns({
onOpenDetail: handleDetailVisible,
onSwapTable: handleSwapTable,
})}
dataSource={subTasks}
expandable={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import { Button, Drawer, message, Space } from 'antd';
import { useForm } from 'antd/es/form/Form';
import { useContext, useEffect, useRef, useState } from 'react';
import styles from './index.less';
import ManualForm from './ManualForm';
import ScanForm from './ScanForm';
import tracert from '@/util/tracert';
import SensitiveRule from '../../SensitiveRule';
import { merge } from 'lodash';
const defaultScanTableData: Array<ScanTableData> = [];
const checkResult = (resData: Array<ScanTableData> = []) =>
resData?.length > 0 ? resData : defaultScanTableData;
Expand Down Expand Up @@ -116,7 +116,7 @@ const FormSensitiveColumnDrawer = ({
setSearchText('');
clearTimeout(timer.current);
};
const handleScanTableDataChange = (
const handleScanTableDataChange = async (
key: string,
columnName: string,
maskingAlgorithmId: number,
Expand All @@ -141,8 +141,6 @@ const FormSensitiveColumnDrawer = ({
});
}
});
setScanTableData(checkResult(resData));
setOriginScanTableData(checkResult(resData));
} else {
const newDataSource = sensitiveColumnMap.get(key).dataSource.map((item) => {
if (item.columnName === columnName) {
Expand All @@ -154,10 +152,20 @@ const FormSensitiveColumnDrawer = ({
sensitiveColumnMap?.forEach((ds) => {
resData.push(ds);
});
setScanTableData(checkResult(resData));
setOriginScanTableData(checkResult(resData));
}
setScanTableData(checkResult(resData));
setOriginScanTableData(checkResult(resData));
setSensitiveColumnMap(sensitiveColumnMap);
const fieldsValue = await _formRef.getFieldsValue();
await _formRef.setFieldsValue(
merge(fieldsValue, {
scanTableData: {
[`${key}`]: {
[`${columnName}`]: maskingAlgorithmId,
},
},
}),
);
};
const handleScanTableDataDelete = (database: string, tableName: string, columnName: string) => {
const key = `${database}_${tableName}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import { formatMessage } from '@/util/intl';
import { Button, Divider, Form, Select } from 'antd';
import { useContext, useEffect, useState } from 'react';
import SensitiveContext from '../../../SensitiveContext';
import HelpDoc from '@/component/helpDoc';
import { ProjectRole } from '@/d.ts/project';
import { projectRoleTextMap } from '@/page/Project/User';
const ScanRule = ({ formRef, reset, setManageSensitiveRuleDrawerOpen }) => {
const context = useContext(ProjectContext);
const sensitiveContext = useContext(SensitiveContext);
Expand Down
Loading

0 comments on commit 199a10a

Please sign in to comment.