Skip to content

Commit

Permalink
[feature]: (SQLManagement) Support list filtering based on rules
Browse files Browse the repository at this point in the history
  • Loading branch information
LZS911 committed Nov 2, 2023
1 parent 0d3caf7 commit 754bf98
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 17 deletions.
18 changes: 17 additions & 1 deletion src/api/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import {
IGetSqlManageListResp,
IBatchUpdateSqlManageReq,
IBaseRes
IBaseRes,
IGetSqlManageRuleTipsResp
} from '../common.d';

export interface IGetSqlManageListParams {
Expand All @@ -32,6 +33,10 @@ export interface IGetSqlManageListParams {

filter_status?: GetSqlManageListFilterStatusEnum;

filter_rule_name?: string;

filter_db_type?: string;

page_index: number;

page_size: number;
Expand Down Expand Up @@ -63,4 +68,15 @@ export interface IExportSqlManageV1Params {
filter_last_audit_start_time_to?: string;

filter_status?: exportSqlManageV1FilterStatusEnum;

filter_db_type?: string;

filter_rule_name?: string;
}

export interface IGetSqlManageRuleTipsParams {
project_name: string;
}

export interface IGetSqlManageRuleTipsReturn
extends IGetSqlManageRuleTipsResp {}
19 changes: 18 additions & 1 deletion src/api/SqlManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
IGetSqlManageListReturn,
IBatchUpdateSqlManageParams,
IBatchUpdateSqlManageReturn,
IExportSqlManageV1Params
IExportSqlManageV1Params,
IGetSqlManageRuleTipsParams,
IGetSqlManageRuleTipsReturn
} from './index.d';

class SqlManageService extends ServiceBase {
Expand Down Expand Up @@ -59,6 +61,21 @@ class SqlManageService extends ServiceBase {
options
);
}

public GetSqlManageRuleTips(
params: IGetSqlManageRuleTipsParams,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const project_name = paramsData.project_name;
delete paramsData.project_name;

return this.get<IGetSqlManageRuleTipsReturn>(
`/v1/projects/${project_name}/sql_manages/rule_tips`,
paramsData,
options
);
}
}

export default new SqlManageService();
35 changes: 35 additions & 0 deletions src/api/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
WorkflowStepResV1TypeEnum,
WorkflowTemplateDetailResV1AllowSubmitWhenLessAuditLevelEnum,
AuditResDataV2AuditLevelEnum,
DirectAuditFileReqV2SqlTypeEnum,
DirectAuditReqV2SqlTypeEnum,
GetWorkflowTasksItemV2StatusEnum,
WorkflowRecordResV2StatusEnum,
Expand Down Expand Up @@ -1362,6 +1363,14 @@ export interface IGetSqlManageListResp {
sql_manage_total_num?: number;
}

export interface IGetSqlManageRuleTipsResp {
code?: number;

data?: IRuleTips[];

message?: string;
}

