@macrostrat/data-sheet 4.10.1 → 4.11.1

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/components/indicators/filter-and-sort.cjs +20 -71
  3. package/dist/components/indicators/filter-and-sort.cjs.map +1 -1
  4. package/dist/components/indicators/filter-and-sort.d.ts +10 -23
  5. package/dist/components/indicators/filter-and-sort.js +18 -69
  6. package/dist/components/indicators/filter-and-sort.js.map +1 -1
  7. package/dist/components/indicators/unified-filters.cjs +22 -46
  8. package/dist/components/indicators/unified-filters.cjs.map +1 -1
  9. package/dist/components/indicators/unified-filters.js +23 -47
  10. package/dist/components/indicators/unified-filters.js.map +1 -1
  11. package/dist/components/toolbars/actions-toolbar.cjs +39 -18
  12. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
  13. package/dist/components/toolbars/actions-toolbar.d.ts +7 -4
  14. package/dist/components/toolbars/actions-toolbar.js +37 -18
  15. package/dist/components/toolbars/actions-toolbar.js.map +1 -1
  16. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +11 -14
  17. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -1
  18. package/dist/components/toolbars/actions-toolbar.module.sass.js +12 -15
  19. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -1
  20. package/dist/data-panel.cjs +18 -6
  21. package/dist/data-panel.cjs.map +1 -1
  22. package/dist/data-panel.d.ts +6 -1
  23. package/dist/data-panel.js +19 -7
  24. package/dist/data-panel.js.map +1 -1
  25. package/dist/data-sheet.css +15 -21
  26. package/dist/index.cjs +5 -1
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.js +2 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/postgrest-table/data-loaders.cjs +1 -1
  31. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  32. package/dist/postgrest-table/data-loaders.d.ts +2 -1
  33. package/dist/postgrest-table/data-loaders.js +1 -1
  34. package/dist/postgrest-table/data-loaders.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/components/indicators/filter-and-sort.ts +25 -87
  37. package/src/components/indicators/unified-filters.ts +22 -50
  38. package/src/components/toolbars/actions-toolbar.module.sass +8 -10
  39. package/src/components/toolbars/actions-toolbar.ts +48 -17
  40. package/src/data-panel.ts +26 -5
  41. package/src/postgrest-table/data-loaders.ts +6 -2
@@ -1,5 +1,11 @@
1
1
  import { Button, ButtonGroup, PopoverNext } from "@blueprintjs/core";
2
2
  import { type ReactNode, useCallback, useMemo, useState } from "react";
3
+ import {
4
+ Toolbar,
5
+ type ToolbarCollapse,
6
+ type ToolbarItem,
7
+ } from "@macrostrat/ui-components";
8
+ import classNames from "classnames";
3
9
  import h from "./actions-toolbar.module.sass";
4
10
  import { ctx, selectionAtom, useSelector } from "../../provider";
