@macrostrat/data-sheet 4.11.1 → 4.11.3
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 +23 -0
- package/dist/components/indicators/index.d.ts +1 -0
- package/dist/components/indicators/load-error.cjs +28 -0
- package/dist/components/indicators/load-error.cjs.map +1 -0
- package/dist/components/indicators/load-error.d.ts +10 -0
- package/dist/components/indicators/load-error.js +28 -0
- package/dist/components/indicators/load-error.js.map +1 -0
- package/dist/data-panel.cjs +2 -15
- package/dist/data-panel.cjs.map +1 -1
- package/dist/data-panel.js +2 -15
- package/dist/data-panel.js.map +1 -1
- package/dist/data-sheet.cjs +35 -30
- package/dist/data-sheet.cjs.map +1 -1
- package/dist/data-sheet.css +58 -40
- package/dist/data-sheet.js +35 -30
- package/dist/data-sheet.js.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +15 -14
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +15 -14
- package/dist/main.module.sass.js.map +1 -1
- package/dist/postgrest-table/data-loaders.cjs +1 -0
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.js +1 -0
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/main.module.sass.cjs +15 -14
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +15 -14
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/renderers/cell-renderer.cjs +8 -4
- package/dist/renderers/cell-renderer.cjs.map +1 -1
- package/dist/renderers/cell-renderer.js +8 -4
- package/dist/renderers/cell-renderer.js.map +1 -1
- package/dist/renderers/column-header-cell.cjs +18 -10
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.js +9 -1
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/utils/key-handling.cjs +2 -3
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +2 -1
- package/dist/utils/key-handling.js +2 -3
- package/dist/utils/key-handling.js.map +1 -1
- package/package.json +2 -2
- package/src/components/indicators/index.ts +1 -0
- package/src/components/indicators/load-error.ts +28 -0
- package/src/data-panel.ts +1 -18
- package/src/data-sheet.ts +34 -29
- package/src/main.module.sass +9 -0
- package/src/postgrest-table/data-loaders.ts +4 -1
- package/src/postgrest-table/main.module.sass +9 -0
- package/src/renderers/cell-renderer.ts +10 -5
- package/src/renderers/column-header-cell.ts +15 -1
- package/src/utils/key-handling.ts +4 -7
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import h from "../../postgrest-table/main.module.sass";
|
|
2
|
+
import { Button, NonIdealState } from "@blueprintjs/core";
|
|
3
|
+
import { useLoadControls } from "../../postgrest-table";
|
|
4
|
+
import { ctx, dataRefreshTokenAtom } from "../../provider";
|
|
5
|
+
|
|
6
|
+
/** A failed load, with a retry: loading stays off after an error, so
|
|
7
|
+
* reloading is the user's call. */
|
|
8
|
+
export function LoadErrorState({ error }: { error: Error }) {
|
|
9
|
+
const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);
|
|
10
|
+
return h(NonIdealState, {
|
|
11
|
+
icon: "error",
|
|
12
|
+
title: "Couldn't load data",
|
|
13
|
+
description: error.message ?? "The data source returned an error.",
|
|
14
|
+
action: h(
|
|
15
|
+
Button,
|
|
16
|
+
{ icon: "refresh", onClick: () => bumpRefresh((v) => v + 1) },
|
|
17
|
+
"Try again",
|
|
18
|
+
),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `LoadErrorState` over a table body that has no rows to show. Once rows are
|
|
23
|
+
* loaded, a later failure is reported by the footer instead. */
|
|
24
|
+
export function LoadErrorOverlay() {
|
|
25
|
+
const { error, loaded } = useLoadControls();
|
|
26
|
+
if (error == null || loaded > 0) return null;
|
|
27
|
+
return h("div.load-error-overlay", h(LoadErrorState, { error }));
|
|
28
|
+
}
|
package/src/data-panel.ts
CHANGED
|
@@ -38,7 +38,6 @@ import {
|
|
|
38
38
|
} from "react";
|
|
39
39
|
import {
|
|
40
40
|
AnchorButton,
|
|
41
|
-
Button,
|
|
42
41
|
Classes,
|
|
43
42
|
Icon,
|
|
44
43
|
NonIdealState,
|
|
@@ -49,7 +48,6 @@ import {
|
|
|
49
48
|
anchorRefAtom,
|
|
50
49
|
ctx,
|
|
51
50
|
dataProviderAtom,
|
|
52
|
-
dataRefreshTokenAtom,
|
|
53
51
|
DataSheetProvider,
|
|
54
52
|
DataViewRendererType,
|
|
55
53
|
FetchData,
|
|
@@ -73,6 +71,7 @@ import {
|
|
|
73
71
|
import classNames from "classnames";
|
|
74
72
|
import {
|
|
75
73
|
ActionsToolbar,
|
|
74
|
+
LoadErrorState,
|
|
76
75
|
LoadProgressIndicator,
|
|
77
76
|
useDataPanelControls,
|
|
78
77
|
type ViewControlsPresentation,
|
|
@@ -560,22 +559,6 @@ function modifiersOf(arg?: SelectModifiers | ReactMouseEvent): SelectModifiers {
|
|
|
560
559
|
return arg;
|
|
561
560
|
}
|
|
562
561
|
|
|
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
|
-
|
|
579
562
|
/**
|
|
580
563
|
* Bottom-sentinel infinite-scroll hook (no `react-intersection-observer`
|
|
581
564
|
* dependency). Calls `onVisible` when the observed element is on screen, and —
|
package/src/data-sheet.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
useRef,
|
|
16
16
|
} from "react";
|
|
17
17
|
import {
|
|
18
|
+
LoadErrorOverlay,
|
|
18
19
|
LoadProgressIndicator,
|
|
19
20
|
ActionsToolbar,
|
|
20
21
|
ActiveFiltersList,
|
|
@@ -208,7 +209,7 @@ export function DataSheetRenderer<T>({
|
|
|
208
209
|
|
|
209
210
|
// This is quite hacky!
|
|
210
211
|
const hotkeysConfig = useMemo(() => {
|
|
211
|
-
return getHotkeys();
|
|
212
|
+
return getHotkeys(_actions);
|
|
212
213
|
}, [_actions]);
|
|
213
214
|
|
|
214
215
|
const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeysConfig);
|
|
@@ -574,34 +575,38 @@ export function DataSheetRenderer<T>({
|
|
|
574
575
|
ref: tableElementRef,
|
|
575
576
|
style: holderStyle,
|
|
576
577
|
},
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
578
|
+
[
|
|
579
|
+
// Inside the holder, so the toolbar and filters stay reachable.
|
|
580
|
+
h.if(_showLoadProgress)(LoadErrorOverlay),
|
|
581
|
+
h(
|
|
582
|
+
Table as any, // Some sort of hyperscript type error
|
|
583
|
+
{
|
|
584
|
+
ref,
|
|
585
|
+
numRows,
|
|
586
|
+
className: "data-sheet",
|
|
587
|
+
enableFocusedCell,
|
|
588
|
+
enableColumnReordering,
|
|
589
|
+
onColumnsReordered,
|
|
590
|
+
focusedCell,
|
|
591
|
+
selectedRegions,
|
|
592
|
+
defaultRowHeight: rowHeight,
|
|
593
|
+
columnWidths,
|
|
594
|
+
onColumnWidthChanged,
|
|
595
|
+
onSelection,
|
|
596
|
+
/** TODO: we could enable this if we had a use-case */
|
|
597
|
+
enableRowReordering: false,
|
|
598
|
+
enableRowResizing: false,
|
|
599
|
+
// The cell renderer is memoized internally based on these data dependencies
|
|
600
|
+
cellRendererDependencies,
|
|
601
|
+
onVisibleCellsChange: _onVisibleCellsChange,
|
|
602
|
+
rowHeaderCellRenderer,
|
|
603
|
+
selectionModes: _selectionModes,
|
|
604
|
+
...tableProps,
|
|
605
|
+
getCellClipboardData: null,
|
|
606
|
+
},
|
|
607
|
+
realizedColumns,
|
|
608
|
+
),
|
|
609
|
+
],
|
|
605
610
|
),
|
|
606
611
|
h("div.status-bar", [
|
|
607
612
|
filterStatus,
|
package/src/main.module.sass
CHANGED
|
@@ -84,6 +84,11 @@
|
|
|
84
84
|
color: var(--pz-text-subtle-color, var(--secondary-color)) !important
|
|
85
85
|
font-style: italic
|
|
86
86
|
|
|
87
|
+
// Locked columns in an editable sheet: dimmed, not italic, so they read apart
|
|
88
|
+
// from derived ones.
|
|
89
|
+
.readonly-cell
|
|
90
|
+
color: var(--pz-text-subtle-color, var(--secondary-color)) !important
|
|
91
|
+
|
|
87
92
|
.value-viewer-cell
|
|
88
93
|
:global(.bp6-popover-target)
|
|
89
94
|
width: 100%
|
|
@@ -145,3 +150,7 @@
|
|
|
145
150
|
padding: 0.2em 0.5em
|
|
146
151
|
gap: 0.5em
|
|
147
152
|
background-color: var(--panel-secondary-background-color)
|
|
153
|
+
|
|
154
|
+
// Anchors the load-error overlay to the table body.
|
|
155
|
+
.data-sheet-holder
|
|
156
|
+
position: relative
|
|
@@ -368,7 +368,6 @@ const defaultVisibleRegion: RowRegion = {
|
|
|
368
368
|
/** Atom to house the current visible region of the table */
|
|
369
369
|
const visibleRegionAtom = atom<RowRegion>(defaultVisibleRegion);
|
|
370
370
|
|
|
371
|
-
|
|
372
371
|
/** Current page index (0-based) for paged fetch mode. */
|
|
373
372
|
export const chunkPageAtom = atom(0);
|
|
374
373
|
|
|
@@ -769,6 +768,10 @@ export function useDataLoader<T = any>(
|
|
|
769
768
|
|
|
770
769
|
useAsyncEffect(async () => {
|
|
771
770
|
if (state.loading) return;
|
|
771
|
+
// A failed load is final until the view is reset (a sort or filter change,
|
|
772
|
+
// or a refresh). Without this, whatever re-runs the effect requests the
|
|
773
|
+
// same chunk again, for as long as the source keeps failing.
|
|
774
|
+
if (state.error != null) return;
|
|
772
775
|
|
|
773
776
|
// A seed hasn't landed in state yet. Every effect in a commit sees the
|
|
774
777
|
// render's snapshot, so this one runs *before* the seed it was mounted
|
|
@@ -79,3 +79,12 @@
|
|
|
79
79
|
.tag-cell-content
|
|
80
80
|
line-height: 1
|
|
81
81
|
|
|
82
|
+
// Covers a table body that has nothing to show after a failed load.
|
|
83
|
+
.load-error-overlay
|
|
84
|
+
position: absolute
|
|
85
|
+
inset: 0
|
|
86
|
+
z-index: 30
|
|
87
|
+
display: flex
|
|
88
|
+
align-items: center
|
|
89
|
+
justify-content: center
|
|
90
|
+
background-color: var(--data-sheet-cell-background-color-internal, var(--background-color))
|
|
@@ -174,8 +174,13 @@ export function basicCellRenderer<T>(
|
|
|
174
174
|
col.cellDetail != null ? (col.detailPresentation ?? "popover") : null;
|
|
175
175
|
|
|
176
176
|
// Derived values are drawn dimmed, so a reader can tell a record from a
|
|
177
|
-
// restatement of one.
|
|
178
|
-
|
|
177
|
+
// restatement of one. Locked columns in an editable sheet are dimmed too.
|
|
178
|
+
// Applied on every path below.
|
|
179
|
+
const locked = tableIsEditable && col.editable === false && !col.derived;
|
|
180
|
+
const valueClass = classNames({
|
|
181
|
+
"derived-cell": col.derived,
|
|
182
|
+
"readonly-cell": locked,
|
|
183
|
+
});
|
|
179
184
|
|
|
180
185
|
// Fast path — any non-focused cell whose *unfocused* appearance is just the
|
|
181
186
|
// value viewer (a plain Blueprint `Cell`). That's everything except a custom
|
|
@@ -196,7 +201,7 @@ export function basicCellRenderer<T>(
|
|
|
196
201
|
loading,
|
|
197
202
|
//value,
|
|
198
203
|
style,
|
|
199
|
-
className:
|
|
204
|
+
className: valueClass,
|
|
200
205
|
interactive: false,
|
|
201
206
|
//disabled: tableIsEditable && !editable,
|
|
202
207
|
},
|
|
@@ -277,7 +282,7 @@ export function basicCellRenderer<T>(
|
|
|
277
282
|
loading,
|
|
278
283
|
value,
|
|
279
284
|
style,
|
|
280
|
-
className:
|
|
285
|
+
className: valueClass,
|
|
281
286
|
disabled: tableIsEditable && !editable,
|
|
282
287
|
interactive: false,
|
|
283
288
|
...cellComponentProps,
|
|
@@ -412,7 +417,7 @@ export function basicCellRenderer<T>(
|
|
|
412
417
|
if (_dataEditor != null) {
|
|
413
418
|
cellContents = _dataEditor;
|
|
414
419
|
}
|
|
415
|
-
const className = classNames("value-viewer-cell",
|
|
420
|
+
const className = classNames("value-viewer-cell", valueClass);
|
|
416
421
|
|
|
417
422
|
return h(
|
|
418
423
|
_Cell,
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
import h from "@macrostrat/hyper";
|
|
10
10
|
import { ColumnHeaderCell, RegionCardinality } from "@blueprintjs/table";
|
|
11
11
|
import { Icon, Menu, MenuItem } from "@blueprintjs/core";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
ctx,
|
|
14
|
+
tableActionsAtom,
|
|
15
|
+
useSelector,
|
|
16
|
+
type ColumnSpec,
|
|
17
|
+
} from "../provider";
|
|
13
18
|
import type {
|
|
14
19
|
PostgrestColumnFilter,
|
|
15
20
|
ColumnSortEntry,
|
|
@@ -92,6 +97,9 @@ export function renderColumnHeaderCell({
|
|
|
92
97
|
* exposed as `data-column-key` so consumers can target a specific header from
|
|
93
98
|
* CSS (e.g. to tint a column) without a bespoke styling prop. */
|
|
94
99
|
function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
|
|
100
|
+
// Only meaningful when the rest of the sheet takes edits.
|
|
101
|
+
const tableEditable = useSelector((s) => s.editable);
|
|
102
|
+
const locked = tableEditable && col.editable === false && !col.derived;
|
|
95
103
|
return h(
|
|
96
104
|
"div",
|
|
97
105
|
{
|
|
@@ -120,6 +128,12 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
|
|
|
120
128
|
title: "Derived — computed from other values, not editable",
|
|
121
129
|
style: { marginLeft: "4px", flexShrink: 0, opacity: 0.6 },
|
|
122
130
|
}),
|
|
131
|
+
h.if(locked)(Icon, {
|
|
132
|
+
icon: "lock",
|
|
133
|
+
size: 12,
|
|
134
|
+
title: "Not editable",
|
|
135
|
+
style: { marginLeft: "4px", flexShrink: 0, opacity: 0.6 },
|
|
136
|
+
}),
|
|
123
137
|
h.if(hasSortActive || hasFilterActive)(
|
|
124
138
|
"span",
|
|
125
139
|
{
|
|
@@ -2,13 +2,12 @@ import type { KeyboardEvent } from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
storeAPIAtom,
|
|
4
4
|
storeAtom,
|
|
5
|
-
tableActionsAtom,
|
|
6
5
|
type DataSheetStoreMain,
|
|
7
6
|
singleFocusedCell,
|
|
8
7
|
ctx,
|
|
9
8
|
} from "../provider";
|
|
10
9
|
import { atom } from "jotai";
|
|
11
|
-
import { runActionWrapper } from "../actions";
|
|
10
|
+
import { runActionWrapper, type TableAction } from "../actions";
|
|
12
11
|
import { actionRequiresEditable } from "../actions/selection.ts";
|
|
13
12
|
import { HotkeyConfig } from "@blueprintjs/core";
|
|
14
13
|
import { toasterAtom } from "../notifications.ts";
|
|
@@ -30,16 +29,14 @@ const hasSelectionAtom = atom((get) => {
|
|
|
30
29
|
return selection.length > 0;
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
// Actions are passed in: tableActionsAtom is synced in an effect, so it lags a render.
|
|
33
|
+
export const tableHotkeysAtom = atom<null, [TableAction[]], HotkeyConfig[]>(
|
|
34
34
|
null,
|
|
35
|
-
(get, set) => {
|
|
35
|
+
(get, set, tableActions) => {
|
|
36
36
|
const store = get(storeAPIAtom);
|
|
37
37
|
const toaster = get(toasterAtom);
|
|
38
38
|
const editable = get(isEditableAtom);
|
|
39
39
|
|
|
40
|
-
/** Set up hotkeys for table actions */
|
|
41
|
-
const tableActions = get(tableActionsAtom);
|
|
42
|
-
|
|
43
40
|
if (store == null) return [];
|
|
44
41
|
const keyHandler = (
|
|
45
42
|
actionRunner: HotkeyActionRunner,
|