export interface IGetSyncInstanceTaskListResV1 {
code?: number;

Expand Down Expand Up @@ -2142,6 +2151,12 @@ export interface IRuleResV1 {
type?: string;
}

export interface IRuleRespV1 {
desc?: string;

rule_name?: string;
}

export interface IRuleTemplateDetailResV1 {
db_type?: string;

Expand Down Expand Up @@ -2170,6 +2185,12 @@ export interface IRuleTemplateTipResV1 {
rule_template_name?: string;
}

export interface IRuleTips {
db_type?: string;

rule?: IRuleRespV1[];
}

export interface IRuleTypeV1 {
is_custom_rule_type?: boolean;

Expand Down Expand Up @@ -3176,6 +3197,20 @@ export interface ICreateWorkflowResV2Data {
workflow_id?: string;
}

export interface IDirectAuditFileReqV2 {
file_contents?: string[];

instance_name?: string;

instance_type?: string;

project_name?: string;

schema_name?: string;

sql_type?: DirectAuditFileReqV2SqlTypeEnum;
}

export interface IDirectAuditReqV2 {
instance_type?: string;

Expand Down
8 changes: 8 additions & 0 deletions src/api/common.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ export enum AuditResDataV2AuditLevelEnum {
'UNKNOWN' = ''
}

export enum DirectAuditFileReqV2SqlTypeEnum {
'sql' = 'sql',

'mybatis' = 'mybatis',

'UNKNOWN' = ''
}

export enum DirectAuditReqV2SqlTypeEnum {
'sql' = 'sql',

Expand Down
9 changes: 7 additions & 2 deletions src/api/sql_audit/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
IDirectAuditFileReqV1,
IDirectAuditResV1,
IDirectAuditReqV1,
IDirectAuditReqV2,
IDirectAuditResV2
IDirectAuditFileReqV2,
IDirectAuditResV2,
IDirectAuditReqV2
} from '../common.d';

export interface IDirectAuditFilesV1Params extends IDirectAuditFileReqV1 {}
Expand All @@ -14,6 +15,10 @@ export interface IDirectAuditV1Params extends IDirectAuditReqV1 {}

export interface IDirectAuditV1Return extends IDirectAuditResV1 {}

export interface IDirectAuditFilesV2Params extends IDirectAuditFileReqV2 {}

export interface IDirectAuditFilesV2Return extends IDirectAuditResV2 {}

export interface IDirectAuditV2Params extends IDirectAuditReqV2 {}

export interface IDirectAuditV2Return extends IDirectAuditResV2 {}
14 changes: 14 additions & 0 deletions src/api/sql_audit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
IDirectAuditFilesV1Return,
IDirectAuditV1Params,
IDirectAuditV1Return,
IDirectAuditFilesV2Params,
IDirectAuditFilesV2Return,
IDirectAuditV2Params,
IDirectAuditV2Return
} from './index.d';
Expand Down Expand Up @@ -40,6 +42,18 @@ class SqlAuditService extends ServiceBase {
);
}

public directAuditFilesV2(
params: IDirectAuditFilesV2Params,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
return this.post<IDirectAuditFilesV2Return>(
'/v2/audit_files',
paramsData,
options
);
}

public directAuditV2(
params: IDirectAuditV2Params,
options?: AxiosRequestConfig
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-CN/sqlManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default {
status: '状态',
relatedToMe: '与我相关',
time: '时间范围',
rule: '审核规则',
},

table: {
Expand Down
74 changes: 61 additions & 13 deletions src/page/SQLManagement/SQLPanel/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Input,
Row,
Select,
SelectProps,
Space,
Switch,
} from 'antd';
Expand All @@ -14,17 +15,15 @@ import {
SQLPanelFilterFormProps,
} from './index.type';
import { useTranslation } from 'react-i18next';
import {
FilterFormColLayout,
FilterFormRowLayout,
filterFormButtonLayoutFactory,
} from '../../../data/common';
import { FilterFormColLayout, FilterFormRowLayout } from '../../../data/common';
import useInstance from '../../../hooks/useInstance';
import { useEffect } from 'react';
import moment from 'moment';
import useStaticStatus from './hooks/useStaticStatus';
import { getInstanceTipListV1FunctionalModuleEnum } from '../../../api/instance/index.enum';
import { GetSqlManageListFilterStatusEnum } from '../../../api/SqlManage/index.enum';
import useRuleTips from './hooks/useRuleTips';
import { extractTextFromReactNode } from '../../../utils/Common';

const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
form,
Expand All @@ -33,7 +32,16 @@ const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
projectName,
}) => {
const { t } = useTranslation();
const { generateInstanceSelectOption, updateInstanceList } = useInstance();
const {
generateInstanceSelectOption,
updateInstanceList,
loading: getInstanceListLoading,
} = useInstance();
const {
generateRuleTipsSelectOptions,
updateRuleTips,
loading: getRuleTipsLoading,
} = useRuleTips();
const {
generateSourceSelectOptions,
generateAuditLevelSelectOptions,
Expand All @@ -42,6 +50,15 @@ const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
const computeDisabledDate = (current: moment.Moment) => {
return current && current > moment().endOf('day');
};

const ruleTipsFilterOptions: SelectProps['filterOption'] = (
inputValue,
option
) => {
const label = extractTextFromReactNode(option?.label);
return label.toLowerCase().includes(inputValue.toLowerCase());
};

useEffect(() => {
form.setFieldValue(
'filter_status',
Expand All @@ -51,7 +68,8 @@ const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
project_name: projectName,
functional_module: getInstanceTipListV1FunctionalModuleEnum.sql_manage,
});
}, [form, projectName, updateInstanceList]);
updateRuleTips(projectName);
}, [form, projectName, updateInstanceList, updateRuleTips]);
return (
<Form<SQLPanelFilterFormFields> form={form} onFinish={submit}>
<Row {...FilterFormRowLayout}>
Expand Down Expand Up @@ -86,6 +104,7 @@ const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
name="filter_instance_name"
>
<Select
loading={getInstanceListLoading}
placeholder={t('common.form.placeholder.searchSelect', {
name: t('sqlManagement.filterForm.instanceName'),
})}
Expand Down Expand Up @@ -134,18 +153,47 @@ const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
</Col>
<Col {...FilterFormColLayout}>
<Form.Item
label={t('sqlManagement.filterForm.relatedToMe')}
name="filter_assignee"
name="filter_rule"
label={t('sqlManagement.filterForm.rule')}
>
<Switch />
<Select
filterOption={ruleTipsFilterOptions}
optionFilterProp="children"
loading={getRuleTipsLoading}
showSearch
>
{generateRuleTipsSelectOptions()}
</Select>
</Form.Item>
</Col>

<Col
{...filterFormButtonLayoutFactory(0, 8, 0)}
className="text-align-right"
{...{
xs: 24,
sm: {
span: 12,
offset: 0,
},
xl: {
span: 16,
offset: 0,
},
xxl: {
span: 6,
offset: 0,
},
}}
className="flex-space-between"
>
<Form.Item className="clear-margin-right" wrapperCol={{ span: 24 }}>
<Form.Item
label={t('sqlManagement.filterForm.relatedToMe')}
name="filter_assignee"
valuePropName="checked"
>
<Switch />
</Form.Item>

<Form.Item className="clear-margin-right" label=" " colon={false}>
<Space>
<Button onClick={reset}>{t('common.reset')}</Button>
<Button type="primary" htmlType="submit">
Expand Down
Loading

0 comments on commit 754bf98

Please sign in to comment.