Skip to content

feat(list): persist page in URL and reset to 1 on save/group switch - #2257

Merged
jsers merged 1 commit into
prefrom
feat/list-paging-cache-reset
Aug 12, 2026
Merged

feat(list): persist page in URL and reset to 1 on save/group switch#2257
jsers merged 1 commit into
prefrom
feat/list-paging-cache-reset

Conversation

@jsers

@jsers jsers commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

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.

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.
Copilot AI lite review requested due to automatic review settings August 12, 2026 10:45
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bfcd6472-14a5-4664-b1bf-994d8bea1f31

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jsers
jsers merged commit 9a785ec into pre Aug 12, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 urlPage utilities (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 page query 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.

Comment on lines 107 to +110
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');
Comment on lines 77 to 81
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' });
Comment on lines +76 to 80
const defaultPage = getPageFromSearch(location.search);
const [filter, setFilter] = useState<Filter>(defaultFilter);
const [current, setCurrent] = useState<number>(defaultPage);
const handleFilterChange = (newFilter: Filter) => {
setFilter(newFilter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants