diff --git a/src/hooks/useTable/index.test.ts b/src/hooks/useTable/index.test.ts index b816a168..3e11730b 100644 --- a/src/hooks/useTable/index.test.ts +++ b/src/hooks/useTable/index.test.ts @@ -114,7 +114,7 @@ describe('useTable', () => { {} as any ); }); - expect(result.current.pagination).toEqual({ pageIndex: 11, pageSize: 20 }); + expect(result.current.pagination).toEqual({ pageIndex: 11, pageSize: 10 }); act(() => { result.current.tableChange( @@ -125,7 +125,7 @@ describe('useTable', () => { ); }); expect(result.current.pagination).toEqual({ - pageIndex: 111, + pageIndex: 1, pageSize: 200, }); }); diff --git a/src/hooks/useTable/index.ts b/src/hooks/useTable/index.ts index ed8ad4c8..9393f877 100644 --- a/src/hooks/useTable/index.ts +++ b/src/hooks/useTable/index.ts @@ -4,6 +4,7 @@ import React, { useState } from 'react'; import { Dictionary } from '../../types/common.type'; import { TablePagination, UseTableOption } from './index.type'; import { SorterResult } from 'antd/lib/table/interface'; +import { isEqual } from 'lodash'; const useTable = (option?: UseTableOption) => { const { @@ -19,10 +20,26 @@ const useTable = (option?: UseTableOption) => { SorterResult | SorterResult[] >(); - const submitFilter = React.useCallback(() => { - const values = form.getFieldsValue(); - setFilterInfo(values); - }, [form]); + const [pagination, setPagination] = React.useState({ + pageIndex: defaultPageIndex, + pageSize: defaultPageSize, + }); + const [filterInfo, updateFilterInfo] = React.useState( + defaultFilterInfo as any + ); + + const setFilterInfo = React.useCallback((values: T) => { + if (!isEqual(values, filterInfo)) { + setPagination((prevPage) => { + return { + pageIndex: 1, + pageSize: prevPage.pageSize, + }; + }); + } + updateFilterInfo(values); + }, + [filterInfo]); /** * TODO: @@ -31,28 +48,32 @@ const useTable = (option?: UseTableOption) => { const resetFilter = React.useCallback(() => { form.resetFields(); setFilterInfo({} as any); - }, [form]); + }, [form, setFilterInfo]); - const [pagination, setPagination] = React.useState({ - pageIndex: defaultPageIndex, - pageSize: defaultPageSize, - }); - const [filterInfo, setFilterInfo] = React.useState( - defaultFilterInfo as any - ); + const submitFilter = React.useCallback(() => { + const values = form.getFieldsValue(); + setFilterInfo(values); + }, [form, setFilterInfo]); - const tableChange = React.useCallback>['onChange']>( + const tableChange = React.useCallback>["onChange"]>( (newPagination, _, sorter) => { setSorterInfo(sorter); + let paginationParams = { + pageIndex: defaultPageIndex, + pageSize: defaultPageSize, + }; + if (newPagination.pageSize && newPagination.pageSize !== pagination.pageSize) { + paginationParams.pageSize = newPagination.pageSize; + setPagination(paginationParams); + return; + } if ( - newPagination.current !== pagination.pageIndex || - newPagination.pageSize !== pagination.pageSize + newPagination.current && + newPagination.current !== pagination.pageIndex ) { - setPagination({ - pageIndex: newPagination.current ?? defaultPageIndex, - pageSize: newPagination.pageSize ?? defaultPageSize, - }); + paginationParams.pageIndex = newPagination.current; } + setPagination(paginationParams); }, // eslint-disable-next-line react-hooks/exhaustive-deps [pagination.pageIndex, pagination.pageSize] diff --git a/src/page/AuditPlan/PlanDetail/Detail/Report/index.tsx b/src/page/AuditPlan/PlanDetail/Detail/Report/index.tsx index 0246b682..c383ad40 100644 --- a/src/page/AuditPlan/PlanDetail/Detail/Report/index.tsx +++ b/src/page/AuditPlan/PlanDetail/Detail/Report/index.tsx @@ -85,17 +85,17 @@ const AuditPlanReport: React.FC = () => { - {t('auditPlan.report.time', { - time: formatTime(reportInfo?.audit_plan_report_timestamp, '--'), + {t("auditPlan.report.time", { + time: formatTime(reportInfo?.audit_plan_report_timestamp, "--"), })}   - {t('auditPlan.report.source', { - source: reportInfo?.score ?? '--', + {t("auditPlan.report.source", { + source: reportInfo?.score ?? "--", })}   - {t('auditPlan.report.passRage', { - rage: reportInfo?.pass_rate ?? '--', + {t("auditPlan.report.passRage", { + rage: reportInfo?.pass_rate ?? "--", })} @@ -106,7 +106,7 @@ const AuditPlanReport: React.FC = () => { onClick={exportReport} disabled={exportButtonDisabled} > - {t('auditPlan.report.export.buttonText')} + {t("auditPlan.report.export.buttonText")} } > @@ -117,7 +117,7 @@ const AuditPlanReport: React.FC = () => { columns={AuditPlanReportTableHeader(handleClickAnalyze)} pagination={{ showSizeChanger: true, - total: data?.total ?? 0, + total: data?.total ?? 0 }} onChange={tableChange} /> diff --git a/src/page/AuditPlan/PlanList/index.tsx b/src/page/AuditPlan/PlanList/index.tsx index 747824db..d19b58b9 100644 --- a/src/page/AuditPlan/PlanList/index.tsx +++ b/src/page/AuditPlan/PlanList/index.tsx @@ -133,7 +133,7 @@ const PlanList = () => { - {t('auditPlan.list.title')} + {t("auditPlan.list.title")} @@ -142,7 +142,7 @@ const PlanList = () => { extra={[ - + , ]} @@ -160,6 +160,7 @@ const PlanList = () => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} loading={loading} onChange={tableChange} diff --git a/src/page/DataSource/DataSourceList/index.tsx b/src/page/DataSource/DataSourceList/index.tsx index 612399cf..e24a4756 100644 --- a/src/page/DataSource/DataSourceList/index.tsx +++ b/src/page/DataSource/DataSourceList/index.tsx @@ -111,7 +111,7 @@ const DataSourceList = () => { - {t('dataSource.databaseListTitle')} + {t("dataSource.databaseListTitle")} @@ -120,7 +120,7 @@ const DataSourceList = () => { extra={ - + } @@ -142,6 +142,7 @@ const DataSourceList = () => { )} pagination={{ total: data?.total, + current: pagination.pageIndex, }} onChange={tableChange} /> diff --git a/src/page/Member/MemberGroupList/index.tsx b/src/page/Member/MemberGroupList/index.tsx index 9db73c5a..1aeae803 100644 --- a/src/page/Member/MemberGroupList/index.tsx +++ b/src/page/Member/MemberGroupList/index.tsx @@ -121,7 +121,7 @@ const UserGroupList: React.FC = () => { style={{ marginTop: theme.common.padding }} title={ - {t('member.memberGroupList.title')} + {t("member.memberGroupList.title")} @@ -133,7 +133,7 @@ const UserGroupList: React.FC = () => { key="create-user-group" > , ]} @@ -152,6 +152,7 @@ const UserGroupList: React.FC = () => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} onChange={tableChange} /> diff --git a/src/page/Member/MemberList/index.tsx b/src/page/Member/MemberList/index.tsx index be39d2c5..095c5bee 100644 --- a/src/page/Member/MemberList/index.tsx +++ b/src/page/Member/MemberList/index.tsx @@ -114,7 +114,7 @@ const MemberList: React.FC = () => { - {t('member.memberList.title')} + {t("member.memberList.title")} @@ -123,7 +123,7 @@ const MemberList: React.FC = () => { extra={[ , ]} @@ -142,6 +142,7 @@ const MemberList: React.FC = () => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} onChange={tableChange} /> diff --git a/src/page/OperationRecord/OperationRecordList/List.tsx b/src/page/OperationRecord/OperationRecordList/List.tsx index 1679dbed..2e3e7cdc 100644 --- a/src/page/OperationRecord/OperationRecordList/List.tsx +++ b/src/page/OperationRecord/OperationRecordList/List.tsx @@ -80,7 +80,7 @@ const OperationRecordList: React.FC = () => { - {t('operationRecord.list.title')} + {t("operationRecord.list.title")} @@ -93,7 +93,7 @@ const OperationRecordList: React.FC = () => { onClick={exportRecord} disabled={exportButtonEnableStatus} > - {t('operationRecord.list.exportButtonText')} + {t("operationRecord.list.exportButtonText")} , ]} > @@ -105,6 +105,7 @@ const OperationRecordList: React.FC = () => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} loading={loading} onChange={tableChange} diff --git a/src/page/Order/AuditResult/index.tsx b/src/page/Order/AuditResult/index.tsx index a30ed8b2..c7a1f51a 100644 --- a/src/page/Order/AuditResult/index.tsx +++ b/src/page/Order/AuditResult/index.tsx @@ -173,9 +173,10 @@ const AuditResult: React.FC = (props) => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} columns={ - mode === 'order' + mode === "order" ? orderAuditResultColumn(updateSqlDescribe, handleClickAnalyze) : AuditResultRecordColumn(updateSqlDescribe, handleClickAnalyze) } @@ -195,7 +196,7 @@ const AuditResult: React.FC = (props) => { ) : null, columnWidth: 14, }} - scroll={{ x: 'max-content' }} + scroll={{ x: "max-content" }} /> ); diff --git a/src/page/Order/List/index.tsx b/src/page/Order/List/index.tsx index 9e59d91f..72dd3837 100644 --- a/src/page/Order/List/index.tsx +++ b/src/page/Order/List/index.tsx @@ -352,6 +352,7 @@ const OrderList = () => { pagination={{ total: orderList?.total, showSizeChanger: true, + current: pagination.pageIndex, }} onChange={tableChange} onRow={(record) => ({ diff --git a/src/page/SQLManagement/SQLPanel/index.tsx b/src/page/SQLManagement/SQLPanel/index.tsx index af3c5190..76a5f11b 100644 --- a/src/page/SQLManagement/SQLPanel/index.tsx +++ b/src/page/SQLManagement/SQLPanel/index.tsx @@ -396,14 +396,14 @@ const SQLPanel: React.FC = () => { } type="primary" > - {t('sqlManagement.table.actions.batchAssignment')} + {t("sqlManagement.table.actions.batchAssignment")} @@ -413,13 +413,13 @@ const SQLPanel: React.FC = () => { } type="primary" > - {t('sqlManagement.table.actions.batchSolve')} + {t("sqlManagement.table.actions.batchSolve")} @@ -429,7 +429,7 @@ const SQLPanel: React.FC = () => { } type="primary" > - {t('sqlManagement.table.actions.batchIgnore')} + {t("sqlManagement.table.actions.batchIgnore")} @@ -440,7 +440,7 @@ const SQLPanel: React.FC = () => { onClick={exportAction} disabled={exportButtonDisabled} > - {t('sqlManagement.table.actions.export')} + {t("sqlManagement.table.actions.export")} @@ -465,6 +465,7 @@ const SQLPanel: React.FC = () => { pagination={{ showSizeChanger: true, total: data?.total ?? 0, + current: pagination.pageIndex, }} expandable={{ expandedRowRender, @@ -480,7 +481,7 @@ const SQLPanel: React.FC = () => { ) : null, columnWidth: 14, }} - scroll={{ x: 'max-content' }} + scroll={{ x: "max-content" }} /> diff --git a/src/page/SqlAuditRecord/List/index.tsx b/src/page/SqlAuditRecord/List/index.tsx index 70eedaa1..b6e7de2d 100644 --- a/src/page/SqlAuditRecord/List/index.tsx +++ b/src/page/SqlAuditRecord/List/index.tsx @@ -101,24 +101,24 @@ const SQLAuditList: React.FC = () => { return ( <> } > - {t('sqlAudit.list.pageDesc')} + {t("sqlAudit.list.pageDesc")}
- {t('sqlAudit.list.table.title')} + {t("sqlAudit.list.table.title")} @@ -144,9 +144,10 @@ const SQLAuditList: React.FC = () => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} scroll={{ - x: 'max-content', + x: "max-content", }} /> diff --git a/src/page/UserCenter/UserGroup/UserGroupList/index.tsx b/src/page/UserCenter/UserGroup/UserGroupList/index.tsx index 693696ff..2f055a91 100644 --- a/src/page/UserCenter/UserGroup/UserGroupList/index.tsx +++ b/src/page/UserCenter/UserGroup/UserGroupList/index.tsx @@ -111,7 +111,7 @@ const UserGroupList = () => { - {t('userGroup.userGroupList.title')} + {t("userGroup.userGroupList.title")} @@ -124,7 +124,7 @@ const UserGroupList = () => { icon={} onClick={addUserGroup} > - {t('userGroup.createUserGroup.title')} + {t("userGroup.createUserGroup.title")} , ]} > @@ -138,6 +138,7 @@ const UserGroupList = () => { pagination={{ total: data?.total, showSizeChanger: true, + current: pagination.pageIndex, }} />