Skip to content

Commit 130be40

Browse files
committed
fix(dns): keep the record table on a valid page while filtering
Filtering from a later page left pageIndex past the end of the filtered set, so the table said no records matched while the counter above it reported matches. The page index is clamped to the available page count, and changing the search or the type filter goes back to the first page.
1 parent db2eb4f commit 130be40

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

‎apps/dokploy/components/dashboard/settings/dns/show-dns-records.tsx‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,23 @@ export const ShowDnsRecords = ({ dnsProviderId, zoneId }: Props) => {
294294
[canWrite, canDelete, deletingId, editing?.id, isCloudflare],
295295
);
296296

297+
const pageCount = Math.max(
298+
1,
299+
Math.ceil(filteredRecords.length / pagination.pageSize),
300+
);
301+
const pageIndex = Math.min(pagination.pageIndex, pageCount - 1);
302+
303+
const resetToFirstPage = () =>
304+
setPagination((previous) => ({ ...previous, pageIndex: 0 }));
305+
297306
const table = useReactTable({
298307
data: filteredRecords,
299308
columns,
300309
getRowId: (row) => row.id,
301-
state: { sorting, pagination },
310+
state: {
311+
sorting,
312+
pagination: { pageIndex, pageSize: pagination.pageSize },
313+
},
302314
onSortingChange: setSorting,
303315
onPaginationChange: setPagination,
304316
getCoreRowModel: getCoreRowModel(),
@@ -369,12 +381,21 @@ export const ShowDnsRecords = ({ dnsProviderId, zoneId }: Props) => {
369381
<FocusShortcutInput
370382
placeholder="Filter records..."
371383
value={search}
372-
onChange={(e) => setSearch(e.target.value)}
384+
onChange={(e) => {
385+
setSearch(e.target.value);
386+
resetToFirstPage();
387+
}}
373388
className="pr-10"
374389
/>
375390
<Search className="absolute right-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
376391
</div>
377-
<Select value={typeFilter} onValueChange={setTypeFilter}>
392+
<Select
393+
value={typeFilter}
394+
onValueChange={(value) => {
395+
setTypeFilter(value);
396+
resetToFirstPage();
397+
}}
398+
>
378399
<SelectTrigger className="w-36">
379400
<SelectValue />
380401
</SelectTrigger>
@@ -504,8 +525,7 @@ export const ShowDnsRecords = ({ dnsProviderId, zoneId }: Props) => {
504525
</div>
505526
<div className="flex items-center gap-4">
506527
<span className="text-sm text-muted-foreground tabular-nums">
507-
Page {table.getState().pagination.pageIndex + 1} of{" "}
508-
{Math.max(table.getPageCount(), 1)}
528+
Page {pageIndex + 1} of {pageCount}
509529
</span>
510530
<div className="flex gap-2">
511531
<Button

0 commit comments

Comments
 (0)