@macrostrat/data-sheet 3.0.4 → 4.0.0-dev1
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 +20 -1
- package/dist/actions/builtin.cjs +56 -0
- package/dist/actions/builtin.cjs.map +1 -0
- package/dist/actions/builtin.d.ts +15 -0
- package/dist/actions/builtin.js +56 -0
- package/dist/actions/builtin.js.map +1 -0
- package/dist/actions/clipboard.cjs +250 -0
- package/dist/actions/clipboard.cjs.map +1 -0
- package/dist/actions/clipboard.d.ts +42 -0
- package/dist/actions/clipboard.js +250 -0
- package/dist/actions/clipboard.js.map +1 -0
- package/dist/actions/filters.cjs +123 -0
- package/dist/actions/filters.cjs.map +1 -0
- package/dist/actions/filters.d.ts +6 -0
- package/dist/actions/filters.js +123 -0
- package/dist/actions/filters.js.map +1 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/selection.cjs +194 -0
- package/dist/actions/selection.cjs.map +1 -0
- package/dist/actions/selection.d.ts +40 -0
- package/dist/actions/selection.js +192 -0
- package/dist/actions/selection.js.map +1 -0
- package/dist/actions/toolbar.cjs +171 -0
- package/dist/actions/toolbar.cjs.map +1 -0
- package/dist/actions/toolbar.d.ts +10 -0
- package/dist/actions/toolbar.js +171 -0
- package/dist/actions/toolbar.js.map +1 -0
- package/dist/actions/toolbar.module.sass.cjs +22 -0
- package/dist/actions/toolbar.module.sass.cjs.map +1 -0
- package/dist/actions/toolbar.module.sass.js +20 -0
- package/dist/actions/toolbar.module.sass.js.map +1 -0
- package/dist/actions/types.d.ts +143 -0
- package/dist/cell-renderer.cjs +165 -0
- package/dist/cell-renderer.cjs.map +1 -0
- package/dist/cell-renderer.d.ts +3 -0
- package/dist/cell-renderer.js +165 -0
- package/dist/cell-renderer.js.map +1 -0
- package/dist/components/actions.module.sass.cjs +3 -3
- package/dist/components/actions.module.sass.js +2 -2
- package/dist/components/colors.cjs +20 -16
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.d.ts +4 -3
- package/dist/components/colors.js +20 -16
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +4 -3
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +4 -3
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/main.module.sass.cjs +12 -12
- package/dist/components/main.module.sass.js +11 -11
- package/dist/components/text-areas.cjs +23 -18
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.d.ts +8 -4
- package/dist/components/text-areas.js +20 -13
- package/dist/components/text-areas.js.map +1 -1
- package/dist/components/view-info.cjs +18 -0
- package/dist/components/view-info.cjs.map +1 -0
- package/dist/components/view-info.d.ts +1 -0
- package/dist/components/view-info.js +18 -0
- package/dist/components/view-info.js.map +1 -0
- package/dist/core.cjs +201 -300
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +18 -10
- package/dist/core.js +204 -299
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +190 -52
- package/dist/index.cjs +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +48 -9
- 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 +14 -13
- package/dist/main.module.sass.js.map +1 -1
- package/dist/notifications.cjs +19 -0
- package/dist/notifications.cjs.map +1 -0
- package/dist/notifications.d.ts +9 -0
- package/dist/notifications.js +19 -0
- package/dist/notifications.js.map +1 -0
- package/dist/postgrest-table/data-loaders.cjs +181 -104
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -28
- package/dist/postgrest-table/data-loaders.js +181 -104
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +205 -79
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +14 -17
- package/dist/postgrest-table/index.js +186 -58
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
- package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
- package/dist/postgrest-table/lazy-loader-table.js +17 -14
- package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
- package/dist/postgrest-table/loading-utils.cjs +16 -0
- package/dist/postgrest-table/loading-utils.cjs.map +1 -0
- package/dist/postgrest-table/loading-utils.d.ts +13 -0
- package/dist/postgrest-table/loading-utils.js +16 -0
- package/dist/postgrest-table/loading-utils.js.map +1 -0
- package/dist/postgrest-table/main.module.sass.cjs +18 -13
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +18 -13
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/provider.cjs +96 -344
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +96 -343
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
- package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
- package/dist/renderers/column-header-cell-postgrest.js +216 -0
- package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +103 -0
- package/dist/renderers/column-header-cell.cjs.map +1 -0
- package/dist/renderers/column-header-cell.d.ts +30 -0
- package/dist/renderers/column-header-cell.js +101 -0
- package/dist/renderers/column-header-cell.js.map +1 -0
- package/dist/renderers/index.d.ts +2 -0
- package/dist/table-updates/data-parameter.d.ts +14 -0
- package/dist/table-updates/filter.d.ts +16 -0
- package/dist/table-updates/index.d.ts +19 -0
- package/dist/types.cjs +9 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/column-spec.cjs +9 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +21 -0
- package/dist/utils/column-spec.js +9 -1
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/utils/key-handling.cjs +161 -47
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +3 -3
- package/dist/utils/key-handling.js +161 -47
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/zustand-store.cjs +485 -0
- package/dist/zustand-store.cjs.map +1 -0
- package/dist/zustand-store.d.ts +6 -0
- package/dist/zustand-store.js +483 -0
- package/dist/zustand-store.js.map +1 -0
- package/package.json +6 -5
- package/src/actions/builtin.ts +65 -0
- package/src/actions/clipboard.ts +350 -0
- package/src/actions/filters.ts +150 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/selection.ts +271 -0
- package/src/actions/toolbar.module.sass +30 -0
- package/src/actions/toolbar.ts +212 -0
- package/src/actions/types.ts +159 -0
- package/src/cell-renderer.ts +221 -0
- package/src/components/colors.ts +22 -19
- package/src/components/editor-popup.ts +3 -2
- package/src/components/index.ts +1 -0
- package/src/components/main.module.sass +1 -0
- package/src/components/text-areas.ts +34 -19
- package/src/components/view-info.ts +17 -0
- package/src/core.ts +273 -360
- package/src/index.ts +4 -0
- package/src/main.module.sass +14 -2
- package/src/notifications.ts +22 -0
- package/src/postgrest-table/data-loaders.ts +300 -201
- package/src/postgrest-table/index.ts +260 -86
- package/src/postgrest-table/lazy-loader-table.ts +18 -17
- package/src/postgrest-table/loading-utils.ts +49 -0
- package/src/postgrest-table/main.module.sass +16 -0
- package/src/provider.ts +110 -487
- package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
- package/src/renderers/column-header-cell-postgrest.ts +282 -0
- package/src/renderers/column-header-cell.ts +388 -0
- package/src/renderers/index.ts +2 -0
- package/src/table-updates/data-parameter.ts +44 -0
- package/src/table-updates/filter.ts +124 -0
- package/src/table-updates/index.ts +239 -0
- package/src/types.ts +121 -0
- package/src/utils/column-spec.ts +47 -0
- package/src/utils/key-handling.ts +201 -66
- package/src/zustand-store.ts +582 -0
- package/dist/provider.d.ts +0 -69
|
@@ -1,37 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
InputGroup,
|
|
4
|
+
OverlayToaster,
|
|
5
|
+
Tag as BPTag,
|
|
6
|
+
} from "@blueprintjs/core";
|
|
7
|
+
import h from "./main.module.sass";
|
|
8
|
+
import { DataSheet, getRowsToDelete } from "../core";
|
|
5
9
|
import { LithologyTag, Tag, TagSize } from "@macrostrat/data-components";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
ColumnSortEntry,
|
|
12
|
+
PostgrestColumnFilter,
|
|
13
|
+
PostgrestFilter,
|
|
14
|
+
PostgrestFilterOperator,
|
|
15
|
+
PostgrestOrder,
|
|
16
|
+
standardizeFilter,
|
|
17
|
+
usePostgRESTLazyLoader,
|
|
18
|
+
} from "./data-loaders";
|
|
19
|
+
import { useCallback, useMemo, useState } from "react";
|
|
12
20
|
import {
|
|
13
21
|
ErrorBoundary,
|
|
14
22
|
ToasterContext,
|
|
15
|
-
useAPIResult,
|
|
16
23
|
useToaster,
|
|
17
24
|
} from "@macrostrat/ui-components";
|
|
18
25
|
import { Spec } from "immutability-helper";
|
|
19
|
-
import { DataSheetProviderProps } from "../provider";
|
|
20
26
|
import { PostgrestFilterBuilder } from "@supabase/postgrest-js";
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
import { ColorCell, InfoBar } from "../components";
|
|
28
|
+
import { DataSheetProviderProps } from "../types.ts";
|
|
29
|
+
import {
|
|
30
|
+
type ColumnHeaderActions,
|
|
31
|
+
ColumnHeaderRendererProps,
|
|
32
|
+
OPERATOR_LABELS,
|
|
33
|
+
renderPostgRESTColumnHeaderCell,
|
|
34
|
+
} from "../renderers";
|
|
35
|
+
import { atom } from "jotai";
|
|
36
|
+
import { columnSpecAtom, ctx } from "../provider.ts";
|
|
37
|
+
import { TableAction } from "../actions";
|
|
38
|
+
import { RegionCardinality } from "@blueprintjs/table";
|
|
39
|
+
|
|
40
|
+
export * from "./data-loaders";
|
|
41
|
+
export * from "./lazy-loader-table";
|
|
35
42
|
|
|
36
43
|
interface PostgRESTTableViewProps<
|
|
37
44
|
T extends object,
|
|
@@ -39,26 +46,65 @@ interface PostgRESTTableViewProps<
|
|
|
39
46
|
endpoint: string;
|
|
40
47
|
table: string;
|
|
41
48
|
columnOptions?: any;
|
|
42
|
-
order?: PostgrestOrder<T
|
|
49
|
+
order?: PostgrestOrder<T> | PostgrestOrder<any>[];
|
|
43
50
|
columns?: string;
|
|
44
51
|
editable?: boolean;
|
|
45
52
|
identityKey?: string;
|
|
46
53
|
enableFullTableSearch?: boolean;
|
|
47
54
|
dataSheetActions?: any;
|
|
48
55
|
filter(
|
|
49
|
-
query: PostgrestFilterBuilder<T, any, any>,
|
|
50
|
-
): PostgrestFilterBuilder<T, any, any>;
|
|
56
|
+
query: PostgrestFilterBuilder<T, any, any, any>,
|
|
57
|
+
): PostgrestFilterBuilder<T, any, any, any>;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
export function PostgRESTTableView<T>(props: PostgRESTTableViewProps<T>) {
|
|
54
61
|
return h(
|
|
55
62
|
ErrorBoundary,
|
|
56
|
-
h(
|
|
63
|
+
h(ctx.Provider, h(ToasterContext, h(_PostgRESTTableView, props))),
|
|
57
64
|
);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
const successResponses = [200, 201];
|
|
61
68
|
|
|
69
|
+
const enableFullTextSearchAtom = atom(false);
|
|
70
|
+
|
|
71
|
+
const fullTextSearchInputAtom = atom("");
|
|
72
|
+
|
|
73
|
+
interface FtsFilterConfig {
|
|
74
|
+
text: string;
|
|
75
|
+
columns: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const fullTextSearchFilterConfigAtom = atom<FtsFilterConfig | null>((get) => {
|
|
79
|
+
const enable = get(enableFullTextSearchAtom);
|
|
80
|
+
const searchText = get(fullTextSearchInputAtom).toLowerCase();
|
|
81
|
+
console.log("Full text search", enable, searchText);
|
|
82
|
+
if (!enable || searchText.length < 3) return null;
|
|
83
|
+
const columnSpec = get(columnSpecAtom);
|
|
84
|
+
|
|
85
|
+
const columns = columnSpec
|
|
86
|
+
.filter((d) => d.dataType == "text")
|
|
87
|
+
.map((d) => d.key);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
text: searchText,
|
|
91
|
+
columns,
|
|
92
|
+
} as FtsFilterConfig;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function buildFilter(cfg: FtsFilterConfig | null): PostgrestFilter | null {
|
|
96
|
+
if (cfg == null) return null;
|
|
97
|
+
return {
|
|
98
|
+
type: "filter",
|
|
99
|
+
id: `fts-${cfg.text}`,
|
|
100
|
+
apply(res) {
|
|
101
|
+
const _filters = cfg.columns.map((d) => `${d}.ilike.*${cfg.text}*`);
|
|
102
|
+
const filters = _filters.join(",");
|
|
103
|
+
return res.or(filters);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
62
108
|
function _PostgRESTTableView<T>({
|
|
63
109
|
endpoint,
|
|
64
110
|
table,
|
|
@@ -66,39 +112,53 @@ function _PostgRESTTableView<T>({
|
|
|
66
112
|
order,
|
|
67
113
|
columns,
|
|
68
114
|
editable = false,
|
|
69
|
-
filter = undefined,
|
|
70
115
|
enableFullTableSearch = false,
|
|
71
116
|
dataSheetActions,
|
|
72
|
-
identityKey =
|
|
117
|
+
identityKey = null,
|
|
73
118
|
...rest
|
|
74
119
|
}: PostgRESTTableViewProps<T>) {
|
|
75
|
-
|
|
120
|
+
// Boundary of Jotai store
|
|
121
|
+
ctx.useSync(enableFullTextSearchAtom, enableFullTableSearch);
|
|
76
122
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
urlParams.delete("or");
|
|
83
|
-
query.url.search = urlParams.toString() ? `?${urlParams.toString()}` : "";
|
|
123
|
+
// Server-side column sort/filter state
|
|
124
|
+
const [columnSorts, setColumnSorts] = useState<ColumnSortEntry[]>([]);
|
|
125
|
+
const [columnFilters, setColumnFilters] = useState<PostgrestColumnFilter[]>(
|
|
126
|
+
[],
|
|
127
|
+
);
|
|
84
128
|
|
|
85
|
-
|
|
86
|
-
|
|
129
|
+
/** TODO: remove "full-text search" from filter options */
|
|
130
|
+
const ftsFilter = buildFilter(ctx.useValue(fullTextSearchFilterConfigAtom));
|
|
131
|
+
let filters = columnFilters.map(standardizeFilter);
|
|
132
|
+
if (ftsFilter != null) {
|
|
133
|
+
filters.push(ftsFilter);
|
|
134
|
+
}
|
|
87
135
|
|
|
88
|
-
|
|
89
|
-
|
|
136
|
+
const _order = [];
|
|
137
|
+
if (typeof order === "object" && "key" in order) {
|
|
138
|
+
_order.push(order);
|
|
139
|
+
} else if (Array.isArray(order)) {
|
|
140
|
+
_order.push(...order);
|
|
141
|
+
}
|
|
142
|
+
_order.push(...columnSorts);
|
|
90
143
|
|
|
91
|
-
|
|
92
|
-
|
|
144
|
+
// Infer identity key
|
|
145
|
+
let _identityKey = identityKey;
|
|
146
|
+
if (_identityKey == null) {
|
|
147
|
+
if (_order.length == 0) {
|
|
148
|
+
throw "Must specify identity key or order by column";
|
|
149
|
+
} else {
|
|
150
|
+
_identityKey = _order[0].key;
|
|
151
|
+
}
|
|
93
152
|
}
|
|
94
153
|
|
|
95
|
-
const { data,
|
|
154
|
+
const { data, dispatch, getClient } = usePostgRESTLazyLoader(
|
|
96
155
|
endpoint,
|
|
97
156
|
table,
|
|
98
157
|
{
|
|
99
|
-
order:
|
|
158
|
+
order: _order,
|
|
100
159
|
columns,
|
|
101
|
-
|
|
160
|
+
filters,
|
|
161
|
+
identityKey: _identityKey,
|
|
102
162
|
},
|
|
103
163
|
);
|
|
104
164
|
|
|
@@ -119,20 +179,66 @@ function _PostgRESTTableView<T>({
|
|
|
119
179
|
[dispatch, toaster],
|
|
120
180
|
);
|
|
121
181
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
182
|
+
// Column header actions for sort/filter
|
|
183
|
+
const columnHeaderActions: ColumnHeaderActions = useMemo(
|
|
184
|
+
() => ({
|
|
185
|
+
onSetSort(key: string, ascending: boolean | null) {
|
|
186
|
+
// Single-column sort: replace any existing sort
|
|
187
|
+
if (ascending == null) {
|
|
188
|
+
setColumnSorts([]);
|
|
189
|
+
} else {
|
|
190
|
+
setColumnSorts([{ key, ascending }]);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
onSetFilter(
|
|
194
|
+
key: string,
|
|
195
|
+
operator: PostgrestFilterOperator | null,
|
|
196
|
+
value: string,
|
|
197
|
+
) {
|
|
198
|
+
setColumnFilters((prev) => {
|
|
199
|
+
const without = prev.filter((f) => f.key !== key);
|
|
200
|
+
if (operator == null || value === "") return without;
|
|
201
|
+
return [...without, { key, operator, value }];
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
onClearColumn(key: string) {
|
|
205
|
+
setColumnSorts((prev) => prev.filter((s) => s.key !== key));
|
|
206
|
+
setColumnFilters((prev) => prev.filter((f) => f.key !== key));
|
|
207
|
+
},
|
|
208
|
+
}),
|
|
209
|
+
[],
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Column header cell renderer using sort/filter state
|
|
213
|
+
const columnHeaderCellRenderer = useCallback(
|
|
214
|
+
(props: ColumnHeaderRendererProps) => {
|
|
215
|
+
const { col, colIndex } = props;
|
|
216
|
+
const activeSort = columnSorts.find((s) => s.key === col.key);
|
|
217
|
+
const activeFilter = columnFilters.find((f) => f.key === col.key);
|
|
218
|
+
return renderPostgRESTColumnHeaderCell({
|
|
219
|
+
col,
|
|
220
|
+
colIndex,
|
|
221
|
+
activeSort,
|
|
222
|
+
activeFilter,
|
|
223
|
+
actions: columnHeaderActions,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
[columnSorts, columnFilters, columnHeaderActions],
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const hasActiveFilters = columnFilters.length > 0;
|
|
230
|
+
const hasActiveSort = columnSorts.length > 0;
|
|
125
231
|
|
|
126
|
-
return h(
|
|
127
|
-
|
|
232
|
+
return h(
|
|
233
|
+
DataSheet,
|
|
234
|
+
{
|
|
128
235
|
...rest,
|
|
129
236
|
dataSheetActions: enableFullTableSearch
|
|
130
|
-
? h(SearchAction
|
|
237
|
+
? h(SearchAction)
|
|
131
238
|
: dataSheetActions,
|
|
132
|
-
|
|
133
|
-
columnSpecOptions: columnOptions ?? {},
|
|
239
|
+
columnSpecOptions: columnOptions,
|
|
134
240
|
editable,
|
|
135
|
-
|
|
241
|
+
columnHeaderCellRenderer,
|
|
136
242
|
onDeleteRows(selection) {
|
|
137
243
|
if (!editable) return;
|
|
138
244
|
|
|
@@ -142,10 +248,8 @@ function _PostgRESTTableView<T>({
|
|
|
142
248
|
|
|
143
249
|
dispatch({ type: "start-loading" });
|
|
144
250
|
|
|
251
|
+
const client = getClient();
|
|
145
252
|
let query = client.delete().in(identityKey, ids);
|
|
146
|
-
|
|
147
|
-
query = filter?.(query) ?? query;
|
|
148
|
-
|
|
149
253
|
finishResponse(query, { $delete: Array.from(rowIndices.keys()) });
|
|
150
254
|
},
|
|
151
255
|
onSaveData(updates, data) {
|
|
@@ -162,18 +266,54 @@ function _PostgRESTTableView<T>({
|
|
|
162
266
|
}
|
|
163
267
|
|
|
164
268
|
dispatch({ type: "start-loading" });
|
|
165
|
-
|
|
269
|
+
const client = getClient();
|
|
166
270
|
// Save data
|
|
167
271
|
let query = client.upsert(updateRows, { defaultToNull: false });
|
|
168
|
-
|
|
169
|
-
query = filter?.(query) ?? query;
|
|
170
|
-
|
|
171
272
|
finishResponse(query, changes);
|
|
172
273
|
},
|
|
173
|
-
}
|
|
174
|
-
|
|
274
|
+
},
|
|
275
|
+
[
|
|
276
|
+
h.if(hasActiveFilters || hasActiveSort)(ServerFilterBar, {
|
|
277
|
+
columnSorts,
|
|
278
|
+
columnFilters,
|
|
279
|
+
onClearFilter(key: string) {
|
|
280
|
+
columnHeaderActions.onClearColumn(key);
|
|
281
|
+
},
|
|
282
|
+
onClearAll() {
|
|
283
|
+
setColumnSorts([]);
|
|
284
|
+
setColumnFilters([]);
|
|
285
|
+
},
|
|
286
|
+
}),
|
|
287
|
+
],
|
|
288
|
+
);
|
|
175
289
|
}
|
|
176
290
|
|
|
291
|
+
const saveDataAction: TableAction = {
|
|
292
|
+
id: "save-data",
|
|
293
|
+
name: "Save changes",
|
|
294
|
+
icon: "floppy-disk",
|
|
295
|
+
intent: "success",
|
|
296
|
+
requiresEditable: true,
|
|
297
|
+
targets: [RegionCardinality.FULL_TABLE],
|
|
298
|
+
async run(ctx) {
|
|
299
|
+
const data = ctx.data;
|
|
300
|
+
const updates = ctx.updatedData;
|
|
301
|
+
|
|
302
|
+
let changes: Spec<any[]> = {};
|
|
303
|
+
let updateRows: any[] = [];
|
|
304
|
+
for (let [key, update] of Object.entries(updates)) {
|
|
305
|
+
const value = { ...data[key], ...update };
|
|
306
|
+
updateRows.push(value);
|
|
307
|
+
changes[key] = { $set: value };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
dispatch({ type: "start-loading" });
|
|
311
|
+
const client = getClient();
|
|
312
|
+
// Save data
|
|
313
|
+
let query = client.upsert(updateRows, { defaultToNull: false });
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
|
|
177
317
|
export function notifyOnError(toaster: OverlayToaster, error: any) {
|
|
178
318
|
console.error(error);
|
|
179
319
|
const { message, status, code, details } = error;
|
|
@@ -265,32 +405,66 @@ export function ExpandedLithologies({ value, onChange }) {
|
|
|
265
405
|
]);
|
|
266
406
|
}
|
|
267
407
|
|
|
268
|
-
export function SearchAction(
|
|
408
|
+
export function SearchAction() {
|
|
409
|
+
const [input, setInput] = ctx.use(fullTextSearchInputAtom);
|
|
269
410
|
return h(InputGroup, {
|
|
270
411
|
type: "search",
|
|
271
412
|
placeholder: "Search table...",
|
|
272
413
|
value: input,
|
|
273
414
|
onChange(event) {
|
|
274
|
-
|
|
275
|
-
if (search.length > 2 || (input.length === 3 && search.length < 3)) {
|
|
276
|
-
dispatch({ type: "reset" });
|
|
277
|
-
}
|
|
278
|
-
setInput(search.toLowerCase());
|
|
415
|
+
setInput(event.target.value);
|
|
279
416
|
},
|
|
280
417
|
});
|
|
281
418
|
}
|
|
282
419
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
420
|
+
/** Bar showing active server-side sort and filter state as removable tags. */
|
|
421
|
+
function ServerFilterBar({
|
|
422
|
+
columnSorts,
|
|
423
|
+
columnFilters,
|
|
424
|
+
onClearFilter,
|
|
425
|
+
onClearAll,
|
|
426
|
+
}: {
|
|
427
|
+
columnSorts: ColumnSortEntry[];
|
|
428
|
+
columnFilters: PostgrestColumnFilter[];
|
|
429
|
+
onClearFilter: (key: string) => void;
|
|
430
|
+
onClearAll: () => void;
|
|
431
|
+
}) {
|
|
432
|
+
return h("div.server-filter-bar", [
|
|
433
|
+
columnSorts.map((s) =>
|
|
434
|
+
h(
|
|
435
|
+
BPTag,
|
|
436
|
+
{
|
|
437
|
+
key: `sort-${s.key}`,
|
|
438
|
+
icon: s.ascending ? "sort-asc" : "sort-desc",
|
|
439
|
+
intent: "primary",
|
|
440
|
+
onRemove: () => onClearFilter(s.key),
|
|
441
|
+
minimal: true,
|
|
442
|
+
},
|
|
443
|
+
`${s.key}: ${s.ascending ? "A→Z" : "Z→A"}`,
|
|
444
|
+
),
|
|
445
|
+
),
|
|
446
|
+
columnFilters.map((f) =>
|
|
447
|
+
h(
|
|
448
|
+
BPTag,
|
|
449
|
+
{
|
|
450
|
+
key: `filter-${f.key}`,
|
|
451
|
+
icon: "filter",
|
|
452
|
+
intent: "warning",
|
|
453
|
+
onRemove: () => onClearFilter(f.key),
|
|
454
|
+
minimal: true,
|
|
455
|
+
},
|
|
456
|
+
`${f.key} ${OPERATOR_LABELS[f.operator] ?? f.operator} ${f.value}`,
|
|
457
|
+
),
|
|
458
|
+
),
|
|
459
|
+
h(
|
|
460
|
+
Button,
|
|
461
|
+
{
|
|
462
|
+
minimal: true,
|
|
463
|
+
small: true,
|
|
464
|
+
icon: "cross",
|
|
465
|
+
onClick: onClearAll,
|
|
466
|
+
},
|
|
467
|
+
"Clear all",
|
|
468
|
+
),
|
|
469
|
+
]);
|
|
296
470
|
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import styles from "./main.module.sass";
|
|
1
|
+
import h from "./main.module.sass";
|
|
3
2
|
import { DataSheet } from "../core";
|
|
4
3
|
import { useTestLazyLoader } from "./data-loaders";
|
|
5
|
-
import { Spinner } from "@blueprintjs/core";
|
|
6
|
-
|
|
7
|
-
const h = hyper.styled(styles);
|
|
8
4
|
|
|
9
5
|
export function TestLazyLoaderTableView<T>({ ...rest }) {
|
|
10
|
-
const { data, onScroll } = useTestLazyLoader();
|
|
11
|
-
|
|
12
|
-
if (data == null) {
|
|
13
|
-
return h(Spinner);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
6
|
return h("div.data-sheet-outer", [
|
|
17
|
-
h(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
h(
|
|
8
|
+
DataSheet,
|
|
9
|
+
{
|
|
10
|
+
...rest,
|
|
11
|
+
editable: false,
|
|
12
|
+
},
|
|
13
|
+
[
|
|
14
|
+
h(TestLazyLoaderManager, {
|
|
15
|
+
key: "test-lazy-loader-manager",
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
),
|
|
23
19
|
]);
|
|
24
20
|
}
|
|
21
|
+
|
|
22
|
+
function TestLazyLoaderManager() {
|
|
23
|
+
useTestLazyLoader();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function adjustArraySize<T>(arr: T[], newSize: number) {
|
|
2
|
+
if (newSize == null || arr.length === newSize) {
|
|
3
|
+
return arr;
|
|
4
|
+
} else if (arr.length > newSize) {
|
|
5
|
+
// Trim the array
|
|
6
|
+
arr = arr.slice(0, newSize);
|
|
7
|
+
}
|
|
8
|
+
return [...arr, ...Array(newSize - arr.length).fill(null)];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RowRegion {
|
|
12
|
+
rowIndexStart: number;
|
|
13
|
+
rowIndexEnd: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
enum LoadDirection {
|
|
17
|
+
"up",
|
|
18
|
+
"down",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function overlapsNulls(data: any[], region: RowRegion) {
|
|
22
|
+
for (let i = region.rowIndexStart; i < region.rowIndexEnd; i++) {
|
|
23
|
+
if (data[i] == null) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function distanceToNextNonEmptyRow(
|
|
31
|
+
data: any[],
|
|
32
|
+
start: number,
|
|
33
|
+
direction: LoadDirection,
|
|
34
|
+
limit: number,
|
|
35
|
+
): number {
|
|
36
|
+
let i = start;
|
|
37
|
+
while (i < data.length && i > 0 && limit > 0) {
|
|
38
|
+
if (data[i] != null) {
|
|
39
|
+
return i;
|
|
40
|
+
}
|
|
41
|
+
i += direction === LoadDirection.down ? 1 : -1;
|
|
42
|
+
limit -= 1;
|
|
43
|
+
}
|
|
44
|
+
return i;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function sleep(ms: number) {
|
|
48
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
49
|
+
}
|
|
@@ -48,7 +48,23 @@
|
|
|
48
48
|
position: relative
|
|
49
49
|
flex: 1
|
|
50
50
|
display: flex
|
|
51
|
+
flex-direction: column
|
|
51
52
|
min-height: 0
|
|
52
53
|
|
|
54
|
+
.toolbar
|
|
55
|
+
display: flex
|
|
56
|
+
flex-direction: row
|
|
57
|
+
flex-wrap: wrap
|
|
58
|
+
gap: var(--data-sheet-toolbar-gap, 4px)
|
|
59
|
+
padding: var(--data-sheet-toolbar-gap, 4px) 0
|
|
60
|
+
|
|
61
|
+
.server-filter-bar
|
|
62
|
+
@extend .toolbar
|
|
63
|
+
|
|
64
|
+
.info-bar
|
|
65
|
+
@extend .toolbar
|
|
66
|
+
order: 10
|
|
67
|
+
|
|
53
68
|
.tag-cell-content
|
|
54
69
|
line-height: 1
|
|
70
|
+
|