Skip to content

Commit

Permalink
[feature]: Enable jumping to SQL review record list from SQL manageme…
Browse files Browse the repository at this point in the history
…nt module
  • Loading branch information
LZS911 committed Oct 9, 2023
1 parent a25877b commit 87d1946
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/api/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ export interface ISQLQueryConfigResV1 {
export interface ISource {
audit_plan_name?: string;

sql_audit_record_id?: string;
sql_audit_record_ids?: string[];

type?: SourceTypeEnum;
}
Expand Down
18 changes: 18 additions & 0 deletions src/api/rule_template/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ export interface IExportProjectRuleTemplateV1Params {
rule_template_name: string;
}

export interface IGetCustomRuleKnowledgeV1Params {
rule_name: string;

db_type: string;
}

export interface IGetCustomRuleKnowledgeV1Return
extends IGetRuleKnowledgeResV1 {}

export interface IUpdateCustomRuleKnowledgeParams
extends IUpdateRuleKnowledgeReq {
rule_name: string;

db_type: string;
}

export interface IUpdateCustomRuleKnowledgeReturn extends IBaseRes {}

export interface IGetRuleKnowledgeV1Params {
rule_name: string;

Expand Down
40 changes: 40 additions & 0 deletions src/api/rule_template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import {
ICloneProjectRuleTemplateV1Params,
ICloneProjectRuleTemplateV1Return,
IExportProjectRuleTemplateV1Params,
IGetCustomRuleKnowledgeV1Params,
IGetCustomRuleKnowledgeV1Return,
IUpdateCustomRuleKnowledgeParams,
IUpdateCustomRuleKnowledgeReturn,
IGetRuleKnowledgeV1Params,
IGetRuleKnowledgeV1Return,
IUpdateRuleKnowledgeParams,
Expand Down Expand Up @@ -279,6 +283,42 @@ class RuleTemplateService extends ServiceBase {
);
}

public getCustomRuleKnowledgeV1(
params: IGetCustomRuleKnowledgeV1Params,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const db_type = paramsData.db_type;
delete paramsData.db_type;

const rule_name = paramsData.rule_name;
delete paramsData.rule_name;

return this.get<IGetCustomRuleKnowledgeV1Return>(
`/v1/rule_knowledge/db_types/${db_type}/custom_rules/${rule_name}/`,
paramsData,
options
);
}

public updateCustomRuleKnowledge(
params: IUpdateCustomRuleKnowledgeParams,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const db_type = paramsData.db_type;
delete paramsData.db_type;

const rule_name = paramsData.rule_name;
delete paramsData.rule_name;

return this.patch<IUpdateCustomRuleKnowledgeReturn>(
`/v1/rule_knowledge/db_types/${db_type}/custom_rules/${rule_name}/`,
paramsData,
options
);
}

public getRuleKnowledgeV1(
params: IGetRuleKnowledgeV1Params,
options?: AxiosRequestConfig
Expand Down
2 changes: 2 additions & 0 deletions src/api/sql_audit_record/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface IGetSQLAuditRecordsV1Params {

filter_create_time_to?: string;

filter_sql_audit_record_ids?: string;

page_index: number;

page_size: number;
Expand Down
12 changes: 11 additions & 1 deletion src/page/SQLManagement/SQLPanel/column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import EditText from '../../../components/EditText/EditText';
import AssignMember from './AssignMember';
import EmptyBox from '../../../components/EmptyBox';
import UpdateSQLStatus from './UpdateSQLStatus';
import {
SQLAuditRecordIDValuesSplit,
SQLAuditRecordListUrlParamsKey,
} from '../../SqlAuditRecord/List/index.data';

export const SQLPanelColumns: (params: {
projectName: string;
Expand Down Expand Up @@ -80,7 +84,13 @@ export const SQLPanelColumns: (params: {
) {
return (
<Link
to={`project/${projectName}/sqlAudit/${source.sql_audit_record_id}/detail`}
to={`project/${projectName}/sqlAudit?${
SQLAuditRecordListUrlParamsKey.SQLAuditRecordID
}=${
source.sql_audit_record_ids?.join(
SQLAuditRecordIDValuesSplit
) ?? ''

Check warning on line 92 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 92 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
}`}
>
{t(sourceDictionary[source.type])}
</Link>
Expand Down
5 changes: 5 additions & 0 deletions src/page/SqlAuditRecord/List/index.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const SQLAuditRecordListUrlParamsKey = {
SQLAuditRecordID: 'SQLAuditRecordID',
};

Check warning on line 3 in src/page/SqlAuditRecord/List/index.data.ts

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

export const SQLAuditRecordIDValuesSplit = ',';

Check warning on line 5 in src/page/SqlAuditRecord/List/index.data.ts

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
24 changes: 23 additions & 1 deletion src/page/SqlAuditRecord/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import { useTheme } from '@mui/styles';
import { SQLAuditListColumn } from './column';
import sql_audit_record from '../../../api/sql_audit_record';
import { translateTimeForRequest } from '../../../utils/Common';
import { useCallback } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { ResponseCode } from '../../../data/common';

import './index.less';
import { useLocation } from 'react-router-dom';
import { SQLAuditRecordListUrlParamsKey } from './index.data';

const SQLAuditList: React.FC = () => {
const { t } = useTranslation();
const { projectName } = useCurrentProjectName();
const theme = useTheme<Theme>();
const location = useLocation();

Check warning on line 26 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const [resolveUrlParamFlag, setResolveUrlParamFlag] = useState(false);

Check warning on line 27 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

const {
pagination,
Expand All @@ -29,6 +33,7 @@ const SQLAuditList: React.FC = () => {
resetFilter,
submitFilter,
tableChange,
setFilterInfo,
} = useTable<SQLAuditListFilterFormFields>();

const { data, refresh, loading } = useRequest(
Expand All @@ -47,6 +52,7 @@ const SQLAuditList: React.FC = () => {
filter_create_time_to: translateTimeForRequest(
filterInfo.filter_create_time?.[1]
),
filter_sql_audit_record_ids: filterInfo.filter_sql_audit_record_ids,
})
.then((res) => {
return {
Expand All @@ -55,6 +61,7 @@ const SQLAuditList: React.FC = () => {
};
}),

Check warning on line 62 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
{
ready: resolveUrlParamFlag,
refreshDeps: [pagination, filterInfo, projectName],
}
);

Check warning on line 67 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
Expand All @@ -76,6 +83,21 @@ const SQLAuditList: React.FC = () => {
},
[projectName, refresh, t]
);

useEffect(() => {

Check warning on line 87 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
const searchStr = new URLSearchParams(location.search);

Check warning on line 88 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const filter: SQLAuditListFilterFormFields = {};

Check warning on line 89 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
if (searchStr.has(SQLAuditRecordListUrlParamsKey.SQLAuditRecordID)) {
filter.filter_sql_audit_record_ids = searchStr.get(
SQLAuditRecordListUrlParamsKey.SQLAuditRecordID
) as string;

Check warning on line 93 in src/page/SqlAuditRecord/List/index.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 94 in src/page/SqlAuditRecord/List/index.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 94 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
if (Object.keys(filter).length > 0) {
setFilterInfo(filter);

Check warning on line 96 in src/page/SqlAuditRecord/List/index.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 97 in src/page/SqlAuditRecord/List/index.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 97 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
setResolveUrlParamFlag(true);

Check warning on line 98 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
}, [filterForm, location.search, setFilterInfo]);

Check warning on line 99 in src/page/SqlAuditRecord/List/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

return (
<>
<PageHeader
Expand Down
17 changes: 10 additions & 7 deletions src/page/SqlAuditRecord/List/index.type.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { FormInstance } from 'antd';
import { getSQLAuditRecordsV1FilterSqlAuditStatusEnum } from '../../../api/sql_audit_record/index.enum';
import { IGetSQLAuditRecordsV1Params } from '../../../api/sql_audit_record/index.d';

//todo
export type SQLAuditListFilterFormFields = {
fuzzy_search_tags: string;
filter_sql_audit_status: getSQLAuditRecordsV1FilterSqlAuditStatusEnum;
filter_instance_name: string;
filter_create_time: moment.Moment[];
export type SQLAuditListFilterFormFields = Omit<
IGetSQLAuditRecordsV1Params,
| 'page_index'
| 'page_size'
| 'project_name'
| 'filter_create_time_to'
| 'filter_create_time_from'
> & {
filter_create_time?: moment.Moment[];
};

export type SQLAuditListFilterFormProps = {
Expand Down

0 comments on commit 87d1946

Please sign in to comment.