Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/shared/lib/api/sqle/service/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
exportSqlManageV2FilterStatusEnum,
exportSqlManageV2SortFieldEnum,
exportSqlManageV2SortOrderEnum,
exportSqlManageV2ExportFormatEnum,
GetSqlManageListV3FilterSourceEnum,
GetSqlManageListV3FilterAuditLevelEnum,
GetSqlManageListV3FilterStatusEnum,
Expand Down Expand Up @@ -280,6 +281,8 @@ export interface IExportSqlManageV2Params {
sort_field?: exportSqlManageV2SortFieldEnum;

sort_order?: exportSqlManageV2SortOrderEnum;

export_format?: exportSqlManageV2ExportFormatEnum;
}

export interface IGetSqlManageListV3Params {
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/lib/api/sqle/service/SqlManage/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export enum exportSqlManageV2SortOrderEnum {
'desc' = 'desc'
}

export enum exportSqlManageV2ExportFormatEnum {
'csv' = 'csv',

'excel' = 'excel'
}

export enum GetSqlManageListV3FilterSourceEnum {
'audit_plan' = 'audit_plan',

Expand Down
3 changes: 3 additions & 0 deletions packages/shared/lib/api/sqle/service/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DirectAuditReqV1SqlTypeEnum,
FilterMetaFilterInputTypeEnum,
FilterMetaFilterOpTypeEnum,
GetAuditPlanSQLExportReqV1ExportFormatEnum,
GetWorkflowTasksItemV1StatusEnum,
GlobalSqlManageProjectPriorityEnum,
GlobalSqlManageStatusEnum,
Expand Down Expand Up @@ -1352,6 +1353,8 @@ export interface IGetAuditPlanSQLDataResV1 {
}

export interface IGetAuditPlanSQLExportReqV1 {
export_format?: GetAuditPlanSQLExportReqV1ExportFormatEnum;

filter_list?: IFilter[];

is_asc?: boolean;
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/lib/api/sqle/service/common.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ export enum FilterMetaFilterOpTypeEnum {
'between' = 'between'
}

export enum GetAuditPlanSQLExportReqV1ExportFormatEnum {
'csv' = 'csv',

'excel' = 'excel'
}

export enum GetWorkflowTasksItemV1StatusEnum {
'wait_for_audit' = 'wait_for_audit',

Expand Down
3 changes: 3 additions & 0 deletions packages/shared/lib/api/sqle/service/workflow/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
getWorkflowsV1FilterStatusEnum,
autoCreateAndExecuteWorkflowV1ExecModeEnum,
exportWorkflowV1FilterStatusEnum,
exportWorkflowV1ExportFormatEnum,
GetBackupSqlListV1FilterExecStatusEnum
} from './index.enum';

Expand Down Expand Up @@ -245,6 +246,8 @@ export interface IExportWorkflowV1Params {
project_name: string;

fuzzy_keyword?: string;

export_format?: exportWorkflowV1ExportFormatEnum;
}

export interface IGetBackupSqlListV1Params {
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/lib/api/sqle/service/workflow/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ export enum exportWorkflowV1FilterStatusEnum {
'finished' = 'finished'
}

export enum exportWorkflowV1ExportFormatEnum {
'csv' = 'csv',

'excel' = 'excel'
}

export enum GetBackupSqlListV1FilterExecStatusEnum {
'initialized' = 'initialized',

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ExportFormatModal should render modal with correct title and options 1`] = `
<body>
<div />
<div>
<div
class="ant-modal-root"
>
<div
class="ant-modal-mask"
/>
<div
class="ant-modal-wrap"
tabindex="-1"
>
<div
aria-labelledby="test-id"
aria-modal="true"
class="ant-modal basic-modal-wrapper css-vvpsbb ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
role="dialog"
style="width: 480px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
class="ant-modal-content"
>
<button
aria-label="Close"
class="ant-modal-close"
type="button"
>
<span
class="ant-modal-close-x"
>
<svg
fill="currentColor"
height="16"
viewBox="0 0 14 14"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="m7 6.175 2.887-2.887.825.825L7.825 7l2.887 2.888-.825.824L7 7.825l-2.888 2.887-.824-.824L6.175 7 3.288 4.113l.824-.825z"
/>
</svg>
</span>
</button>
<div
class="ant-modal-header"
>
<div
class="ant-modal-title"
id="test-id"
>
选择导出文件格式
</div>
</div>
<div
class="ant-modal-body"
>
<div
class="ant-radio-group ant-radio-group-outline"
>
<div
class="ant-space ant-space-vertical"
>
<div
class="ant-space-item"
style="margin-bottom: 8px;"
>
<label
class="ant-radio-wrapper ant-radio-wrapper-checked"
>
<span
class="ant-radio ant-radio-checked"
>
<input
checked=""
class="ant-radio-input"
type="radio"
value="csv"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
CSV
</span>
</label>
</div>
<div
class="ant-space-item"
>
<label
class="ant-radio-wrapper"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="excel"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
Excel
</span>
</label>
</div>
</div>
</div>
</div>
<div
class="ant-modal-footer"
>
<div
class="ant-space ant-space-horizontal ant-space-align-center"
>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn ant-btn-default basic-button-wrapper css-lfzis8"
type="button"
>
<span>
取 消
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-primary basic-button-wrapper css-lfzis8"
type="button"
>
<span>
确 认
</span>
</button>
</div>
</div>
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
</div>
</div>
</div>
</div>
</body>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { fireEvent, screen } from '@testing-library/react';
import ExportFormatModal from '../index';
import { sqleSuperRender } from '../../../testUtils/superRender';
import { GetAuditPlanSQLExportReqV1ExportFormatEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';

describe('ExportFormatModal', () => {
const mockOnFormatChange = jest.fn();
const mockOnConfirm = jest.fn();
const mockOnCancel = jest.fn();

const defaultProps = {
open: true,
selectedFormat: GetAuditPlanSQLExportReqV1ExportFormatEnum.csv,
onFormatChange: mockOnFormatChange,
onConfirm: mockOnConfirm,
onCancel: mockOnCancel
};

beforeEach(() => {
jest.clearAllMocks();
});

it('should render modal with correct title and options', () => {
const { baseElement } = sqleSuperRender(
<ExportFormatModal {...defaultProps} />
);

expect(screen.getByText('选择导出文件格式')).toBeInTheDocument();
expect(screen.getByText('CSV')).toBeInTheDocument();
expect(screen.getByText('Excel')).toBeInTheDocument();
expect(baseElement).toMatchSnapshot();
});

it('should not render modal when open is false', () => {
sqleSuperRender(<ExportFormatModal {...defaultProps} open={false} />);

expect(screen.queryByText('选择导出文件格式')).not.toBeInTheDocument();
});

it('should call onFormatChange when format is changed', () => {
sqleSuperRender(<ExportFormatModal {...defaultProps} />);

const excelRadio = screen.getByText('Excel');
fireEvent.click(excelRadio);

expect(mockOnFormatChange).toHaveBeenCalledWith('excel');
});

it('should call onConfirm when confirm button is clicked', () => {
sqleSuperRender(<ExportFormatModal {...defaultProps} />);

const confirmButton = screen.getByText('确 认');
fireEvent.click(confirmButton);

expect(mockOnConfirm).toHaveBeenCalledTimes(1);
});

it('should call onCancel when cancel button is clicked', () => {
sqleSuperRender(<ExportFormatModal {...defaultProps} />);

const cancelButton = screen.getByText('取 消');
fireEvent.click(cancelButton);

expect(mockOnCancel).toHaveBeenCalledTimes(1);
});
});
55 changes: 55 additions & 0 deletions packages/sqle/src/components/ExportFormatModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { BasicButton, BasicModal } from '@actiontech/dms-kit';
import { Radio, Space } from 'antd';
import { useTranslation } from 'react-i18next';
import { GetAuditPlanSQLExportReqV1ExportFormatEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';

export interface ExportFormatModalProps {
open: boolean;
selectedFormat: GetAuditPlanSQLExportReqV1ExportFormatEnum;
onFormatChange: (format: GetAuditPlanSQLExportReqV1ExportFormatEnum) => void;
onConfirm: () => void;
onCancel: () => void;
}

const ExportFormatModal = ({
open,
selectedFormat,
onFormatChange,
onConfirm,
onCancel
}: ExportFormatModalProps) => {
const { t } = useTranslation();

return (
<BasicModal
title={t('sqlManagement.pageHeader.action.exportFormatModal.title')}
open={open}
onCancel={onCancel}
size="small"
footer={
<Space>
<BasicButton onClick={onCancel}>{t('common.cancel')}</BasicButton>
<BasicButton onClick={onConfirm} type="primary">
{t('common.ok')}
</BasicButton>
</Space>
}
>
<Radio.Group
value={selectedFormat}
onChange={(e) => onFormatChange(e.target.value)}
>
<Space direction="vertical">
<Radio value={GetAuditPlanSQLExportReqV1ExportFormatEnum.csv}>
CSV
</Radio>
<Radio value={GetAuditPlanSQLExportReqV1ExportFormatEnum.excel}>
Excel
</Radio>
</Space>
</Radio.Group>
</BasicModal>
);
};

export default ExportFormatModal;
Loading