fix(ui): ограничить каталог BGP и сохранить страницу при обновлении
This commit is contained in:
1 parent
604b2b0b51
commit
39789765cb
5 files changed
+68
-3
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
import { dataGridFeatures, type DataGridFeatures } from "@/components/reui/data-grid"
|
||||
|
||||
import { useMemo } from "react"
|
||||
import { useMemo, useEffect } from "react"
|
||||
import {
|
||||
type ColumnDef,
|
||||
useTable,
|
||||
@@ -266,7 +266,9 @@ function BgpSessionsDataGrid({ sessions, emptyTitle, selectedSessionId, onSelect
|
||||
|
||||
const table = useTable({
|
||||
features: dataGridFeatures,
|
||||
manualPagination: true,
|
||||
manualPagination: false,
|
||||
autoResetPageIndex: false,
|
||||
initialState: { pagination: { pageIndex: 0, pageSize: 50 } },
|
||||
data: sessions,
|
||||
columns,
|
||||
getRowId: (row) => row.id,
|
||||
@@ -274,6 +276,18 @@ function BgpSessionsDataGrid({ sessions, emptyTitle, selectedSessionId, onSelect
|
||||
...(onSelectSession ? { state: { expanded: selectedSessionId ? { [selectedSessionId]: true } : {} } } : {}),
|
||||
})
|
||||
|
||||
const {pageIndex,pageSize}=table.state.pagination
|
||||
const sorting=table.state.sorting
|
||||
useEffect(()=>{
|
||||
const last=Math.max(0,Math.ceil(sessions.length/pageSize)-1)
|
||||
if(pageIndex>last)table.setPageIndex(last)
|
||||
},[sessions.length,pageSize,pageIndex,table])
|
||||
useEffect(()=>{
|
||||
if(!selectedSessionId)return
|
||||
const index=table.getPrePaginatedRowModel().rows.findIndex(row=>row.id===selectedSessionId)
|
||||
if(index>=0)table.setPageIndex(Math.floor(index/pageSize))
|
||||
},[selectedSessionId,pageSize,sessions.length,sorting,table])
|
||||
|
||||
if (sessions.length === 0) {
|
||||
return (
|
||||
<EmptyState
|
||||
@@ -289,6 +303,7 @@ function BgpSessionsDataGrid({ sessions, emptyTitle, selectedSessionId, onSelect
|
||||
<DataGridShell
|
||||
table={table}
|
||||
recordCount={sessions.length}
|
||||
pagination={sessions.length>50 || pageSize!==50}
|
||||
onRowClick={(row) => onSelectSession ? onSelectSession(row.id === selectedSessionId ? null : row.id) : table.getRow(row.id).toggleExpanded()}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user