5
11
  import {
@@ -28,12 +34,17 @@ export function ActionsToolbar<T>({
28
34
  children,
29
35
  className,
30
36
  compact = false,
37
+ collapse = "never",
31
38
  }: {
32
39
  actions: TableAction<T>[];
33
40
  tableName?: string;
34
41
  children: ReactNode;
35
42
  className?: string;
36
43
  compact: boolean;
44
+ /** How the bar sheds width (see `Toolbar`): contextual actions fold into a
45
+ * "more" popover when `narrow`; the selection title and the global actions
46
+ * stay. Default `never`. */
47
+ collapse?: ToolbarCollapse;
37
48
  }) {
38
49
  const selection = ctx.useValue(selectionAtom);
39
50
  const editable = useSelector((state) => state.editable);
@@ -108,24 +119,44 @@ export function ActionsToolbar<T>({
108
119
 
109
120
  const globalActions = shownActions.filter(isGlobal);
110
121
 
111
- return h("div.actions-toolbar", { className }, [
112
- h(SelectionIndicator, { minimal: compact }),
113
- h(
114
- "div.toolbar-group.contextual",
115
- contextual.map((action) =>
116
- h(ActionButton, { key: action.id, action, ctx: actionContext }),
117
- ),
118
- ),
119
- children,
120
- h("div.toolbar-spacer", { style: { flex: 1 } }),
121
- h(
122
- ButtonGroup,
123
- { minimal: true },
124
- globalActions.map((action) =>
125
- h(ActionButton, { key: action.id, action, ctx: actionContext }),
122
+ // Laid out by the shared `Toolbar`: the selection title, contextual actions
123
+ // and any custom chrome (`children`, at its natural width) lead; the global
124
+ // actions sit at the end as one group.
125
+ const start: ToolbarItem[] = [
126
+ {
127
+ id: "selection",
128
+ pinned: true,
129
+ content: h(SelectionIndicator, { minimal: compact }),
130
+ },
131
+ ...contextual.map((action) => ({
132
+ id: action.id,
133
+ content: h(ActionButton, { action, ctx: actionContext }),
134
+ })),
135
+ ];
136
+ if (children != null) {
137
+ start.push({ id: "toolbar-children", pinned: true, content: children });
138
+ }
139
+ const end: ToolbarItem[] = [];
140
+ if (globalActions.length > 0) {
141
+ end.push({
142
+ id: "global-actions",
143
+ pinned: true,
144
+ content: h(
145
+ ButtonGroup,
146
+ { minimal: true },
147
+ globalActions.map((action) =>
148
+ h(ActionButton, { key: action.id, action, ctx: actionContext }),
149
+ ),
126
150
  ),
127
- ),
128
- ]);
151
+ });
152
+ }
153
+
154
+ return h(Toolbar, {
155
+ className: classNames("actions-toolbar", className),
156
+ collapse,
157
+ start,
158
+ end,
159
+ });
129
160
  }
130
161
 
131
162
  function isActionDisabled(action: TableAction, state: any): boolean {
package/src/data-panel.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  *
23
23
  * See [[Data list editors]] in the Macrostrat workbench for the design.
24
24
  */
25
+ import type { ToolbarCollapse } from "@macrostrat/ui-components";
25
26
  import h from "./data-panel.module.sass";
26
27
  import {
27
28
  ComponentType,
@@ -37,6 +38,7 @@ import {
37
38
  } from "react";
38
39
  import {
39
40
  AnchorButton,
41
+ Button,
40
42
  Classes,
41
43
  Icon,
42
44
  NonIdealState,
@@ -47,6 +49,7 @@ import {
47
49
  anchorRefAtom,
48
50
  ctx,
49
51
  dataProviderAtom,
52
+ dataRefreshTokenAtom,
50
53
  DataSheetProvider,
51
54
  DataViewRendererType,
52
55
  FetchData,
@@ -164,6 +167,10 @@ export interface DataPanelProps<T = any> extends DataViewSharedProps<T> {
164
167
  * Ignored while a modal view is selecting: the toolbar then carries a single
165
168
  * control that leaves select mode. */
166
169
  viewControls?: ViewControlsPresentation;
170
+ /** How the toolbar sheds width (the shared `Toolbar`'s `collapse`): with
171
+ * `"narrow"`, button labels drop to icons and then contextual controls fold
172
+ * into a "more" popover as the panel narrows. Default `"never"`. */
173
+ toolbarCollapse?: ToolbarCollapse;
167
174
  /** Arbitrary children rendered inside the provider, after the panel. */
168
175
  children?: ReactNode;
169
176
  }
@@ -216,6 +223,7 @@ export function DataPanelRenderer<T>({
216
223
  className,
217
224
  toolbarStyle = DataPanelToolbarStyle.BORDERED,
218
225
  viewControls = "inline",
226
+ toolbarCollapse = "never",
219
227
  children,
220
228
  }: Omit<DataPanelProps<T>, "provider" | "fetchData" | "data" | "identity">) {
221
229
  const {
@@ -320,11 +328,7 @@ export function DataPanelRenderer<T>({
320
328
  let emptyState: ReactNode = null;
321
329
  if (cards.length === 0) {
322
330
  if (error != null) {
323
- emptyState = h(NonIdealState, {
324
- icon: "error",
325
- title: "Couldn't load data",
326
- description: error.message ?? "The data source returned an error.",
327
- });
331
+ emptyState = h(LoadErrorState, { error });
328
332
  } else if (initialized && !loading) {
329
333
  // Only after a fetch settled with no rows — not during the reset gap.
330
334
  emptyState = h(NonIdealState, {
@@ -487,6 +491,7 @@ export function DataPanelRenderer<T>({
487
491
  // so only render it when modal selection is toggle-able (or a
488
492
  // selection is active) — not as a bare label otherwise.
489
493
  compact: true,
494
+ collapse: toolbarCollapse,
490
495
  },
491
496
  toolbar,
492
497
  ),
@@ -555,6 +560,22 @@ function modifiersOf(arg?: SelectModifiers | ReactMouseEvent): SelectModifiers {
555
560
  return arg;
556
561
  }
557
562
 
563
+ /** A failed load, with a retry: auto-load stays off after an error, so
564
+ * reloading is the user's call. */
565
+ function LoadErrorState({ error }: { error: Error }) {
566
+ const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);
567
+ return h(NonIdealState, {
568
+ icon: "error",
569
+ title: "Couldn't load data",
570
+ description: error.message ?? "The data source returned an error.",
571
+ action: h(
572
+ Button,
573
+ { icon: "refresh", onClick: () => bumpRefresh((v) => v + 1) },
574
+ "Try again",
575
+ ),
576
+ });
577
+ }
578
+
558
579
  /**
559
580
  * Bottom-sentinel infinite-scroll hook (no `react-intersection-observer`
560
581
  * dependency). Calls `onVisible` when the observed element is on screen, and —
@@ -447,7 +447,8 @@ export interface LoadControls {
447
447
  total: number | null;
448
448
  /** Auto-load is paused at the `autoLoadPages` checkpoint. */
449
449
  paused: boolean;
450
- /** Auto-load is currently permitted (`hasMore && !loading && !paused`) —
450
+ /** Auto-load is currently permitted (`hasMore && !loading && !paused`, and
451
+ * no load error) —
451
452
  * used to gate an infinite-scroll sentinel. */
452
453
  canLoadMore: boolean;
453
454
  /** Advance one page *without* resuming a paused auto-load (the sentinel
@@ -482,7 +483,10 @@ export function useLoadControls(): LoadControls {
482
483
  const paused =
483
484
  autoLoadPages != null &&
484
485
  loadedCount - resumeBaseline >= autoLoadPages * pageSize;
485
- const canLoadMore = hasMore && !footer.loading && !paused;
486
+ // A failed chunk leaves its rows null, so without the error check the
487
+ // sentinel re-requests it forever.
488
+ const canLoadMore =
489
+ hasMore && !footer.loading && !paused && footer.error == null;
486
490
 
487
491
  const advance = useCallback(() => {
488
492
  setVisibleRegion({