feat(list): persist page in URL and reset to 1 on save/group switch - #2257
Conversation
Move list pagination from sessionStorage to URL ?page=N across list pages. Reset to page 1 after create/edit/batch ops and on business-group switch (via a groupSwitchCount counter). Clear row selection on group switch to prevent stale cross-group IDs reaching batch operations. Add urlPage util (getPageFromSearch/setPageInSearch/removePageFromSearch) with unit tests. Note: task/taskTpl tables drop column sortable/filterMode alongside the custom onChange override for pagination sync.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR standardizes list pagination across the app by persisting the current page in the URL (?page=N) instead of sessionStorage, and ensures page resets + selection clearing on key context switches (e.g., business group switch) to prevent stale cross-context actions.
Changes:
- Added
urlPageutilities (getPageFromSearch,setPageInSearch,removePageFromSearch) and unit tests. - Updated multiple list pages to read/write pagination via URL query, and reset to page 1 after save/batch ops and on business-group switch (plus clearing row selections in some flows).
- Adjusted several “back/cancel” navigations to preserve list page context via the
pagequery param.
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/urlPage.ts | New helpers to read/write/remove page from URL search. |
| src/utils/urlPage.test.ts | Unit tests covering page parsing and query updates. |
| src/pages/warning/subscribe/ListNG.tsx | Subscribe list now syncs pagination to URL and resets on group switch. |
| src/pages/warning/subscribe/index.tsx | Adds group-switch counter to trigger child list reset. |
| src/pages/warning/shield/index.tsx | Shield list pagination moved to URL; group switch resets page. |
| src/pages/taskTpl/modify.tsx | Return-to-list navigation preserves list page. |
| src/pages/taskTpl/index.tsx | Task template list pagination moved to URL and resets on group switch. |
| src/pages/taskTpl/detail.tsx | Back/cross-nav now preserves list page. |
| src/pages/taskTpl/clone.tsx | Return-to-list navigation preserves list page. |
| src/pages/taskTpl/add.tsx | Return-to-list navigation preserves list page (including hard redirect). |
| src/pages/task/result.tsx | Back navigation now preserves tasks list page. |
| src/pages/task/index.tsx | Tasks list pagination moved to URL and resets on group switch. |
| src/pages/task/detail.tsx | Back navigation now preserves tasks list page. |
| src/pages/task/add.tsx | Back navigation now preserves originating list page (tasks or templates). |
| src/pages/recordingRules/PageTable.tsx | Recording rules list pagination moved to URL; resets and clears selection on group switch and after ops. |
| src/pages/recordingRules/index.tsx | Adds group-switch counter to trigger child list reset. |
| src/pages/recordingRules/components/operateForm.tsx | Preserves originating list context (fromGids/page) on cancel/return. |
| src/pages/notificationRules/pages/List.tsx | Notification rules list pagination moved to URL. |
| src/pages/notificationRules/pages/Form/index.tsx | Cancel link now preserves list page. |
| src/pages/notificationRules/pages/Edit.tsx | Back behavior adjusted (relies on history rather than fixed backPath). |
| src/pages/notificationRules/pages/Detail/index.tsx | Back-to-list and edit links preserve page. |
| src/pages/notificationRules/pages/Add.tsx | Back behavior adjusted (relies on history rather than fixed backPath). |
| src/pages/notificationRules/constants.ts | Exposes filter storage key as a shared constant. |
| src/pages/notificationChannels/pages/ListNG/index.tsx | Notification channels list pagination moved to URL. |
| src/pages/notificationChannels/pages/Form/index.tsx | Cancel link now preserves list page. |
| src/pages/notificationChannels/pages/Edit.tsx | Back behavior adjusted (relies on history rather than fixed backPath). |
| src/pages/notificationChannels/pages/Add.tsx | Back behavior adjusted (relies on history rather than fixed backPath). |
| src/pages/notificationChannels/constants.ts | Exposes filter storage key as a shared constant. |
| src/pages/dashboard/List/index.tsx | Dashboard list pagination moved to URL; resets on group switch and clears selection. |
| src/pages/dashboard/List/Header.tsx | Clears selection after batch operations. |
| src/pages/dashboard/List/BatchClone.tsx | Adds optional onOk callback to clear selection on success. |
| src/pages/dashboard/Detail/Title.tsx | Return-to-list logic now uses page from URL when present. |
| src/pages/alertRules/List/MoreOperations.tsx | Batch ops now optionally clear selection on success. |
| src/pages/alertRules/List/ListNG.tsx | Alert rules list pagination moved to URL; resets paging + clears selection after ops and on group switch. |
| src/pages/alertRules/List/index.tsx | Plumbs group-switch counter and clearSelection through list components. |
| src/pages/alertRules/List/constants.ts | Exposes filter storage key as a shared constant. |
| src/pages/alertRules/index.tsx | Adds group-switch counter to trigger child list reset. |
| src/pages/alertRules/FormNG/index.tsx | Cancel returns to original list page; save returns to list page 1. |
| src/pages/alertRules/Edit.tsx | Back path now preserves list page. |
| src/pages/alertRules/Add.tsx | Back path now preserves list page. |
Suppressed comments (1)
src/pages/warning/subscribe/ListNG.tsx:80
current只在初次渲染时从location.search初始化;当用户使用浏览器前进/后退导致?page=变化时,这里不会同步更新,URL 和表格页码可能不一致。建议把 URL 作为单一数据源:监听location.search变化并同步current。
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const query = querystring.parse(location.search); | ||
| const { viewMode, __public__ } = query; | ||
| // 从列表进入详情时 URL 带 page 参数,返回列表时回到原页;其他入口回列表第一页 | ||
| const goListPath = props.gobackPath || (getPageFromSearch(location.search) > 1 ? `/dashboards?page=${getPageFromSearch(location.search)}` : '/dashboards'); |
| const [searchVal, setsearchVal] = useState<string>(sessionStorage.getItem(SEARCH_SESSION_STORAGE_KEY) || ''); | ||
| const [current, setCurrent] = useState<number>(() => { | ||
| const saved = sessionStorage.getItem(DASHBOARD_PAGE_SESSION_KEY); | ||
| return saved ? Number(saved) : 1; | ||
| }); | ||
| const [current, setCurrent] = useState<number>(() => getPageFromSearch(location.search)); | ||
| const [selectedBusinessGroup, setSelectedBusinessGroup] = useState<number[] | undefined>(getDefaultPublicSelectGids(PUBLIC_SELECT_GIDS_LOCALKEY)); // 目前只有公开仪表盘会用到 | ||
| const [busiGroups, setBusiGroups] = useState<any[]>([]); | ||
| const pagination = usePagination({ PAGESIZE_KEY: 'dashboard-pagesize' }); |
| const defaultPage = getPageFromSearch(location.search); | ||
| const [filter, setFilter] = useState<Filter>(defaultFilter); | ||
| const [current, setCurrent] = useState<number>(defaultPage); | ||
| const handleFilterChange = (newFilter: Filter) => { | ||
| setFilter(newFilter); |
Move list pagination from sessionStorage to URL ?page=N across list pages. Reset to page 1 after create/edit/batch ops and on business-group switch (via a groupSwitchCount counter). Clear row selection on group switch to prevent stale cross-group IDs reaching batch operations. Add urlPage util (getPageFromSearch/setPageInSearch/removePageFromSearch) with unit tests.
Note: task/taskTpl tables drop column sortable/filterMode alongside the custom onChange override for pagination sync.