Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: endpoint information adjustment #346

Closed
wants to merge 2 commits into from
Closed
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
43 changes: 42 additions & 1 deletion src/api/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
exportSqlManageV1FilterAuditLevelEnum,
exportSqlManageV1FilterStatusEnum,
exportSqlManageV1SortFieldEnum,
exportSqlManageV1SortOrderEnum
exportSqlManageV1SortOrderEnum,
GetSqlManageListV2FilterSourceEnum,
GetSqlManageListV2FilterAuditLevelEnum,
GetSqlManageListV2FilterStatusEnum,
GetSqlManageListV2SortFieldEnum,
GetSqlManageListV2SortOrderEnum
} from './index.enum';

import {
Expand Down Expand Up @@ -96,3 +101,39 @@ export interface IGetSqlManageRuleTipsParams {

export interface IGetSqlManageRuleTipsReturn
extends IGetSqlManageRuleTipsResp {}

export interface IGetSqlManageListV2Params {
project_name: string;

fuzzy_search_sql_fingerprint?: string;

filter_assignee?: string;

filter_instance_name?: string;

filter_source?: GetSqlManageListV2FilterSourceEnum;

filter_audit_level?: GetSqlManageListV2FilterAuditLevelEnum;

filter_last_audit_start_time_from?: string;

filter_last_audit_start_time_to?: string;

filter_status?: GetSqlManageListV2FilterStatusEnum;

filter_rule_name?: string;

filter_db_type?: string;

fuzzy_search_endpoint?: string;

sort_field?: GetSqlManageListV2SortFieldEnum;

sort_order?: GetSqlManageListV2SortOrderEnum;

page_index: number;

page_size: number;
}

export interface IGetSqlManageListV2Return extends IGetSqlManageListResp {}
40 changes: 40 additions & 0 deletions src/api/SqlManage/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,43 @@ export enum exportSqlManageV1SortOrderEnum {

'desc' = 'desc'
}

export enum GetSqlManageListV2FilterSourceEnum {
'audit_plan' = 'audit_plan',

'sql_audit_record' = 'sql_audit_record'
}

export enum GetSqlManageListV2FilterAuditLevelEnum {
'normal' = 'normal',

'notice' = 'notice',

'warn' = 'warn',

'error' = 'error'
}

export enum GetSqlManageListV2FilterStatusEnum {
'unhandled' = 'unhandled',

'solved' = 'solved',

'ignored' = 'ignored',

'manual_audited' = 'manual_audited'
}

export enum GetSqlManageListV2SortFieldEnum {
'first_appear_timestamp' = 'first_appear_timestamp',

'last_receive_timestamp' = 'last_receive_timestamp',

'fp_count' = 'fp_count'
}

export enum GetSqlManageListV2SortOrderEnum {
'asc' = 'asc',

'desc' = 'desc'
}
19 changes: 18 additions & 1 deletion src/api/SqlManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
IBatchUpdateSqlManageReturn,
IExportSqlManageV1Params,
IGetSqlManageRuleTipsParams,
IGetSqlManageRuleTipsReturn
IGetSqlManageRuleTipsReturn,
IGetSqlManageListV2Params,
IGetSqlManageListV2Return,
} from './index.d';

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

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

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

export default new SqlManageService();
10 changes: 5 additions & 5 deletions src/api/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2312,21 +2312,21 @@ export interface ISqlExecutionFailPercent {
}

export interface ISqlManage {
appear_num?: number;

assignees?: string[];

audit_result?: IAuditResult[];

endpoint?: string;
endpoints?: string[];

first_appear_timestamp?: string;

first_appear_time?: string;
fp_count?: number;

id?: number;

instance_name?: string;

last_appear_time?: string;
last_receive_timestamp?: string;

remark?: string;

Expand Down
4 changes: 2 additions & 2 deletions src/page/SQLManagement/SQLPanel/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@
import moment from 'moment';
import useStaticStatus from './hooks/useStaticStatus';
import { getInstanceTipListV1FunctionalModuleEnum } from '../../../api/instance/index.enum';
import { GetSqlManageListFilterStatusEnum } from '../../../api/SqlManage/index.enum';
import { GetSqlManageListV2FilterStatusEnum } from '../../../api/SqlManage/index.enum';
import useRuleTips from './hooks/useRuleTips';
import { extractTextFromReactNode } from '../../../utils/Common';

const FilterForm: React.FC<SQLPanelFilterFormProps> = ({
form,
reset,
submit,
projectName,
}) => {
const { t } = useTranslation();
const {
generateInstanceSelectOption,
updateInstanceList,
loading: getInstanceListLoading,
} = useInstance();
const {
generateRuleTipsSelectOptions,
updateRuleTips,
loading: getRuleTipsLoading,
} = useRuleTips();
const {
generateSourceSelectOptions,
generateAuditLevelSelectOptions,
generateStatusSelectOptions,
} = useStaticStatus();
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',
GetSqlManageListFilterStatusEnum.unhandled
GetSqlManageListV2FilterStatusEnum.unhandled
);

Check warning on line 66 in src/page/SQLManagement/SQLPanel/FilterForm.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
updateInstanceList({
project_name: projectName,
functional_module: getInstanceTipListV1FunctionalModuleEnum.sql_manage,
Expand Down
33 changes: 28 additions & 5 deletions src/page/SQLManagement/SQLPanel/column.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Space, Table, Tag, TagProps, Typography } from 'antd';
import { Space, Table, Tag, TagProps, Typography, Popover } from 'antd';
import { GetSqlManageListFilterStatusEnum } from '../../../api/SqlManage/index.enum';
import { IAuditResult, ISource, ISqlManage } from '../../../api/common';
import { t } from '../../../locale';
Expand Down Expand Up @@ -53,115 +53,138 @@
| (ColumnGroupType<ISqlManage> | ColumnType<ISqlManage>) & {
dataIndex?: keyof ISqlManage | 'operator';
}
> = ({
projectName,
updateRemark,
signalActionsLoading,
signalAssignment,
actionPermission,
username,
updateSQLStatus,
}) => {
const columns: Array<
| (ColumnGroupType<ISqlManage> | ColumnType<ISqlManage>) & {
dataIndex?: keyof ISqlManage | 'operator';
}
> = [
{
dataIndex: 'sql_fingerprint',
title: () => t('sqlManagement.table.SQLFingerprint'),
className: 'table-column-sql-fingerprint',
render: (sql: string) => <RenderExecuteSql sql={sql} rows={2} />,
},
{
dataIndex: 'sql',
title: () => 'SQL',
className: 'table-column-sql',
render: (sql: string) => <RenderExecuteSql sql={sql} rows={2} />,
},
{
dataIndex: 'source',
title: () => t('sqlManagement.table.source'),
render: (source: ISource) => {
if (source.type && source.type === SourceTypeEnum.audit_plan) {
return (
<Link
to={`project/${projectName}/auditPlan/detail/${source.audit_plan_name}`}
>
{t(sourceDictionary[source.type])}
</Link>
);
} else if (
source.type &&
source.type === SourceTypeEnum.sql_audit_record
) {
return (
<Link
to={`project/${projectName}/sqlAudit?${
SQLAuditRecordListUrlParamsKey.SQLAuditRecordID
}=${
source.sql_audit_record_ids?.join(
SQLAuditRecordIDValuesSplit
) ?? ''
}`}
>
{t(sourceDictionary[source.type])}
</Link>
);
}
return '--';
},
},
{
dataIndex: 'instance_name',
title: () => t('sqlManagement.table.instanceName'),
},
{
dataIndex: 'audit_result',
title: () => t('sqlManagement.table.auditResult'),
render: (auditResult: IAuditResult[]) => {
return <AuditResultInfo auditResult={auditResult} />;
},
},
Table.EXPAND_COLUMN,
{
dataIndex: 'first_appear_time',
dataIndex: 'first_appear_timestamp',
title: () => t('sqlManagement.table.firstOccurrence'),
render: (time: string) => {
return formatTime(time, '--');
},
sorter: true,
sortDirections: ['descend', 'ascend'],
},
{
dataIndex: 'last_appear_time',
dataIndex: 'last_receive_timestamp',
title: () => t('sqlManagement.table.lastOccurrence'),
render: (time: string) => {
return formatTime(time, '--');
},
sorter: true,
sortDirections: ['descend', 'ascend'],
},
{
dataIndex: 'appear_num',
dataIndex: 'fp_count',
title: () => t('sqlManagement.table.occurrenceCount'),
sorter: true,
sortDirections: ['descend', 'ascend'],
},

{
dataIndex: 'assignees',
title: () => t('sqlManagement.table.personInCharge'),
render: (assignees: string[]) => {
if (!Array.isArray(assignees)) {
return '--';
}
return assignees.map((v) => <Tag key={v}>{v}</Tag>);
},
},
{
dataIndex: 'endpoint',
dataIndex: 'endpoints',
title: () => t('sqlManagement.table.endpoint'),
render: (endpoints: string[]) => {
if (!Array.isArray(endpoints) || endpoints.length === 0) {
return '--';
}
if (endpoints.length === 1) {
return <Tag>{endpoints[0]}</Tag>;

}
return (
<Popover content={
<div style={{ maxWidth: '600px' }}>
<Space wrap>{
endpoints.map((v) => (
<Tag key={v}>{v}</Tag>
))
}</Space>
</div>
}>
<Tag>{endpoints[0]}</Tag>
{endpoints.length > 1 ? '...' : null}
</Popover >
)

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

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
}
},
{
dataIndex: 'status',
Expand Down
16 changes: 8 additions & 8 deletions src/page/SQLManagement/SQLPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import AssignMember from './AssignMember';
import {
GetSqlManageListFilterStatusEnum,
GetSqlManageListSortFieldEnum,
GetSqlManageListSortOrderEnum,
GetSqlManageListV2SortFieldEnum,
GetSqlManageListV2SortOrderEnum,
exportSqlManageV1FilterAuditLevelEnum,
exportSqlManageV1FilterSourceEnum,
exportSqlManageV1FilterStatusEnum,
Expand All @@ -37,114 +37,114 @@
filter_status: GetSqlManageListFilterStatusEnum.unhandled,
};

const SQLPanel: React.FC = () => {
const { t } = useTranslation();
const {
pagination,
filterForm,
filterInfo,
submitFilter,
tableChange,
resetFilter,
sorterInfo,
} = useTable<SQLPanelFilterFormFields>({
defaultFilterInfo,
});

const { projectName } = useCurrentProjectName();
const { username, isAdmin, isProjectManager } = useCurrentUser();
const [SQLNum, setSQLNum] = useState<SQLStatisticsProps>({
SQLTotalNum: 0,
problemSQlNum: 0,
optimizedSQLNum: 0,
});
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
const actionPermission = useMemo(() => {
return isAdmin || isProjectManager(projectName);
}, [isAdmin, isProjectManager, projectName]);
const [
batchActionsLoading,
{ setFalse: finishBatchAction, setTrue: startBatchAction },
] = useBoolean();
const [
signalActionsLoading,
{ setFalse: finishSignalAction, setTrue: startSignalAction },
] = useBoolean();

const rowSelection: TableRowSelection<ISqlManage> = {
selectedRowKeys,
onChange: (selectedRowKeys) => {
setSelectedRowKeys(selectedRowKeys as number[]);
},
};

const { data, loading, refresh } = useRequest(
() => {
const getSortField = () => {
if (Array.isArray(sorterInfo)) {
return undefined;
}

if (sorterInfo?.field === 'first_appear_time') {
return GetSqlManageListSortFieldEnum.first_appear_timestamp;
return GetSqlManageListV2SortFieldEnum.first_appear_timestamp;

Check warning on line 89 in src/page/SQLManagement/SQLPanel/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 90 in src/page/SQLManagement/SQLPanel/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 90 in src/page/SQLManagement/SQLPanel/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 (sorterInfo?.field === 'last_appear_time') {
return GetSqlManageListSortFieldEnum.last_receive_timestamp;
return GetSqlManageListV2SortFieldEnum.last_receive_timestamp;

Check warning on line 92 in src/page/SQLManagement/SQLPanel/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 93 in src/page/SQLManagement/SQLPanel/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 93 in src/page/SQLManagement/SQLPanel/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 (sorterInfo?.field === 'appear_num') {
return GetSqlManageListSortFieldEnum.fp_count;
return GetSqlManageListV2SortFieldEnum.fp_count;

Check warning on line 95 in src/page/SQLManagement/SQLPanel/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 96 in src/page/SQLManagement/SQLPanel/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 96 in src/page/SQLManagement/SQLPanel/index.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 97 in src/page/SQLManagement/SQLPanel/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 getSortOrder = () => {
if (Array.isArray(sorterInfo)) {
return undefined;
}

if (sorterInfo?.order === 'ascend') {
return GetSqlManageListSortOrderEnum.asc;
return GetSqlManageListV2SortOrderEnum.asc;

Check warning on line 104 in src/page/SQLManagement/SQLPanel/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 105 in src/page/SQLManagement/SQLPanel/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 105 in src/page/SQLManagement/SQLPanel/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 (sorterInfo?.order === 'descend') {
return GetSqlManageListSortOrderEnum.desc;
return GetSqlManageListV2SortOrderEnum.desc;

Check warning on line 108 in src/page/SQLManagement/SQLPanel/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 109 in src/page/SQLManagement/SQLPanel/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 109 in src/page/SQLManagement/SQLPanel/index.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 110 in src/page/SQLManagement/SQLPanel/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 SqlManage.GetSqlManageList({
return SqlManage.GetSqlManageListV2({
project_name: projectName,
page_index: pagination.pageIndex,
page_size: pagination.pageSize,
filter_assignee: !!filterInfo.filter_assignee ? username : undefined,
filter_last_audit_start_time_from: translateTimeForRequest(
filterInfo.filter_last_audit_time?.[0]
),
filter_last_audit_start_time_to: translateTimeForRequest(
filterInfo.filter_last_audit_time?.[1]
),

fuzzy_search_sql_fingerprint: filterInfo.fuzzy_search_sql_fingerprint,
filter_instance_name: filterInfo.filter_instance_name,
filter_status: filterInfo.filter_status,
filter_source: filterInfo.filter_source,
filter_audit_level: filterInfo.filter_audit_level,
filter_db_type: filterInfo.filter_rule?.split(
DB_TYPE_RULE_NAME_SEPARATOR
)?.[0],
filter_rule_name: filterInfo.filter_rule?.split(
DB_TYPE_RULE_NAME_SEPARATOR
)?.[1],
fuzzy_search_endpoint: filterInfo.fuzzy_search_endpoint,
sort_field: getSortField(),
sort_order: getSortOrder(),
}).then((res) => {
setSQLNum({
SQLTotalNum: res.data?.sql_manage_total_num ?? 0,
problemSQlNum: res.data?.sql_manage_bad_num ?? 0,
optimizedSQLNum: res.data?.sql_manage_optimized_num ?? 0,
});
return {
list: res.data?.data ?? [],
total: res.data?.sql_manage_total_num ?? 0,
};
});

Check warning on line 147 in src/page/SQLManagement/SQLPanel/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
},
{
refreshDeps: [pagination, filterInfo, sorterInfo],
Expand Down
12 changes: 6 additions & 6 deletions src/page/SQLManagement/SQLPanel/index.type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FormInstance } from 'antd';
import {
GetSqlManageListFilterAuditLevelEnum,
GetSqlManageListFilterSourceEnum,
GetSqlManageListFilterStatusEnum,
GetSqlManageListV2FilterSourceEnum,
GetSqlManageListV2FilterAuditLevelEnum,
GetSqlManageListV2FilterStatusEnum,
} from '../../../api/SqlManage/index.enum';

export type SQLPanelFilterFormFields = {
Expand All @@ -12,13 +12,13 @@ export type SQLPanelFilterFormFields = {

filter_instance_name?: string;

filter_source?: GetSqlManageListFilterSourceEnum;
filter_source?: GetSqlManageListV2FilterSourceEnum;

filter_audit_level?: GetSqlManageListFilterAuditLevelEnum;
filter_audit_level?: GetSqlManageListV2FilterAuditLevelEnum;

filter_last_audit_time?: moment.Moment[];

filter_status?: GetSqlManageListFilterStatusEnum;
filter_status?: GetSqlManageListV2FilterStatusEnum;

filter_rule?: string;

Expand Down