@macrostrat/data-sheet 3.1.0 → 4.0.0-dev2

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 (184) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/actions/builtin.cjs +56 -0
  3. package/dist/actions/builtin.cjs.map +1 -0
  4. package/dist/actions/builtin.d.ts +15 -0
  5. package/dist/actions/builtin.js +56 -0
  6. package/dist/actions/builtin.js.map +1 -0
  7. package/dist/actions/clipboard.cjs +250 -0
  8. package/dist/actions/clipboard.cjs.map +1 -0
  9. package/dist/actions/clipboard.d.ts +42 -0
  10. package/dist/actions/clipboard.js +250 -0
  11. package/dist/actions/clipboard.js.map +1 -0
  12. package/dist/actions/filters.cjs +123 -0
  13. package/dist/actions/filters.cjs.map +1 -0
  14. package/dist/actions/filters.d.ts +6 -0
  15. package/dist/actions/filters.js +123 -0
  16. package/dist/actions/filters.js.map +1 -0
  17. package/dist/actions/index.d.ts +6 -0
  18. package/dist/actions/selection.cjs +194 -0
  19. package/dist/actions/selection.cjs.map +1 -0
  20. package/dist/actions/selection.d.ts +40 -0
  21. package/dist/actions/selection.js +192 -0
  22. package/dist/actions/selection.js.map +1 -0
  23. package/dist/actions/toolbar.cjs +171 -0
  24. package/dist/actions/toolbar.cjs.map +1 -0
  25. package/dist/actions/toolbar.d.ts +10 -0
  26. package/dist/actions/toolbar.js +171 -0
  27. package/dist/actions/toolbar.js.map +1 -0
  28. package/dist/actions/toolbar.module.sass.cjs +22 -0
  29. package/dist/actions/toolbar.module.sass.cjs.map +1 -0
  30. package/dist/actions/toolbar.module.sass.js +20 -0
  31. package/dist/actions/toolbar.module.sass.js.map +1 -0
  32. package/dist/actions/types.d.ts +143 -0
  33. package/dist/cell-renderer.cjs +44 -41
  34. package/dist/cell-renderer.cjs.map +1 -1
  35. package/dist/cell-renderer.d.ts +1 -6
  36. package/dist/cell-renderer.js +45 -42
  37. package/dist/cell-renderer.js.map +1 -1
  38. package/dist/components/actions.module.sass.cjs +3 -3
  39. package/dist/components/actions.module.sass.js +2 -2
  40. package/dist/components/colors.cjs +20 -16
  41. package/dist/components/colors.cjs.map +1 -1
  42. package/dist/components/colors.d.ts +3 -2
  43. package/dist/components/colors.js +20 -16
  44. package/dist/components/colors.js.map +1 -1
  45. package/dist/components/editor-popup.cjs +4 -3
  46. package/dist/components/editor-popup.cjs.map +1 -1
  47. package/dist/components/editor-popup.js +4 -3
  48. package/dist/components/editor-popup.js.map +1 -1
  49. package/dist/components/index.d.ts +1 -0
  50. package/dist/components/main.module.sass.cjs +12 -12
  51. package/dist/components/main.module.sass.js +11 -11
  52. package/dist/components/text-areas.cjs +23 -18
  53. package/dist/components/text-areas.cjs.map +1 -1
  54. package/dist/components/text-areas.d.ts +8 -4
  55. package/dist/components/text-areas.js +20 -13
  56. package/dist/components/text-areas.js.map +1 -1
  57. package/dist/components/view-info.cjs +18 -0
  58. package/dist/components/view-info.cjs.map +1 -0
  59. package/dist/components/view-info.d.ts +1 -0
  60. package/dist/components/view-info.js +18 -0
  61. package/dist/components/view-info.js.map +1 -0
  62. package/dist/core.cjs +184 -156
  63. package/dist/core.cjs.map +1 -1
  64. package/dist/core.d.ts +14 -1
  65. package/dist/core.js +187 -157
  66. package/dist/core.js.map +1 -1
  67. package/dist/data-sheet.css +181 -43
  68. package/dist/index.cjs +43 -13
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.ts +1 -0
  71. package/dist/index.js +43 -10
  72. package/dist/index.js.map +1 -1
  73. package/dist/main.module.sass.cjs +15 -14
  74. package/dist/main.module.sass.cjs.map +1 -1
  75. package/dist/main.module.sass.js +14 -13
  76. package/dist/main.module.sass.js.map +1 -1
  77. package/dist/notifications.cjs +19 -0
  78. package/dist/notifications.cjs.map +1 -0
  79. package/dist/notifications.d.ts +9 -0
  80. package/dist/notifications.js +19 -0
  81. package/dist/notifications.js.map +1 -0
  82. package/dist/postgrest-table/data-loaders.cjs +181 -104
  83. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  84. package/dist/postgrest-table/data-loaders.d.ts +52 -28
  85. package/dist/postgrest-table/data-loaders.js +181 -104
  86. package/dist/postgrest-table/data-loaders.js.map +1 -1
  87. package/dist/postgrest-table/index.cjs +205 -79
  88. package/dist/postgrest-table/index.cjs.map +1 -1
  89. package/dist/postgrest-table/index.d.ts +13 -16
  90. package/dist/postgrest-table/index.js +186 -58
  91. package/dist/postgrest-table/index.js.map +1 -1
  92. package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
  93. package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
  94. package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
  95. package/dist/postgrest-table/lazy-loader-table.js +17 -14
  96. package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
  97. package/dist/postgrest-table/loading-utils.cjs +16 -0
  98. package/dist/postgrest-table/loading-utils.cjs.map +1 -0
  99. package/dist/postgrest-table/loading-utils.d.ts +13 -0
  100. package/dist/postgrest-table/loading-utils.js +16 -0
  101. package/dist/postgrest-table/loading-utils.js.map +1 -0
  102. package/dist/postgrest-table/main.module.sass.cjs +18 -13
  103. package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
  104. package/dist/postgrest-table/main.module.sass.js +18 -13
  105. package/dist/postgrest-table/main.module.sass.js.map +1 -1
  106. package/dist/provider.cjs +58 -26
  107. package/dist/provider.cjs.map +1 -1
  108. package/dist/provider.js +57 -23
  109. package/dist/provider.js.map +1 -1
  110. package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
  111. package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
  112. package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
  113. package/dist/renderers/column-header-cell-postgrest.js +216 -0
  114. package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
  115. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
  116. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
  117. package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
  118. package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
  119. package/dist/renderers/column-header-cell.cjs +103 -0
  120. package/dist/renderers/column-header-cell.cjs.map +1 -0
  121. package/dist/renderers/column-header-cell.d.ts +30 -0
  122. package/dist/renderers/column-header-cell.js +101 -0
  123. package/dist/renderers/column-header-cell.js.map +1 -0
  124. package/dist/renderers/index.d.ts +2 -0
  125. package/dist/table-updates/data-parameter.d.ts +14 -0
  126. package/dist/table-updates/filter.d.ts +16 -0
  127. package/dist/table-updates/index.d.ts +19 -0
  128. package/dist/types.cjs +9 -0
  129. package/dist/types.cjs.map +1 -0
  130. package/dist/types.d.ts +58 -4
  131. package/dist/types.js +9 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/utils/column-spec.cjs +9 -1
  134. package/dist/utils/column-spec.cjs.map +1 -1
  135. package/dist/utils/column-spec.d.ts +21 -0
  136. package/dist/utils/column-spec.js +9 -1
  137. package/dist/utils/column-spec.js.map +1 -1
  138. package/dist/utils/key-handling.cjs +141 -52
  139. package/dist/utils/key-handling.cjs.map +1 -1
  140. package/dist/utils/key-handling.d.ts +2 -3
  141. package/dist/utils/key-handling.js +142 -53
  142. package/dist/utils/key-handling.js.map +1 -1
  143. package/dist/zustand-store.cjs +216 -51
  144. package/dist/zustand-store.cjs.map +1 -1
  145. package/dist/zustand-store.js +197 -32
  146. package/dist/zustand-store.js.map +1 -1
  147. package/package.json +5 -5
  148. package/src/actions/builtin.ts +65 -0
  149. package/src/actions/clipboard.ts +350 -0
  150. package/src/actions/filters.ts +150 -0
  151. package/src/actions/index.ts +6 -0
  152. package/src/actions/selection.ts +271 -0
  153. package/src/actions/toolbar.module.sass +30 -0
  154. package/src/actions/toolbar.ts +212 -0
  155. package/src/actions/types.ts +159 -0
  156. package/src/cell-renderer.ts +55 -51
  157. package/src/components/colors.ts +22 -19
  158. package/src/components/editor-popup.ts +3 -2
  159. package/src/components/index.ts +1 -0
  160. package/src/components/main.module.sass +1 -0
  161. package/src/components/text-areas.ts +34 -19
  162. package/src/components/view-info.ts +17 -0
  163. package/src/core.ts +243 -170
  164. package/src/index.ts +1 -0
  165. package/src/main.module.sass +14 -2
  166. package/src/notifications.ts +22 -0
  167. package/src/postgrest-table/data-loaders.ts +300 -201
  168. package/src/postgrest-table/index.ts +258 -84
  169. package/src/postgrest-table/lazy-loader-table.ts +18 -17
  170. package/src/postgrest-table/loading-utils.ts +49 -0
  171. package/src/postgrest-table/main.module.sass +16 -0
  172. package/src/provider.ts +63 -20
  173. package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
  174. package/src/renderers/column-header-cell-postgrest.ts +282 -0
  175. package/src/renderers/column-header-cell.ts +388 -0
  176. package/src/renderers/index.ts +2 -0
  177. package/src/table-updates/data-parameter.ts +44 -0
  178. package/src/table-updates/filter.ts +124 -0
  179. package/src/table-updates/index.ts +239 -0
  180. package/src/types.ts +58 -3
  181. package/src/utils/column-spec.ts +47 -0
  182. package/src/utils/key-handling.ts +181 -72
  183. package/src/zustand-store.ts +241 -36
  184. package/dist/provider.d.ts +0 -15
