@ethanhann/mantine-dataview 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/dist/core/useDataViewFetcher.d.ts +6 -1
- package/dist/index.js +483 -424
- package/dist/index.js.map +1 -1
- package/dist/types/options.d.ts +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -321,6 +321,55 @@ Re-fetch the current data without changing any state:
|
|
|
321
321
|
This re-emits the current request to the fetcher. It's the same mechanism the built-in
|
|
322
322
|
error retry button uses.
|
|
323
323
|
|
|
324
|
+
### Optimistic reconciliation
|
|
325
|
+
|
|
326
|
+
When a sibling library (e.g. a detail panel) saves, creates, or deletes a record, the list
|
|
327
|
+
can reflect the change instantly without a full reload. Three primitives on the return value
|
|
328
|
+
apply in-place mutations, then schedule a background revalidation fetch that reconciles with
|
|
329
|
+
server truth.
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
const view = useDataViewFetcher({ ... });
|
|
333
|
+
|
|
334
|
+
// A record was updated, replace it in place.
|
|
335
|
+
view.patchRow(updatedRecord);
|
|
336
|
+
|
|
337
|
+
// A new record was created, prepend it to the current page.
|
|
338
|
+
view.insertRow(newRecord);
|
|
339
|
+
|
|
340
|
+
// A record was deleted, remove it from the current page.
|
|
341
|
+
view.removeRow(recordId);
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Each call immediately updates the rendered rows and then kicks off a debounced background
|
|
345
|
+
refetch (default 1 second, configurable via `revalidateDelay`). Rapid mutations coalesce
|
|
346
|
+
into a single fetch. When the server responds, its data fully replaces the optimistic state,
|
|
347
|
+
correcting sort position, filter membership, pagination counts, and facet buckets.
|
|
348
|
+
|
|
349
|
+
`view.isRevalidating` is `true` while the background fetch is in flight. Use it to show a
|
|
350
|
+
subtle sync indicator without replacing content with loading skeletons.
|
|
351
|
+
|
|
352
|
+
```tsx
|
|
353
|
+
const view = useDataViewFetcher({
|
|
354
|
+
fetcher,
|
|
355
|
+
columns,
|
|
356
|
+
getRowId: (row) => row.id,
|
|
357
|
+
revalidateDelay: 500, // default 1000ms
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
{view.isRevalidating && <Loader size="xs" />}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**Semantics.** The client cannot reproduce server-side filter membership, sort order, or facet
|
|
364
|
+
counts. The optimistic patch is a best-effort visual preview. The background revalidation is
|
|
365
|
+
the source of truth. An edited row that no longer matches the active filter will disappear
|
|
366
|
+
when the server responds. A created row that doesn't belong on the current page will be
|
|
367
|
+
repositioned. This is the stale-while-revalidate pattern: instant perceived speed with
|
|
368
|
+
eventual correctness.
|
|
369
|
+
|
|
370
|
+
When using the raw `useDataView` hook (without the fetcher wrapper), the three methods fall
|
|
371
|
+
back to calling `refetch()`, since you control the row data externally.
|
|
372
|
+
|
|
324
373
|
## Column data types and formatting
|
|
325
374
|
|
|
326
375
|
Set `dataType` on a column's meta to enable automatic value formatting. When no explicit
|
|
@@ -932,9 +981,21 @@ This is opt-in. The default behavior (skeleton loading) is unchanged.
|
|
|
932
981
|
| `ViewSwitcher` | Table/Cards toggle (customizable labels) |
|
|
933
982
|
| `exportCsv` | Standalone CSV export utility |
|
|
934
983
|
| `col` | Fluent column builder factory |
|
|
984
|
+
| `getViewMode` | Detect table vs cards from cell context |
|
|
935
985
|
| `createColumnHelper`, `composeCardLayout`, `resolveColumnLabel` | Column helpers |
|
|
936
986
|
| `@ethanhann/mantine-dataview/url` | `windowHistoryAdapter` + serializer utilities |
|
|
937
987
|
|
|
988
|
+
### Reconciliation primitives
|
|
989
|
+
|
|
990
|
+
Returned by `useDataViewFetcher` (fall back to `refetch()` on raw `useDataView`):
|
|
991
|
+
|
|
992
|
+
| Method / Property | Purpose |
|
|
993
|
+
|--------------------|----------------------------------------------------------------|
|
|
994
|
+
| `patchRow(record)` | Replace an existing row by identity, then background revalidate |
|
|
995
|
+
| `insertRow(record)`| Prepend a new row, increment `rowCount`, then revalidate |
|
|
996
|
+
| `removeRow(id)` | Remove a row, decrement `rowCount`, then revalidate |
|
|
997
|
+
| `isRevalidating` | `true` while the background revalidation fetch is in flight |
|
|
998
|
+
|
|
938
999
|
### Customization slots
|
|
939
1000
|
|
|
940
1001
|
Passed via the `slots` prop on `DataViewer` or the presentation components:
|
|
@@ -5,5 +5,10 @@ export interface UseDataViewFetcherOptions<TData> extends Omit<UseDataViewOption
|
|
|
5
5
|
fetcher: (request: DataViewRequest) => Promise<DataViewResponse<NoInfer<TData>>>;
|
|
6
6
|
/** External dependencies that should trigger a refetch when they change. */
|
|
7
7
|
deps?: unknown[];
|
|
8
|
+
/**
|
|
9
|
+
* Delay in milliseconds before the background revalidation fetch fires after an optimistic
|
|
10
|
+
* mutation. Multiple rapid mutations coalesce into one fetch. Default `1000`.
|
|
11
|
+
*/
|
|
12
|
+
revalidateDelay?: number;
|
|
8
13
|
}
|
|
9
|
-
export declare function useDataViewFetcher<TData>({ fetcher, deps, ...options }: UseDataViewFetcherOptions<TData>): UseDataViewReturn<TData>;
|
|
14
|
+
export declare function useDataViewFetcher<TData>({ fetcher, deps, revalidateDelay, ...options }: UseDataViewFetcherOptions<TData>): UseDataViewReturn<TData>;
|