feat: add reloadKey prop to various components for improved data fetching control
This commit is contained in:
@@ -163,6 +163,7 @@ export type DashboardCrudPageProps<TItem, TPayload> = {
|
||||
handleLabel: string
|
||||
}
|
||||
pageSize?: number
|
||||
reloadKey?: string | number | null
|
||||
layout?: "page" | "fragment"
|
||||
showToolbar?: boolean
|
||||
showToolbarActions?: boolean
|
||||
@@ -205,6 +206,7 @@ export function DashboardCrudPage<TItem, TPayload>({
|
||||
renderRowActions,
|
||||
sort,
|
||||
pageSize = 20,
|
||||
reloadKey,
|
||||
layout = "page",
|
||||
showToolbar = true,
|
||||
showToolbarActions = true,
|
||||
@@ -227,6 +229,7 @@ export function DashboardCrudPage<TItem, TPayload>({
|
||||
filters,
|
||||
fetchList,
|
||||
pageSize,
|
||||
reloadKey,
|
||||
loadFailed: labels.loadFailed,
|
||||
})
|
||||
const draftFilters = list.draftFilters
|
||||
|
||||
@@ -68,6 +68,7 @@ export type DashboardListPageProps<TItem> = {
|
||||
onRowClick?: (item: TItem) => void
|
||||
pageSize?: number
|
||||
enabled?: boolean
|
||||
reloadKey?: string | number | null
|
||||
layout?: "page" | "fragment"
|
||||
tableShellClassName?: string
|
||||
labels: {
|
||||
@@ -90,6 +91,7 @@ export function DashboardListPage<TItem>({
|
||||
onRowClick,
|
||||
pageSize,
|
||||
enabled,
|
||||
reloadKey,
|
||||
layout = "page",
|
||||
tableShellClassName,
|
||||
labels,
|
||||
@@ -99,6 +101,7 @@ export function DashboardListPage<TItem>({
|
||||
fetchList,
|
||||
pageSize,
|
||||
enabled,
|
||||
reloadKey,
|
||||
loadFailed: labels.loadFailed,
|
||||
})
|
||||
const renderContext: DashboardListRenderContext<TItem> = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { useCallback, useEffect, useState } from "react"
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import {
|
||||
@@ -24,6 +24,7 @@ export type DashboardPagedListOptions<TItem> = {
|
||||
pageSize?: number
|
||||
loadFailed: string
|
||||
enabled?: boolean
|
||||
reloadKey?: string | number | null
|
||||
}
|
||||
|
||||
export function useDashboardPagedList<TItem>({
|
||||
@@ -32,7 +33,10 @@ export function useDashboardPagedList<TItem>({
|
||||
pageSize = 20,
|
||||
loadFailed,
|
||||
enabled = true,
|
||||
reloadKey,
|
||||
}: DashboardPagedListOptions<TItem>) {
|
||||
const fetchListRef = useRef(fetchList)
|
||||
fetchListRef.current = fetchList
|
||||
const filtersKey = filters
|
||||
.map(
|
||||
(filter) =>
|
||||
@@ -65,7 +69,7 @@ export function useDashboardPagedList<TItem>({
|
||||
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await fetchList(
|
||||
const data = await fetchListRef.current(
|
||||
buildDashboardCrudQuery({
|
||||
values: appliedFilters,
|
||||
filters,
|
||||
@@ -80,7 +84,7 @@ export function useDashboardPagedList<TItem>({
|
||||
setLoading(false)
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [appliedFilters, enabled, fetchList, filtersKey, limit, loadFailed, page])
|
||||
}, [appliedFilters, enabled, filtersKey, limit, loadFailed, page, reloadKey])
|
||||
|
||||
useEffect(() => {
|
||||
void loadData()
|
||||
|
||||
Reference in New Issue
Block a user