@@ -1,37 +1,44 @@
1
- import { HotkeysProvider, OverlayToaster } from "@blueprintjs/core";
2
- import hyper from "@macrostrat/hyper";
3
- import styles from "./main.module.sass";
4
- import { DataSheet, getRowsToDelete } from "../core"; //getRowsToDelete
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 { PostgrestOrder, usePostgRESTLazyLoader } from "./data-loaders";
7
- import { Spinner, InputGroup } from "@blueprintjs/core";
8
-
9
- export * from "./data-loaders";
10
- export * from "./lazy-loader-table";
11
- import { useCallback, useState, useRef } from "react";
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
26
  import { PostgrestFilterBuilder } from "@supabase/postgrest-js";
20
- import type {
21
- GenericFunction,
22
- GenericTable,
23
- GenericView,
24
- } from "@supabase/postgrest-js/dist/cjs/index";
25
- import { ColorCell } from "../components";
27
+ import { ColorCell, InfoBar } from "../components";
26
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";
27
39
 
28
- const h = hyper.styled(styles);
29
-
30
- export type GenericSchema = {
31
- Tables: Record<string, GenericTable>;
32
- Views: Record<string, GenericView>;
33
- Functions: Record<string, GenericFunction>;
34
- };
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(HotkeysProvider, h(ToasterContext, h(_PostgRESTTableView, props))),
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 = "id",
117
+ identityKey = null,
73
118
  ...rest
