Skip to content

Commit

Permalink
[feature]: (Order) Support uploading sql zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
LZS911 committed Nov 9, 2023
1 parent 7fa7720 commit dac0f3e
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 17 deletions.
14 changes: 13 additions & 1 deletion src/api/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import {
GetSqlManageListFilterSourceEnum,
GetSqlManageListFilterAuditLevelEnum,
GetSqlManageListFilterStatusEnum,
GetSqlManageListSortFieldEnum,
GetSqlManageListSortOrderEnum,
exportSqlManageV1FilterSourceEnum,
exportSqlManageV1FilterAuditLevelEnum,
exportSqlManageV1FilterStatusEnum
exportSqlManageV1FilterStatusEnum,
exportSqlManageV1SortFieldEnum,
exportSqlManageV1SortOrderEnum
} from './index.enum';

import {
Expand Down Expand Up @@ -37,6 +41,10 @@ export interface IGetSqlManageListParams {

filter_db_type?: string;

sort_field?: GetSqlManageListSortFieldEnum;

sort_order?: GetSqlManageListSortOrderEnum;

page_index: number;

page_size: number;
Expand Down Expand Up @@ -72,6 +80,10 @@ export interface IExportSqlManageV1Params {
filter_db_type?: string;

filter_rule_name?: string;

sort_field?: exportSqlManageV1SortFieldEnum;

sort_order?: exportSqlManageV1SortOrderEnum;
}

export interface IGetSqlManageRuleTipsParams {
Expand Down
28 changes: 28 additions & 0 deletions src/api/SqlManage/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export enum GetSqlManageListFilterStatusEnum {
'manual_audited' = 'manual_audited'
}

export enum GetSqlManageListSortFieldEnum {
'first_appear_timestamp' = 'first_appear_timestamp',

'last_receive_timestamp' = 'last_receive_timestamp',

'fp_count' = 'fp_count'
}

export enum GetSqlManageListSortOrderEnum {
'asc' = 'asc',

'desc' = 'desc'
}

export enum exportSqlManageV1FilterSourceEnum {
'audit_plan' = 'audit_plan',

Expand All @@ -51,3 +65,17 @@ export enum exportSqlManageV1FilterStatusEnum {

'manual_audited' = 'manual_audited'
}

export enum exportSqlManageV1SortFieldEnum {
'first_appear_timestamp' = 'first_appear_timestamp',

'last_receive_timestamp' = 'last_receive_timestamp',

'fp_count' = 'fp_count'
}

export enum exportSqlManageV1SortOrderEnum {
'asc' = 'asc',

'desc' = 'desc'
}
4 changes: 4 additions & 0 deletions src/api/task/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface ICreateAndAuditTaskV1Params {
input_sql_file?: any;

input_mybatis_xml_file?: any;

input_zip_file?: any;
}

export interface ICreateAndAuditTaskV1Return extends IGetAuditTaskResV1 {}
Expand All @@ -52,6 +54,8 @@ export interface IAuditTaskGroupIdV1Params {
input_sql_file?: any;

input_mybatis_xml_file?: any;

input_zip_file?: any;
}

export interface IAuditTaskGroupIdV1Return extends IAuditTaskGroupResV1 {}
Expand Down
8 changes: 8 additions & 0 deletions src/api/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class TaskService extends ServiceBase {
);
}

if (params.input_zip_file != undefined) {
paramsData.append('input_zip_file', params.input_zip_file as any);
}

const project_name = params.project_name;

return this.post<ICreateAndAuditTaskV1Return>(
Expand Down Expand Up @@ -126,6 +130,10 @@ class TaskService extends ServiceBase {
);
}

if (params.input_zip_file != undefined) {
paramsData.append('input_zip_file', params.input_zip_file as any);
}

return this.post<IAuditTaskGroupIdV1Return>(
'/v1/task_groups/audit',
paramsData,
Expand Down
4 changes: 3 additions & 1 deletion src/locale/zh-CN/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ export default {
sql: 'SQL语句',
sqlFile: 'SQL文件',
mybatisFile: 'Mybatis的XML文件',
zipFile: 'ZIP文件',

addInstance: '添加数据源',

uploadType: '选择审核SQL语句上传方式',
manualInput: '输入SQL语句',
uploadFile: '上传SQL文件',
updateMybatisFile: '上传Mybatis的XML文件',
uploadMybatisFile: '上传Mybatis的XML文件',
uploadZipFile: '上传ZIP文件',

audit: '审核',
format: 'SQL美化',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,26 @@ exports[`order/create/sqlInfoForm should match snapshot 1`] = `
/>
</span>
<span>
order.sqlInfo.updateMybatisFile
order.sqlInfo.uploadMybatisFile
</span>
</label>
<label
class="ant-radio-wrapper ant-radio-wrapper-in-form-item"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="3"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
order.sqlInfo.uploadZipFile
</span>
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/page/Order/Create/SqlInfoForm/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ describe('order/create/sqlInfoForm', () => {
fireEvent.click(instance);
await act(async () => jest.advanceTimersByTime(3000));

fireEvent.click(screen.getByText('order.sqlInfo.updateMybatisFile'));
fireEvent.click(screen.getByText('order.sqlInfo.uploadMybatisFile'));

const mybatisFile = new File(
[
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('order/create/sqlInfoForm', () => {
fireEvent.click(screen.getByText('order.sqlInfo.format'));
expect(mockSqlFormatter).toBeCalledTimes(2);

fireEvent.click(screen.getByText('order.sqlInfo.updateMybatisFile'));
fireEvent.click(screen.getByText('order.sqlInfo.uploadMybatisFile'));
fireEvent.click(screen.getByText('order.sqlInfo.format'));
expect(mockSqlFormatter).toBeCalledTimes(2);

Expand Down
84 changes: 80 additions & 4 deletions src/page/Order/Create/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,26 @@ exports[`Order/Create should audit sql when user click audit button 1`] = `
/>
</span>
<span>
order.sqlInfo.updateMybatisFile
order.sqlInfo.uploadMybatisFile
</span>
</label>
<label
class="ant-radio-wrapper ant-radio-wrapper-in-form-item"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="3"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
order.sqlInfo.uploadZipFile
</span>
</label>
</div>
Expand Down Expand Up @@ -3445,7 +3464,26 @@ exports[`Order/Create should audit sql when user click audit button 2`] = `
/>
</span>
<span>
order.sqlInfo.updateMybatisFile
order.sqlInfo.uploadMybatisFile
</span>
</label>
<label
class="ant-radio-wrapper ant-radio-wrapper-in-form-item"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="3"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
order.sqlInfo.uploadZipFile
</span>
</label>
</div>
Expand Down Expand Up @@ -5123,7 +5161,26 @@ exports[`Order/Create should render page header 1`] = `
/>
</span>
<span>
order.sqlInfo.updateMybatisFile
order.sqlInfo.uploadMybatisFile
</span>
</label>
<label
class="ant-radio-wrapper ant-radio-wrapper-in-form-item"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="3"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
order.sqlInfo.uploadZipFile
</span>
</label>
</div>
Expand Down Expand Up @@ -5994,7 +6051,26 @@ exports[`Order/Create should render result modal when created order 1`] = `
/>
</span>
<span>
order.sqlInfo.updateMybatisFile
order.sqlInfo.uploadMybatisFile
</span>
</label>
<label
class="ant-radio-wrapper ant-radio-wrapper-in-form-item"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="3"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
order.sqlInfo.uploadZipFile
</span>
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ exports[`Order/Detail/Modal/ModifySqlModal should send sql file when user upload
order.sqlInfo.uploadFile
</span>
</label>
<label
class="ant-radio-wrapper ant-radio-wrapper-in-form-item"
>
<span
class="ant-radio"
>
<input
class="ant-radio-input"
type="radio"
value="3"
/>
<span
class="ant-radio-inner"
/>
</span>
<span>
order.sqlInfo.uploadZipFile
</span>
</label>
</div>
</div>
</div>
Expand Down
27 changes: 26 additions & 1 deletion src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
</Radio>
<EmptyBox if={!hideUpdateMybatisFile}>
<Radio value={SQLInputType.uploadMybatisFile}>
{t('order.sqlInfo.updateMybatisFile')}
{t('order.sqlInfo.uploadMybatisFile')}
</Radio>
</EmptyBox>
<Radio value={SQLInputType.zipFile}>
{t('order.sqlInfo.uploadZipFile')}
</Radio>
</Radio.Group>
</Form.Item>
<EmptyBox if={currentSQLInputType === SQLInputType.manualInput}>
Expand Down Expand Up @@ -158,6 +161,28 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
</Upload>
</Form.Item>
</EmptyBox>

<EmptyBox if={currentSQLInputType === SQLInputType.zipFile}>
<Form.Item
label={t('order.sqlInfo.zipFile')}
valuePropName="fileList"
name={generateFieldName('zipFile')}
rules={[
{
required: true,
},
]}
getValueFromEvent={getFileFromUploadChangeEvent}
>
<Upload
accept=".zip"
beforeUpload={() => false}

Check warning on line 179 in src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 179 in src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
onRemove={removeFile.bind(null, 'zipFile')}
>
<Button>{t('common.upload')}</Button>
</Upload>
</Form.Item>
</EmptyBox>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('test Order/SqlStatementForm', () => {
screen.queryByLabelText('order.sqlInfo.mybatisFile')
).not.toBeInTheDocument();

fireEvent.click(screen.getByLabelText('order.sqlInfo.updateMybatisFile'));
fireEvent.click(screen.getByLabelText('order.sqlInfo.uploadMybatisFile'));
expect(
screen.queryByLabelText('order.sqlInfo.sql')
).not.toBeInTheDocument();
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('test Order/SqlStatementForm', () => {
</Form>
);
expect(
screen.queryByLabelText('order.sqlInfo.updateMybatisFile')
screen.queryByLabelText('order.sqlInfo.uploadMybatisFile')
).not.toBeInTheDocument();
});

Expand Down Expand Up @@ -224,7 +224,7 @@ describe('test Order/SqlStatementForm', () => {
'0_sqlFile'
);

fireEvent.click(screen.getByLabelText('order.sqlInfo.updateMybatisFile'));
fireEvent.click(screen.getByLabelText('order.sqlInfo.uploadMybatisFile'));
expect(screen.getByLabelText('order.sqlInfo.mybatisFile')).toHaveAttribute(
'id',
'0_mybatisFile'
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('test Order/SqlStatementForm', () => {
'1_sqlFile'
);

fireEvent.click(screen.getByLabelText('order.sqlInfo.updateMybatisFile'));
fireEvent.click(screen.getByLabelText('order.sqlInfo.uploadMybatisFile'));
expect(screen.getByLabelText('order.sqlInfo.mybatisFile')).toHaveAttribute(
'id',
'1_mybatisFile'
Expand Down
Loading

0 comments on commit dac0f3e

Please sign in to comment.