@macrostrat/data-sheet 4.2.1 → 4.3.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/CHANGELOG.md +83 -0
- package/dist/actions/types.d.ts +10 -0
- package/dist/components/indicators/filter-and-sort.cjs +47 -6
- package/dist/components/indicators/filter-and-sort.cjs.map +1 -1
- package/dist/components/indicators/filter-and-sort.d.ts +28 -6
- package/dist/components/indicators/filter-and-sort.js +48 -7
- package/dist/components/indicators/filter-and-sort.js.map +1 -1
- package/dist/components/indicators/filter-and-sort.module.sass.cjs +5 -3
- package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -1
- package/dist/components/indicators/filter-and-sort.module.sass.js +5 -3
- package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -1
- package/dist/components/indicators/unified-filters.cjs +36 -22
- package/dist/components/indicators/unified-filters.cjs.map +1 -1
- package/dist/components/indicators/unified-filters.d.ts +10 -8
- package/dist/components/indicators/unified-filters.js +37 -23
- package/dist/components/indicators/unified-filters.js.map +1 -1
- package/dist/components/indicators/view-info.cjs +6 -0
- package/dist/components/indicators/view-info.cjs.map +1 -1
- package/dist/components/indicators/view-info.d.ts +2 -2
- package/dist/components/indicators/view-info.js +7 -1
- package/dist/components/indicators/view-info.js.map +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs +7 -1
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
- package/dist/components/toolbars/actions-toolbar.js +7 -1
- package/dist/components/toolbars/actions-toolbar.js.map +1 -1
- package/dist/data-panel.cjs +51 -6
- package/dist/data-panel.cjs.map +1 -1
- package/dist/data-panel.d.ts +1 -1
- package/dist/data-panel.js +52 -7
- package/dist/data-panel.js.map +1 -1
- package/dist/data-panel.module.sass.cjs +24 -21
- package/dist/data-panel.module.sass.cjs.map +1 -1
- package/dist/data-panel.module.sass.js +24 -21
- package/dist/data-panel.module.sass.js.map +1 -1
- package/dist/data-sheet.cjs +3 -1
- package/dist/data-sheet.cjs.map +1 -1
- package/dist/data-sheet.css +56 -35
- package/dist/data-sheet.d.ts +1 -1
- package/dist/data-sheet.js +3 -1
- package/dist/data-sheet.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/postgrest-table/data-loaders.cjs +20 -3
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +10 -0
- package/dist/postgrest-table/data-loaders.js +21 -4
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/provider/core.cjs +27 -56
- package/dist/provider/core.cjs.map +1 -1
- package/dist/provider/core.d.ts +7 -9
- package/dist/provider/core.js +19 -48
- package/dist/provider/core.js.map +1 -1
- package/dist/provider/interactions.d.ts +1 -1
- package/dist/provider/selection.d.ts +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.js.map +1 -1
- package/package.json +5 -6
- package/src/actions/types.ts +11 -0
- package/src/components/indicators/filter-and-sort.module.sass +7 -0
- package/src/components/indicators/filter-and-sort.ts +71 -11
- package/src/components/indicators/unified-filters.ts +66 -29
- package/src/components/indicators/view-info.ts +10 -0
- package/src/components/toolbars/actions-toolbar.ts +10 -1
- package/src/data-panel.module.sass +18 -1
- package/src/data-panel.ts +65 -6
- package/src/data-sheet.ts +2 -0
- package/src/postgrest-table/data-loaders.ts +40 -4
- package/src/provider/core.ts +29 -53
- package/src/types.ts +4 -0
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
ALL_CARDINALITIES,
|
|
3
3
|
isColumnFilterable,
|
|
4
4
|
TableAction,
|
|
5
|
+
TableFilter,
|
|
5
6
|
} from "../../actions";
|
|
6
7
|
import { ctx, storeAtom, useSelector } from "../../provider";
|
|
7
8
|
import { useMemo } from "react";
|
|
@@ -10,33 +11,74 @@ import { Menu, Tag } from "@blueprintjs/core";
|
|
|
10
11
|
import {
|
|
11
12
|
ColumnFilterMenuItem,
|
|
12
13
|
ColumnSortMenu,
|
|
14
|
+
InlineFilterControl,
|
|
13
15
|
MenuDropdown,
|
|
16
|
+
MenuInlineFilterItem,
|
|
14
17
|
resolveColumnFilter,
|
|
15
18
|
} from "./filter-and-sort.ts";
|
|
16
19
|
import { atom } from "jotai";
|
|
17
20
|
|
|
21
|
+
/** A filter to surface, plus the label to show for it. */
|
|
22
|
+
interface FilterEntry {
|
|
23
|
+
filter: TableFilter;
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
/**
|
|
19
|
-
* Stand-in for the column-header dropdown the card list lacks
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
28
|
+
* Stand-in for the column-header dropdown the card list lacks. Surfaces every
|
|
29
|
+
* available filter (column-declared `filterable` + any table-level `filters`)
|
|
30
|
+
* and sort, honoring each filter's `presentation`:
|
|
31
|
+
* - `"inline"` → an always-visible toolbar control (its `filterForm` directly),
|
|
32
|
+
* - `"menu"` (default) → a "Filter" menu item that opens the form in a submenu,
|
|
33
|
+
* - `"menu-inline"` → the form rendered directly in the "Filter" menu.
|
|
34
|
+
* Every case reuses the *same* controls and store/provider seam — only
|
|
35
|
+
* placement changes. Sort still comes from the column-declared `sortable` set.
|
|
25
36
|
*/
|
|
26
|
-
export function useDataPanelControls(
|
|
27
|
-
|
|
37
|
+
export function useDataPanelControls(
|
|
38
|
+
tableFilters: TableFilter[] = [],
|
|
39
|
+
): TableAction[] {
|
|
40
|
+
const columnSpec = useSelector((s) => s.columnSpec);
|
|
28
41
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
// All filters, table-level first, then column-derived (each with a label).
|
|
43
|
+
const entries = useMemo<FilterEntry[]>(() => {
|
|
44
|
+
const fromColumns = columnSpec
|
|
45
|
+
.filter((c) => isColumnFilterable(c))
|
|
46
|
+
.map((c) => ({ filter: resolveColumnFilter(c), label: c.name }));
|
|
47
|
+
const fromTable = tableFilters.map((f) => ({ filter: f, label: f.name }));
|
|
48
|
+
return [...fromTable, ...fromColumns];
|
|
49
|
+
}, [columnSpec, tableFilters]);
|
|
50
|
+
|
|
51
|
+
const inlineEntries = entries.filter(
|
|
52
|
+
(e) => presentationOf(e.filter) === "inline",
|
|
53
|
+
);
|
|
54
|
+
const menuEntries = entries.filter(
|
|
55
|
+
(e) => presentationOf(e.filter) !== "inline",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Hooks first (stable order), then assemble.
|
|
59
|
+
const filterMenuAction = useFilterMenuAction(menuEntries);
|
|
33
60
|
const sortAction = useSortAction();
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
|
|
62
|
+
const actions: TableAction[] = [];
|
|
63
|
+
// Inline filters: one always-visible toolbar control each.
|
|
64
|
+
for (const { filter } of inlineEntries) {
|
|
65
|
+
actions.push({
|
|
66
|
+
id: `filter:${filter.id}`,
|
|
67
|
+
name: filter.name,
|
|
68
|
+
icon: filter.icon,
|
|
69
|
+
targets: ALL_CARDINALITIES,
|
|
70
|
+
render: () => h(InlineFilterControl, { filter }),
|
|
71
|
+
});
|
|
36
72
|
}
|
|
73
|
+
if (filterMenuAction != null) actions.push(filterMenuAction);
|
|
74
|
+
if (sortAction != null) actions.push(sortAction);
|
|
37
75
|
return actions;
|
|
38
76
|
}
|
|
39
77
|
|
|
78
|
+
function presentationOf(filter: TableFilter): string {
|
|
79
|
+
return filter.presentation ?? "menu";
|
|
80
|
+
}
|
|
81
|
+
|
|
40
82
|
function useDisplayIntent(atom) {
|
|
41
83
|
const [hasActive, clearActive] = ctx.use(atom);
|
|
42
84
|
const intent = hasActive ? "primary" : "none";
|
|
@@ -54,26 +96,21 @@ function useDisplayIntent(atom) {
|
|
|
54
96
|
return { intent, rightIcon, onRemove, hasActive };
|
|
55
97
|
}
|
|
56
98
|
|
|
57
|
-
function
|
|
58
|
-
const columnSpec = useSelector((s) => s.columnSpec);
|
|
59
|
-
const filterableCols = useMemo(
|
|
60
|
-
() => columnSpec.filter((c) => isColumnFilterable(c)),
|
|
61
|
-
[columnSpec],
|
|
62
|
-
);
|
|
63
|
-
|
|
99
|
+
function useFilterMenuAction(entries: FilterEntry[]): TableAction | null {
|
|
64
100
|
const rest = useDisplayIntent(hasActiveFiltersAtom);
|
|
65
101
|
|
|
66
|
-
if (
|
|
102
|
+
if (entries.length === 0) return null;
|
|
67
103
|
|
|
68
104
|
const filterMenu = h(
|
|
69
105
|
Menu,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
106
|
+
entries.map(({ filter, label }) => {
|
|
107
|
+
// A `menu-inline` filter renders its form directly in the menu (no
|
|
108
|
+
// submenu); the default `menu` presentation uses the submenu item.
|
|
109
|
+
if (presentationOf(filter) === "menu-inline") {
|
|
110
|
+
return h(MenuInlineFilterItem, { key: filter.id, filter, label });
|
|
111
|
+
}
|
|
112
|
+
return h(ColumnFilterMenuItem, { key: filter.id, filter, label });
|
|
113
|
+
}),
|
|
77
114
|
);
|
|
78
115
|
|
|
79
116
|
const filterIndicator = h(
|
|
@@ -9,6 +9,16 @@ import { Button, ButtonGroup, Icon, Spinner } from "@blueprintjs/core";
|
|
|
9
9
|
* controls with "Page X of Y". */
|
|
10
10
|
export function LoadProgressIndicator({ iconSize: size = 12, className }) {
|
|
11
11
|
const footer = ctx.useValue(tableFooterAtom);
|
|
12
|
+
|
|
13
|
+
// A load error takes precedence over the normal progress display in every
|
|
14
|
+
// mode — a compact, non-crashing signal that the source failed.
|
|
15
|
+
if (footer.error != null) {
|
|
16
|
+
return h("div.load-progress.load-error", { className }, [
|
|
17
|
+
h(Icon, { icon: "error", size, intent: "danger" }),
|
|
18
|
+
h("span.load-progress-label", footer.error.message ?? "Failed to load"),
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
if (footer.mode === "paged") return h(PageControl);
|
|
13
23
|
|
|
14
24
|
const { loaded, total, loading } = footer;
|
|
@@ -79,7 +79,10 @@ export function ActionsToolbar<T>({
|
|
|
79
79
|
[actions, columnSpec],
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
// Render whenever there are displayable actions OR the consumer supplied
|
|
83
|
+
// custom toolbar chrome (`children`) — a facet-less panel (e.g. a card list
|
|
84
|
+
// with only a search box) still needs its toolbar slot to appear.
|
|
85
|
+
if (!toolbarIsShown && children == null) {
|
|
83
86
|
return null;
|
|
84
87
|
}
|
|
85
88
|
|
|
@@ -165,6 +168,10 @@ function RunActionButton<T>({ action }: { action: TableAction<T> }) {
|
|
|
165
168
|
return h(
|
|
166
169
|
Button,
|
|
167
170
|
{
|
|
171
|
+
// Minimal + small to match the toolbar's other controls (scroll-to-row,
|
|
172
|
+
// sort/filter tags) — the compact, minimal house style.
|
|
173
|
+
minimal: true,
|
|
174
|
+
small: true,
|
|
168
175
|
icon: action.icon,
|
|
169
176
|
intent: action.intent,
|
|
170
177
|
disabled: isDisabled,
|
|
@@ -230,6 +237,8 @@ function ActionButtonWithForm<T, S>({
|
|
|
230
237
|
h(
|
|
231
238
|
Button,
|
|
232
239
|
{
|
|
240
|
+
minimal: true,
|
|
241
|
+
small: true,
|
|
233
242
|
icon: action.icon,
|
|
234
243
|
intent: action.intent,
|
|
235
244
|
disabled: isDisabled,
|
|
@@ -53,9 +53,26 @@
|
|
|
53
53
|
min-width: 0
|
|
54
54
|
|
|
55
55
|
// The inline end-of-scroll region (default spinner sentinel, or an inline
|
|
56
|
-
// footer). Sits in the scroll flow, so it's seen only at the bottom.
|
|
56
|
+
// footer). Sits in the scroll flow, so it's seen only at the bottom. A constant
|
|
57
|
+
// min-height keeps its content (spinner / "Load more" / end note) swapping in
|
|
58
|
+
// place instead of the footer pinging up into the list as pages append.
|
|
57
59
|
.content-footer-holder
|
|
58
60
|
flex: 0 0 auto
|
|
61
|
+
min-height: 44px
|
|
62
|
+
display: flex
|
|
63
|
+
align-items: center
|
|
64
|
+
justify-content: center
|
|
65
|
+
|
|
66
|
+
// Skeleton placeholder shown where a loading page's rows will land — sized like
|
|
67
|
+
// a card so the body height stays stable (no blank flash, no footer ping). The
|
|
68
|
+
// shimmer comes from Blueprint's `.bp6-skeleton`.
|
|
69
|
+
.data-panel-item-container.is-skeleton
|
|
70
|
+
pointer-events: none
|
|
71
|
+
|
|
72
|
+
.data-panel-skeleton
|
|
73
|
+
width: 100%
|
|
74
|
+
min-height: 3.25em
|
|
75
|
+
border-radius: 4px
|
|
59
76
|
|
|
60
77
|
// Default layout body — a vertical list of cards. A custom `scrollBody`
|
|
61
78
|
// replaces this element (e.g. with a CSS grid) but keeps the same scroll
|
package/src/data-panel.ts
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
useRef,
|
|
36
36
|
useState,
|
|
37
37
|
} from "react";
|
|
38
|
-
import { Icon, Spinner } from "@blueprintjs/core";
|
|
38
|
+
import { Classes, Icon, NonIdealState, Spinner } from "@blueprintjs/core";
|
|
39
39
|
import {
|
|
40
40
|
anchorRefAtom,
|
|
41
41
|
ctx,
|
|
@@ -173,7 +173,9 @@ export interface SelectModifiers {
|
|
|
173
173
|
export function DataPanelRenderer<T>({
|
|
174
174
|
itemComponent,
|
|
175
175
|
actions = [],
|
|
176
|
+
filters = [],
|
|
176
177
|
pageSize = 50,
|
|
178
|
+
filterDebounce,
|
|
177
179
|
name,
|
|
178
180
|
// Bottom bar
|
|
179
181
|
statusBar,
|
|
@@ -211,8 +213,17 @@ export function DataPanelRenderer<T>({
|
|
|
211
213
|
// (also available to the caller's `footer` via the same hook). The panel's
|
|
212
214
|
// `autoLoadPages` prop is the store's configuration input.
|
|
213
215
|
ctx.useSync(autoLoadPagesAtom, autoLoadPages ?? null);
|
|
214
|
-
const {
|
|
215
|
-
|
|
216
|
+
const {
|
|
217
|
+
loading,
|
|
218
|
+
initialized,
|
|
219
|
+
error,
|
|
220
|
+
hasMore,
|
|
221
|
+
loaded,
|
|
222
|
+
total,
|
|
223
|
+
paused,
|
|
224
|
+
canLoadMore,
|
|
225
|
+
advance,
|
|
226
|
+
} = useLoadControls();
|
|
216
227
|
|
|
217
228
|
// Track whether the body is scrolled off the top, to gate the top fade.
|
|
218
229
|
// `setState` with an unchanged value is a no-op, so this only re-renders on
|
|
@@ -270,9 +281,52 @@ export function DataPanelRenderer<T>({
|
|
|
270
281
|
);
|
|
271
282
|
});
|
|
272
283
|
|
|
284
|
+
// Body-level empty/error state: when nothing has loaded, show a clear message
|
|
285
|
+
// instead of a blank list — an errored source (e.g. a 401 on the whole route)
|
|
286
|
+
// degrades gracefully, and a genuinely empty result reads as "no results"
|
|
287
|
+
// rather than a perpetual spinner.
|
|
288
|
+
// A load is pending whenever a fetch is in flight OR the view was just reset
|
|
289
|
+
// and hasn't fetched yet (`!initialized`) — the window that would otherwise
|
|
290
|
+
// flash "No results" before the request starts.
|
|
291
|
+
const loadPending = (loading || !initialized) && error == null;
|
|
292
|
+
|
|
293
|
+
let emptyState: ReactNode = null;
|
|
294
|
+
if (cards.length === 0) {
|
|
295
|
+
if (error != null) {
|
|
296
|
+
emptyState = h(NonIdealState, {
|
|
297
|
+
icon: "error",
|
|
298
|
+
title: "Couldn't load data",
|
|
299
|
+
description: error.message ?? "The data source returned an error.",
|
|
300
|
+
});
|
|
301
|
+
} else if (initialized && !loading) {
|
|
302
|
+
// Only after a fetch settled with no rows — not during the reset gap.
|
|
303
|
+
emptyState = h(NonIdealState, {
|
|
304
|
+
icon: "search",
|
|
305
|
+
title: "No results",
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Skeleton placeholders for the page being fetched — on a view change (the
|
|
311
|
+
// reset pre-sizes to a page of `null` slots) or the next scroll page — so the
|
|
312
|
+
// body shows shimmer where rows will land instead of a blank flash or a
|
|
313
|
+
// footer pinging up into the gap. Bounded to a viewport's worth of cards.
|
|
314
|
+
if (loadPending) {
|
|
315
|
+
const pending = Math.min(Math.max(data.length - loadedCount, 0), 24);
|
|
316
|
+
for (let i = 0; i < pending; i++) {
|
|
317
|
+
cards.push(
|
|
318
|
+
h(
|
|
319
|
+
"div.data-panel-item-container.is-skeleton",
|
|
320
|
+
{ key: `skeleton-${i}`, "aria-hidden": true },
|
|
321
|
+
h("div.data-panel-skeleton", { className: Classes.SKELETON }),
|
|
322
|
+
),
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
273
327
|
// The default spinner sentinel (below-placement): hidden while paused so the
|
|
274
328
|
// pinned footer's "Load more" takes over.
|
|
275
|
-
const shouldLoadNextPage = (hasMore || loading) && !paused;
|
|
329
|
+
const shouldLoadNextPage = (hasMore || loading) && !paused && error == null;
|
|
276
330
|
|
|
277
331
|
// Mount the loader only once the provider resolves (see `PanelLoader`). Built
|
|
278
332
|
// as a real conditional — `h.if(...)` evaluates its arguments eagerly, so
|
|
@@ -283,10 +337,11 @@ export function DataPanelRenderer<T>({
|
|
|
283
337
|
fetchData: activeProvider.fetchData,
|
|
284
338
|
pageSize: loaderPageSize,
|
|
285
339
|
fetchMode: isLocalProvider ? undefined : "scroll",
|
|
340
|
+
filterDebounce,
|
|
286
341
|
});
|
|
287
342
|
}
|
|
288
343
|
|
|
289
|
-
const coreActions = useDataPanelControls();
|
|
344
|
+
const coreActions = useDataPanelControls(filters);
|
|
290
345
|
|
|
291
346
|
// Merge consumer actions with the synthesized Filter/Sort controls, deduped
|
|
292
347
|
// by id — consumer actions come first, so passing an action with id `filter`
|
|
@@ -360,6 +415,10 @@ export function DataPanelRenderer<T>({
|
|
|
360
415
|
actions: _actions,
|
|
361
416
|
tableName: name,
|
|
362
417
|
className: "data-panel-toolbar-content",
|
|
418
|
+
// In the panel the title doubles as the modal-selection control,
|
|
419
|
+
// so only render it when modal selection is toggle-able (or a
|
|
420
|
+
// selection is active) — not as a bare label otherwise.
|
|
421
|
+
compact: true,
|
|
363
422
|
},
|
|
364
423
|
toolbar,
|
|
365
424
|
),
|
|
@@ -371,7 +430,7 @@ export function DataPanelRenderer<T>({
|
|
|
371
430
|
className: classNames({ "is-scrolled": scrolled }),
|
|
372
431
|
},
|
|
373
432
|
h("div.data-panel-body-content", [
|
|
374
|
-
h(ScrollBody, cards),
|
|
433
|
+
emptyState ?? h(ScrollBody, cards),
|
|
375
434
|
_contentFooter,
|
|
376
435
|
]),
|
|
377
436
|
),
|
package/src/data-sheet.ts
CHANGED
|
@@ -108,6 +108,7 @@ export function DataSheetRenderer<T>({
|
|
|
108
108
|
provider,
|
|
109
109
|
pageSize,
|
|
110
110
|
fetchMode,
|
|
111
|
+
filterDebounce,
|
|
111
112
|
onVisibleCellsChange,
|
|
112
113
|
onUpdateData,
|
|
113
114
|
onEdit,
|
|
@@ -539,6 +540,7 @@ export function DataSheetRenderer<T>({
|
|
|
539
540
|
fetchData: activeProvider.fetchData,
|
|
540
541
|
pageSize: isLocalProvider ? Math.max(localCount, 1) : pageSize,
|
|
541
542
|
fetchMode: isLocalProvider ? undefined : fetchMode,
|
|
543
|
+
filterDebounce,
|
|
542
544
|
});
|
|
543
545
|
}
|
|
544
546
|
const showFilterBar =
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useAsyncEffect } from "@macrostrat/ui-components";
|
|
4
4
|
import { debounce } from "underscore";
|
|
5
|
-
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import update, { Spec } from "immutability-helper";
|
|
7
7
|
import {
|
|
8
8
|
ClientServerOptions,
|
|
@@ -372,6 +372,10 @@ export interface TableFooterInfo {
|
|
|
372
372
|
loaded: number;
|
|
373
373
|
total: number | null;
|
|
374
374
|
loading: boolean;
|
|
375
|
+
/** A fetch has been attempted since the last view reset — so `loaded === 0`
|
|
376
|
+
* can be told apart from "not loaded yet" (avoids an empty-state flash). */
|
|
377
|
+
initialized: boolean;
|
|
378
|
+
error: Error | null;
|
|
375
379
|
page: number;
|
|
376
380
|
pageSize: number;
|
|
377
381
|
totalPages: number | null;
|
|
@@ -396,6 +400,8 @@ export const tableFooterAtom = atom<TableFooterInfo>((get) => {
|
|
|
396
400
|
loaded,
|
|
397
401
|
total,
|
|
398
402
|
loading: core.loading,
|
|
403
|
+
initialized: core.initialized,
|
|
404
|
+
error: core.error,
|
|
399
405
|
page: get(chunkPageAtom),
|
|
400
406
|
pageSize: core.pageSize,
|
|
401
407
|
totalPages,
|
|
@@ -419,6 +425,12 @@ export interface LoadControls {
|
|
|
419
425
|
loadMore: () => void;
|
|
420
426
|
/** A fetch is in flight. */
|
|
421
427
|
loading: boolean;
|
|
428
|
+
/** A fetch has been attempted since the last view reset (so an empty result
|
|
429
|
+
* can be told apart from "not loaded yet"). */
|
|
430
|
+
initialized: boolean;
|
|
431
|
+
/** The most recent load error (cleared on the next successful load), else
|
|
432
|
+
* `null` — so a footer/consumer can degrade gracefully instead of hanging. */
|
|
433
|
+
error: Error | null;
|
|
422
434
|
/** More rows remain to load. */
|
|
423
435
|
hasMore: boolean;
|
|
424
436
|
/** Rows loaded so far. */
|
|
@@ -472,6 +484,8 @@ export function useLoadControls(): LoadControls {
|
|
|
472
484
|
return {
|
|
473
485
|
loadMore,
|
|
474
486
|
loading: footer.loading,
|
|
487
|
+
initialized: footer.initialized,
|
|
488
|
+
error: footer.error,
|
|
475
489
|
hasMore,
|
|
476
490
|
loaded: footer.loaded,
|
|
477
491
|
total: footer.total,
|
|
@@ -627,7 +641,7 @@ export function useDataLoader<T = any>(
|
|
|
627
641
|
fetchChunk: FetchData<T>,
|
|
628
642
|
options: FetchDataOptions = {},
|
|
629
643
|
) {
|
|
630
|
-
const { pageSize = 100, fetchMode = "scroll" } = options;
|
|
644
|
+
const { pageSize = 100, fetchMode = "scroll", filterDebounce = 0 } = options;
|
|
631
645
|
const [state, dispatch] = useLazyLoaderReducer();
|
|
632
646
|
|
|
633
647
|
const { isLocalProvider, provider } = ctx.useValue(dataProviderAtom);
|
|
@@ -671,10 +685,17 @@ export function useDataLoader<T = any>(
|
|
|
671
685
|
() => JSON.stringify({ sorts: columnSorts, filters }),
|
|
672
686
|
[columnSorts, filters],
|
|
673
687
|
);
|
|
688
|
+
// Debounce the view-state → refetch: rapid changes (typing in a text filter)
|
|
689
|
+
// otherwise reset + refetch on every keystroke, flashing the list. The store
|
|
690
|
+
// (and so the filter input) still updates instantly; only the *fetch* waits
|
|
691
|
+
// for the view to settle. Scroll paging is unaffected — it's driven by
|
|
692
|
+
// `visibleRegion`/`data`, not this key. `filterDebounce: 0` (default) keeps
|
|
693
|
+
// the immediate behavior.
|
|
694
|
+
const debouncedViewKey = useDebouncedValue(viewKey, filterDebounce);
|
|
674
695
|
useEffect(() => {
|
|
675
696
|
dispatch({ type: "reset" });
|
|
676
697
|
setPage(0);
|
|
677
|
-
}, [
|
|
698
|
+
}, [debouncedViewKey, fetchMode, refreshToken]);
|
|
678
699
|
|
|
679
700
|
useAsyncEffect(async () => {
|
|
680
701
|
if (state.loading) return;
|
|
@@ -759,11 +780,26 @@ export function useDataLoader<T = any>(
|
|
|
759
780
|
dispatch({ type: "error", error: err as Error });
|
|
760
781
|
}
|
|
761
782
|
}
|
|
762
|
-
}, [state.data, visibleRegion,
|
|
783
|
+
}, [state.data, visibleRegion, debouncedViewKey, page, fetchMode]);
|
|
763
784
|
|
|
764
785
|
return { data: state.data, loading: state.loading, error: state.error };
|
|
765
786
|
}
|
|
766
787
|
|
|
788
|
+
/** A value that trails `value` by `delay` ms of stability — the first value is
|
|
789
|
+
* returned immediately, and `delay <= 0` disables debouncing entirely. */
|
|
790
|
+
function useDebouncedValue<T>(value: T, delay: number): T {
|
|
791
|
+
const [debounced, setDebounced] = useState(value);
|
|
792
|
+
useEffect(() => {
|
|
793
|
+
if (delay <= 0) {
|
|
794
|
+
setDebounced(value);
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const t = setTimeout(() => setDebounced(value), delay);
|
|
798
|
+
return () => clearTimeout(t);
|
|
799
|
+
}, [value, delay]);
|
|
800
|
+
return debounced;
|
|
801
|
+
}
|
|
802
|
+
|
|
767
803
|
/**
|
|
768
804
|
* Build a `fetchChunk` backed by a PostgREST endpoint, for use with
|
|
769
805
|
* `useChunkLoader` / `ChunkLoaderManager`. It reuses `buildQuery`, so it pages
|
package/src/provider/core.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import h from "@macrostrat/hyper";
|
|
3
|
-
import { createStore, StoreApi, useStore } from "zustand";
|
|
4
3
|
import { Table } from "@blueprintjs/table";
|
|
5
4
|
import {
|
|
6
5
|
type ColumnSpec,
|
|
@@ -8,7 +7,15 @@ import {
|
|
|
8
7
|
postprocessColumnSpec,
|
|
9
8
|
} from "./column-spec.ts";
|
|
10
9
|
import { splitProps } from "../utils";
|
|
11
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createScopedStore,
|
|
12
|
+
zustandAPIAtom,
|
|
13
|
+
zustandStoreAtom,
|
|
14
|
+
atom,
|
|
15
|
+
ZustandStoreProvider,
|
|
16
|
+
useZustandSelector,
|
|
17
|
+
useZustandStoreAPI,
|
|
18
|
+
} from "@macrostrat/scoped-store";
|
|
12
19
|
import {
|
|
13
20
|
DataSheetProviderProps,
|
|
14
21
|
DataSheetState,
|
|
@@ -17,10 +24,8 @@ import {
|
|
|
17
24
|
TableElementStatus,
|
|
18
25
|
} from "./types.ts";
|
|
19
26
|
import { createZustandStore } from "./zustand-store.ts";
|
|
20
|
-
import { atomWithStore } from "jotai-zustand";
|
|
21
27
|
import { toasterAtom } from "../notifications.ts";
|
|
22
28
|
import { TableAction } from "../actions";
|
|
23
|
-
import { atom } from "jotai";
|
|
24
29
|
import {
|
|
25
30
|
createLocalProvider,
|
|
26
31
|
dataRefreshTokenAtom,
|
|
@@ -42,33 +47,10 @@ import { DataPanelProps } from "../data-panel.ts";
|
|
|
42
47
|
/** Create a Jotai scoped store */
|
|
43
48
|
export const ctx = createScopedStore();
|
|
44
49
|
|
|
45
|
-
export const storeAPIAtom =
|
|
46
|
-
|
|
47
|
-
const storeWrapperAtom = atom((get) => {
|
|
48
|
-
const _storeAPIAtom = get(storeAPIAtom);
|
|
49
|
-
if (_storeAPIAtom == null) {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
return atomWithStore(_storeAPIAtom);
|
|
53
|
-
});
|
|
50
|
+
export const storeAPIAtom = zustandAPIAtom;
|
|
54
51
|
|
|
55
52
|
/** This is the basis for all other atoms that manipulate the store. */
|
|
56
|
-
export const storeAtom =
|
|
57
|
-
(get) => {
|
|
58
|
-
const storeWrapper = get(storeWrapperAtom);
|
|
59
|
-
if (storeWrapper == null) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
return get(storeWrapper);
|
|
63
|
-
},
|
|
64
|
-
(get, set, action: SetStateAction<any>) => {
|
|
65
|
-
const storeWrapper = get(storeWrapperAtom);
|
|
66
|
-
if (storeWrapper == null) {
|
|
67
|
-
throw new Error("Missing DataSheetProvider");
|
|
68
|
-
}
|
|
69
|
-
return set(storeWrapper, action);
|
|
70
|
-
},
|
|
71
|
-
);
|
|
53
|
+
export const storeAtom = zustandStoreAtom;
|
|
72
54
|
|
|
73
55
|
/** Stable empty spec so a function `columnSpec` yields a constant init value
|
|
74
56
|
* (see `DataSheetProviderInner`). */
|
|
@@ -77,7 +59,7 @@ const EMPTY_SPEC: ColumnSpec[] = [];
|
|
|
77
59
|
const initializeStoreAtom = atom(
|
|
78
60
|
null,
|
|
79
61
|
(get, set, payload: Partial<DataSheetStore<any>>) => {
|
|
80
|
-
set(
|
|
62
|
+
set(zustandStoreAtom, (state) => {
|
|
81
63
|
return {
|
|
82
64
|
...state,
|
|
83
65
|
...payload,
|
|
@@ -172,16 +154,13 @@ export function useResolvedProvider<T>(props: {
|
|
|
172
154
|
|
|
173
155
|
function DataSheetStoreWrapper<T>(props: DataSheetProviderProps<T>) {
|
|
174
156
|
const { toaster, ...rest } = props;
|
|
175
|
-
const [store] = useState(() => {
|
|
176
|
-
return createStore<DataSheetStore<T>>(createZustandStore);
|
|
177
|
-
});
|
|
178
157
|
return h(
|
|
179
|
-
|
|
158
|
+
ZustandStoreProvider,
|
|
180
159
|
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
160
|
+
ctx,
|
|
161
|
+
initializeStore: createZustandStore,
|
|
162
|
+
atoms: [[toasterAtom, toaster]],
|
|
163
|
+
debugName: "DataSheetProvider",
|
|
185
164
|
},
|
|
186
165
|
h(DataSheetProviderInner, rest),
|
|
187
166
|
);
|
|
@@ -209,9 +188,7 @@ const dataProviderKeys = new Set([
|
|
|
209
188
|
]);
|
|
210
189
|
|
|
211
190
|
type AnyDataSheetProps<T> =
|
|
212
|
-
|
|
|
213
|
-
| DataPanelProps<T>
|
|
214
|
-
| DataSheetProps<T>;
|
|
191
|
+
DataViewProps<T> | DataPanelProps<T> | DataSheetProps<T>;
|
|
215
192
|
|
|
216
193
|
export function splitDataProviderProps<T>(props: AnyDataSheetProps<T>) {
|
|
217
194
|
/** Split provided props based on provider's needs */
|
|
@@ -295,9 +272,13 @@ export function DataSheetProviderInner<T>(
|
|
|
295
272
|
useEffect(() => {
|
|
296
273
|
initializeStore({
|
|
297
274
|
columnSpec: postprocessColumnSpec(baseSpec),
|
|
298
|
-
//
|
|
299
|
-
//
|
|
300
|
-
|
|
275
|
+
// Suppress the loader's first-chunk auto-generation whenever the consumer
|
|
276
|
+
// provided a spec at all — a function (derived later in `_DataSheet`) OR
|
|
277
|
+
// an explicit array, *including an empty one*. An empty array means "no
|
|
278
|
+
// facet columns" (e.g. a browse panel whose only control is a sheet-level
|
|
279
|
+
// search), not "please generate from the data". Auto-gen runs only when
|
|
280
|
+
// no `columnSpec` was passed.
|
|
281
|
+
deferColumnSpec: columnSpec != null,
|
|
301
282
|
editable: interactionOptions.enableEditing,
|
|
302
283
|
enableColumnReordering,
|
|
303
284
|
data,
|
|
@@ -398,19 +379,14 @@ export function DataSheetProviderInner<T>(
|
|
|
398
379
|
return children;
|
|
399
380
|
}
|
|
400
381
|
|
|
401
|
-
export function useStoreAPI<T>()
|
|
402
|
-
|
|
403
|
-
if (!store) {
|
|
404
|
-
throw new Error("Missing DataSheetProvider");
|
|
405
|
-
}
|
|
406
|
-
return store;
|
|
382
|
+
export function useStoreAPI<T>() {
|
|
383
|
+
return useZustandStoreAPI<DataSheetStore<T>>(ctx);
|
|
407
384
|
}
|
|
408
385
|
|
|
409
386
|
export function useSelector<T = any, A = any>(
|
|
410
387
|
selector: (state: DataSheetStore<T>) => A,
|
|
411
388
|
): A {
|
|
412
|
-
|
|
413
|
-
return useStore(store, selector);
|
|
389
|
+
return useZustandSelector<T, A>(ctx, selector);
|
|
414
390
|
}
|
|
415
391
|
/** Atoms for efficient sub-selection of state */
|
|
416
392
|
|
package/src/types.ts
CHANGED
|
@@ -18,6 +18,10 @@ export type FetchMode = "scroll" | "paged";
|
|
|
18
18
|
export interface FetchDataOptions {
|
|
19
19
|
pageSize?: number;
|
|
20
20
|
fetchMode?: FetchMode;
|
|
21
|
+
/** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a
|
|
22
|
+
* text filter) collapse into one fetch once the view settles. The input stays
|
|
23
|
+
* instant; only the fetch waits. `0` (default) keeps immediate refetching. */
|
|
24
|
+
filterDebounce?: number;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
/** Props shared between the wrapper components and the provider */
|