74
119
  }: PostgRESTTableViewProps<T>) {
75
- const [input, setInput] = useState("");
120
+ // Boundary of Jotai store
121
+ ctx.useSync(enableFullTextSearchAtom, enableFullTableSearch);
76
122
 
77
- if (enableFullTableSearch) {
78
- const columnList = columns ?? getColumnList(endpoint, table);
79
-
80
- filter = (query) => {
81
- const urlParams = new URLSearchParams(query.url.search);
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
- if (input.length > 2 && enableFullTableSearch) {
86
- const conditions = columnList?.map((col) => `${col}.ilike.*${input}*`);
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
- return query.or(conditions.join(","));
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
- return query;
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, onScroll, dispatch, client } = usePostgRESTLazyLoader(
154
+ const { data, dispatch, getClient } = usePostgRESTLazyLoader(
96
155
  endpoint,
97
156
  table,
98
157
  {
99
- order: order ?? { key: identityKey, ascending: true },
158
+ order: _order,
100
159
  columns,
101
- filter,
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
- if (data == null) {
123
- return h(Spinner);
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("div.data-sheet-outer", [
127
- h(DataSheet, {
232
+ return h(
233
+ DataSheet,
234
+ {
128
235
  ...rest,
129
236
  dataSheetActions: enableFullTableSearch
130
- ? h(SearchAction, { input, setInput, dispatch })
237
+ ? h(SearchAction)
131
238
  : dataSheetActions,
132
- data,
133
- columnSpecOptions: columnOptions ?? {},
239
+ columnSpecOptions: columnOptions,
134
240
  editable,
135
- onVisibleCellsChange: onScroll,
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({ input, setInput, dispatch }) {
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
- const search = event.target.value;
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
- function getColumnList(endpoint: string, table: string) {
284
- const url = `${endpoint}/${table}?select=*&limit=1`;
285
- const res = useAPIResult(url);
286
-
287
- if (!res || !Array.isArray(res) || res.length === 0) return [];
288
-
289
- const sampleRow = res[0];
290
-
291
- return Object.entries(sampleRow)
292
- .filter(([_, value]) => {
293
- return typeof value === "string";
294
- })
295
- .map(([key]) => key);
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 hyper from "@macrostrat/hyper";
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(DataSheet, {
18
- ...rest,
19
- data,
20
- editable: false,
21
- onVisibleCellsChange: onScroll,
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
+