Skip to content

Commit

Permalink
[feature]:(SqlAuditDrawer, SqlExecWorkflow, DataExportManagement) han…
Browse files Browse the repository at this point in the history
…dle exception scenarios in SQL audit
  • Loading branch information
LZS911 committed Jan 16, 2025
1 parent 7863f74 commit 9740e8f
Show file tree
Hide file tree
Showing 54 changed files with 1,297 additions and 391 deletions.
9 changes: 6 additions & 3 deletions packages/base/src/locale/zh-CN/dmsDataExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ export default {
'目前,支持 SQL 美化的数据库类型有 {{supportType}}。如果未选择数据源或选择的数据源类型尚未得到支持,进行 SQL 美化可能会导致 SQL 语句语法错误。'
}
},
submit: {
buttonText: '提交工单',
onlySupportDDLSqls: '仅支持对DQL语句创建导出工单',
hasExceptionRule: '当前存在审核规则未被校验,请排除问题后重新触发审核'
},
update: {
baseTitle: '工单基本信息',
sourceTitle: '工单导出对象',
methodTitle: '导出方式',
updateInfoAction: '修改工单',
submitAction: '提交工单',
submitTips: '仅支持对DQL语句创建导出工单'
updateInfoAction: '修改工单'
},
result: {
success: '工单创建成功',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports[`base/CloudBeaver/CBSqlOperationAuditDetailDrawer should match snap shot
</span>
</div>
<div
class="audit-report-wrapper css-126skhi"
class="audit-report-wrapper css-1lblrgt"
>
<div
class="ant-spin-nested-loading css-dev-only-do-not-override-txh9fw"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import SqlRewrittenDrawer from 'sqle/src/components/SqlRewrittenDrawer';
const AuditResultTable: React.FC<AuditResultTableProps> = ({
taskID,
projectID,
updateExecuteSQLsTypeIsDQL
onSuccessGetDataExportTaskSqls,
onErrorGetDataExportTaskSqls
}) => {
const [currentAuditResultRecord, setCurrentAuditResultRecord] =
useState<IListDataExportTaskSQL>();
Expand Down Expand Up @@ -63,12 +64,10 @@ const AuditResultTable: React.FC<AuditResultTableProps> = ({
ready: typeof taskID === 'string',
refreshDeps: [pagination, taskID],
onSuccess(res) {
updateExecuteSQLsTypeIsDQL?.(
!!res.list?.every((item) => item.export_sql_type === 'dql')
);
onSuccessGetDataExportTaskSqls?.(res.list ?? []);
},
onError() {
updateExecuteSQLsTypeIsDQL?.(true);
onErrorGetDataExportTaskSqls?.();
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { IListDataExportTaskSQL } from '@actiontech/shared/lib/api/base/service/
export type AuditResultTableProps = {
taskID?: string;
projectID: string;
updateExecuteSQLsTypeIsDQL?: (val: boolean) => void;
onSuccessGetDataExportTaskSqls?: (taskSqls: IListDataExportTaskSQL[]) => void;
onErrorGetDataExportTaskSqls?: () => void;
};

export type AuditResultDrawerProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ exports[`test DataExport/Common/AuditResultList should match snapshot 4`] = `
</span>
</div>
<div
class="audit-report-wrapper css-126skhi"
class="audit-report-wrapper css-1lblrgt"
>
<div
class="ant-spin-nested-loading css-dev-only-do-not-override-txh9fw"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { act, cleanup, fireEvent, screen } from '@testing-library/react';
import { act, fireEvent, screen } from '@testing-library/react';
import AuditResultList from '.';
import { superRender } from '../../../../testUtils/customRender';
import dataExport from '../../../../testUtils/mockApi/dataExport';
import {
BatchGetDataExportTaskResponseData,
ListDataExportTaskSQLsResponseData
} from '../../../../testUtils/mockApi/dataExport/data';
import {
createSpySuccessResponse,
createSpyFailResponse
} from '@actiontech/shared/lib/testUtil/mockApi';
import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi';
import { GetDataExportTaskStatusEnum } from '@actiontech/shared/lib/api/base/service/common.enum';
import {
getAllBySelector,
Expand Down Expand Up @@ -229,65 +226,22 @@ describe('test DataExport/Common/AuditResultList', () => {
expect(container).toMatchSnapshot();
});

it('should execute updateExecuteSQLsTypeIsDQL', async () => {
const updateExecuteSQLsTypeIsDQLSpy = jest.fn();
it('should execute onSuccessGetDataExportTaskSqlsSpy', async () => {
const onSuccessGetDataExportTaskSqlsSpy = jest.fn();
superRender(
<AuditResultList
taskIDs={taskIDs}
projectID={projectID}
updateExecuteSQLsTypeIsDQL={updateExecuteSQLsTypeIsDQLSpy}
onSuccessGetDataExportTaskSqls={onSuccessGetDataExportTaskSqlsSpy}
/>
);
await act(async () => jest.advanceTimersByTime(3000));
await act(async () => jest.advanceTimersByTime(3000));

expect(updateExecuteSQLsTypeIsDQLSpy).toHaveBeenCalledTimes(1);
expect(updateExecuteSQLsTypeIsDQLSpy).toHaveBeenCalledWith(true);

jest.clearAllMocks();
cleanup();

getTaskSQLsSpy.mockImplementation(() =>
createSpySuccessResponse({
data: [
...ListDataExportTaskSQLsResponseData,
{
uid: 7,
sql: 'INSERT INTO t1 values (name, "test")',
export_status: '',
export_sql_type: 'dml',
audit_level: ''
}
]
})
expect(onSuccessGetDataExportTaskSqlsSpy).toHaveBeenCalledTimes(1);
expect(onSuccessGetDataExportTaskSqlsSpy).toHaveBeenCalledWith(
ListDataExportTaskSQLsResponseData
);
superRender(
<AuditResultList
taskIDs={taskIDs}
projectID={projectID}
updateExecuteSQLsTypeIsDQL={updateExecuteSQLsTypeIsDQLSpy}
/>
);
await act(async () => jest.advanceTimersByTime(3000));
await act(async () => jest.advanceTimersByTime(3000));
expect(updateExecuteSQLsTypeIsDQLSpy).toHaveBeenCalledTimes(1);
expect(updateExecuteSQLsTypeIsDQLSpy).toHaveBeenCalledWith(false);

jest.clearAllMocks();
cleanup();

getTaskSQLsSpy.mockImplementation(() => createSpyFailResponse({}));
superRender(
<AuditResultList
taskIDs={taskIDs}
projectID={projectID}
updateExecuteSQLsTypeIsDQL={updateExecuteSQLsTypeIsDQLSpy}
/>
);
await act(async () => jest.advanceTimersByTime(3000));
await act(async () => jest.advanceTimersByTime(3000));
expect(updateExecuteSQLsTypeIsDQLSpy).toHaveBeenCalledTimes(1);
expect(updateExecuteSQLsTypeIsDQLSpy).toHaveBeenCalledWith(true);
});

it('should render sql rewriter button', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { AuditTaskResV1AuditLevelEnum } from '@actiontech/shared/lib/api/sqle/se
const AuditResultList: React.FC<AuditResultListProps> = ({
taskIDs,
projectID,
updateExecuteSQLsTypeIsDQL
onErrorGetDataExportTaskSqls,
onSuccessGetDataExportTaskSqls
}) => {
const [tasks, setTasks] = useState<IGetDataExportTask[]>([]);

Expand Down Expand Up @@ -68,7 +69,8 @@ const AuditResultList: React.FC<AuditResultListProps> = ({
<AuditResultTable
taskID={currentTaskID}
projectID={projectID}
updateExecuteSQLsTypeIsDQL={updateExecuteSQLsTypeIsDQL}
onErrorGetDataExportTaskSqls={onErrorGetDataExportTaskSqls}
onSuccessGetDataExportTaskSqls={onSuccessGetDataExportTaskSqls}
/>
</AuditResultStyleWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { IListDataExportTaskSQL } from '@actiontech/shared/lib/api/base/service/common';

export type AuditResultListProps = {
taskIDs: string[];
projectID: string;
updateExecuteSQLsTypeIsDQL?: (val: boolean) => void;
onSuccessGetDataExportTaskSqls?: (taskSqls: IListDataExportTaskSQL[]) => void;
onErrorGetDataExportTaskSqls?: () => void;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test SubmitWorkflowButton handles button click 1`] = `
<div>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
提交工单
</span>
</button>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { fireEvent, screen } from '@testing-library/dom';
import SubmitWorkflowButton from '..';
import { superRender } from '../../../../../../../testUtils/customRender';

describe('test SubmitWorkflowButton', () => {
it('handles button click', () => {
const onClick = jest.fn();

const { container } = superRender(
<SubmitWorkflowButton
executeSQLsIsDQL={true}
loading={false}
onClick={onClick}
hasExceptionAuditRule={false}
/>
);
expect(container).toMatchSnapshot();

fireEvent.click(screen.getByText('提交工单'));
expect(onClick).toHaveBeenCalledTimes(1);
});

it('displays the tooltip message when executeSQLsIsDQL is false', async () => {
const onClick = jest.fn();

superRender(
<SubmitWorkflowButton
executeSQLsIsDQL={false}
loading={false}
onClick={onClick}
hasExceptionAuditRule={false}
/>
);
fireEvent.click(screen.getByText('提交工单'));
expect(onClick).not.toHaveBeenCalled();

fireEvent.mouseOver(screen.getByText('提交工单'));

await screen.findByText('仅支持对DQL语句创建导出工单');
});

it('disables the button when loading prop is true', () => {
const onClick = jest.fn();

superRender(
<SubmitWorkflowButton
executeSQLsIsDQL={true}
loading={true}
onClick={onClick}
hasExceptionAuditRule={false}
/>
);
fireEvent.click(screen.getByText('提交工单'));
expect(onClick).not.toHaveBeenCalled();
});

it('displays the tooltip message when hasExceptionAuditRule is equal true', async () => {
const onClick = jest.fn();

superRender(
<SubmitWorkflowButton
executeSQLsIsDQL={false}
loading={false}
onClick={onClick}
hasExceptionAuditRule
/>
);
fireEvent.click(screen.getByText('提交工单'));
expect(onClick).not.toHaveBeenCalled();

fireEvent.mouseOver(screen.getByText('提交工单'));

await screen.findByText(
'当前存在审核规则未被校验,请排除问题后重新触发审核'
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ActionButton, BasicButton } from '@actiontech/shared';
import { SubmitWorkflowButtonProps } from './index.type';
import { useTranslation } from 'react-i18next';
import { InfoHexagonOutlined } from '@actiontech/icons';

const SubmitWorkflowButton: React.FC<SubmitWorkflowButtonProps> = ({
loading,
onClick,
hasExceptionAuditRule,
executeSQLsIsDQL
}) => {
const { t } = useTranslation();

if (hasExceptionAuditRule) {
return (
<ActionButton
danger
disabled
actionType="tooltip"
icon={<InfoHexagonOutlined color="currentColor" height={20} />}
tooltip={{
title: t('dmsDataExport.create.submit.hasExceptionRule')
}}
text={t('dmsDataExport.create.submit.buttonText')}
/>
);
}

if (!executeSQLsIsDQL) {
return (
<ActionButton
disabled
actionType="tooltip"
icon={<InfoHexagonOutlined color="currentColor" height={20} />}
tooltip={{
title: t('dmsDataExport.create.submit.onlySupportDDLSqls')
}}
text={t('dmsDataExport.create.submit.buttonText')}
/>
);
}

return (
<BasicButton loading={loading} type="primary" onClick={onClick}>
{t('dmsDataExport.create.submit.buttonText')}
</BasicButton>
);
};

export default SubmitWorkflowButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type SubmitWorkflowButtonProps = {
executeSQLsIsDQL: boolean;
onClick: () => void;
loading: boolean;
hasExceptionAuditRule: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ describe('test base/DataExport/Create/SubmitWorkflow', () => {
superRender(<SubmitExportWorkflow />);

expect(screen.getByText('修改工单').closest('button')).toBeDisabled();
expect(screen.getByText('提交工单').closest('button')).toBeDisabled();
expect(screen.getByText('提交工单').closest('button')).toHaveClass(
'ant-btn-loading'
);
});

it('should send submit request when clicked submit button', async () => {
Expand Down
Loading

0 comments on commit 9740e8f

Please sign in to comment.