Skip to content

Commit

Permalink
[feature]:(SQLManagement) Support for list sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
LZS911 committed Nov 8, 2023
1 parent 80d9869 commit 0d6a98a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 6 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'
}
8 changes: 7 additions & 1 deletion src/hooks/useTable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useForm } from 'antd/lib/form/Form';
import React, { useState } from 'react';
import { Dictionary } from '../../types/common.type';
import { TablePagination, UseTableOption } from './index.type';
import { SorterResult } from 'antd/lib/table/interface';

const useTable = <T = Dictionary>(option?: UseTableOption) => {
const {
Expand All @@ -14,6 +15,9 @@ const useTable = <T = Dictionary>(option?: UseTableOption) => {

const [form] = useForm<T>();
const [collapse, collapseChange] = useState(defaultFilterFormCollapse);
const [sorterInfo, setSorterInfo] = useState<
SorterResult<any> | SorterResult<any>[]
>();

const submitFilter = React.useCallback(() => {
const values = form.getFieldsValue();
Expand All @@ -38,7 +42,8 @@ const useTable = <T = Dictionary>(option?: UseTableOption) => {
);

const tableChange = React.useCallback<Required<TableProps<any>>['onChange']>(
(newPagination) => {
(newPagination, _, sorter) => {
setSorterInfo(sorter);
if (
newPagination.current !== pagination.pageIndex ||
newPagination.pageSize !== pagination.pageSize
Expand All @@ -64,6 +69,7 @@ const useTable = <T = Dictionary>(option?: UseTableOption) => {
submitFilter,
resetFilter,
tableChange,
sorterInfo,
};
};

Expand Down
3 changes: 3 additions & 0 deletions src/page/SQLManagement/SQLPanel/column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ export const SQLPanelColumns: (params: {
render: (time: string) => {
return formatTime(time, '--');
},
sorter: true,
},
{
dataIndex: 'last_appear_time',
title: () => t('sqlManagement.table.lastOccurrence'),
render: (time: string) => {
return formatTime(time, '--');
},
sorter: true,
},
{
dataIndex: 'appear_num',
title: () => t('sqlManagement.table.occurrenceCount'),
sorter: true,
},
{
dataIndex: 'assignees',
Expand Down
43 changes: 39 additions & 4 deletions src/page/SQLManagement/SQLPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { ResponseCode } from '../../../data/common';
import AssignMember from './AssignMember';
import {
GetSqlManageListFilterStatusEnum,
GetSqlManageListSortFieldEnum,
GetSqlManageListSortOrderEnum,
exportSqlManageV1FilterAuditLevelEnum,
exportSqlManageV1FilterSourceEnum,
exportSqlManageV1FilterStatusEnum,
Expand All @@ -44,9 +46,11 @@ const SQLPanel: React.FC = () => {
submitFilter,
tableChange,
resetFilter,
sorterInfo,
} = useTable<SQLPanelFilterFormFields>({
defaultFilterInfo,
});

const { projectName } = useCurrentProjectName();
const { username, isAdmin, isProjectManager } = useCurrentUser();
const [SQLNum, setSQLNum] = useState<SQLStatisticsProps>({
Expand Down Expand Up @@ -75,8 +79,36 @@ const SQLPanel: React.FC = () => {
};

const { data, loading, refresh } = useRequest(
() =>
SqlManage.GetSqlManageList({
() => {

Check warning on line 82 in src/page/SQLManagement/SQLPanel/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 getSortField = () => {

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

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
if (Array.isArray(sorterInfo)) {
return undefined;

Check warning on line 85 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 86 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 86 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 === 'first_appear_time') {
return GetSqlManageListSortFieldEnum.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;

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;

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 = () => {

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

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
if (Array.isArray(sorterInfo)) {
return undefined;

Check warning on line 100 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 101 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 101 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 === 'ascend') {
return GetSqlManageListSortOrderEnum.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;

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({
project_name: projectName,
page_index: pagination.pageIndex,
page_size: pagination.pageSize,
Expand All @@ -99,6 +131,8 @@ const SQLPanel: React.FC = () => {
filter_rule_name: filterInfo.filter_rule?.split(
DB_TYPE_RULE_NAME_SEPARATOR
)?.[1],
sort_field: getSortField(),
sort_order: getSortOrder(),
}).then((res) => {
setSQLNum({
SQLTotalNum: res.data?.sql_manage_total_num ?? 0,
Expand All @@ -109,9 +143,10 @@ const SQLPanel: React.FC = () => {
list: res.data?.data ?? [],
total: res.data?.sql_manage_total_num ?? 0,
};
}),
});

Check warning on line 146 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],
refreshDeps: [pagination, filterInfo, sorterInfo],
}
);

Check warning on line 151 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

Expand Down

0 comments on commit 0d6a98a

Please sign in to comment.