@macrostrat/data-sheet 2.0.1 → 2.1.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.
Files changed (161) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +17 -10
  3. package/dist/esm/{postgrest-table.d1f8b3a4.js → data-sheet.00171fc5.js} +76 -61
  4. package/dist/esm/data-sheet.00171fc5.js.map +1 -0
  5. package/dist/esm/{utils.5d81fe80.js → data-sheet.0adfe599.js} +2 -2
  6. package/dist/esm/{utils.5d81fe80.js.map → data-sheet.0adfe599.js.map} +1 -1
  7. package/dist/esm/{editor-popup.819ce365.js → data-sheet.1d6ac6c6.js} +28 -8
  8. package/dist/esm/data-sheet.1d6ac6c6.js.map +1 -0
  9. package/dist/esm/{data-loaders.b7de291b.js → data-sheet.2773da15.js} +12 -3
  10. package/dist/esm/data-sheet.2773da15.js.map +1 -0
  11. package/dist/esm/{main.module.7e0903d4.js → data-sheet.37e35216.js} +16 -1
  12. package/dist/esm/data-sheet.37e35216.js.map +1 -0
  13. package/dist/esm/{column-spec.e56f4d75.js → data-sheet.410c5122.js} +20 -7
  14. package/dist/esm/data-sheet.410c5122.js.map +1 -0
  15. package/dist/esm/{main.module.83442ac4.js → data-sheet.48635112.js} +4 -1
  16. package/dist/esm/data-sheet.48635112.js.map +1 -0
  17. package/dist/esm/{actions.module.560a3136.js → data-sheet.54cfa8e8.js} +1 -1
  18. package/dist/esm/{actions.module.560a3136.js.map → data-sheet.54cfa8e8.js.map} +1 -1
  19. package/dist/esm/{colors.75a92ad3.js → data-sheet.6021b6c9.js} +30 -21
  20. package/dist/esm/data-sheet.6021b6c9.js.map +1 -0
  21. package/dist/esm/{actions.module.684172fa.css → data-sheet.706f955d.css} +1 -1
  22. package/dist/esm/{actions.module.684172fa.css.map → data-sheet.706f955d.css.map} +1 -1
  23. package/dist/esm/{main.module.658cf7b2.css → data-sheet.91223ec6.css} +35 -1
  24. package/dist/esm/data-sheet.91223ec6.css.map +1 -0
  25. package/dist/esm/{actions.065d098d.js → data-sheet.a3eb6088.js} +4 -4
  26. package/dist/esm/{actions.065d098d.js.map → data-sheet.a3eb6088.js.map} +1 -1
  27. package/dist/esm/{main.module.df43976f.css → data-sheet.b3ccc91b.css} +8 -5
  28. package/dist/esm/data-sheet.b3ccc91b.css.map +1 -0
  29. package/dist/esm/{provider.7942302e.js → data-sheet.b4098761.js} +162 -13
  30. package/dist/esm/data-sheet.b4098761.js.map +1 -0
  31. package/dist/esm/{text-areas.ccfcf204.js → data-sheet.b5946d6b.js} +6 -5
  32. package/dist/esm/data-sheet.b5946d6b.js.map +1 -0
  33. package/dist/esm/{main.module.bd60788c.js → data-sheet.d570ef95.js} +22 -22
  34. package/dist/esm/data-sheet.d570ef95.js.map +1 -0
  35. package/dist/esm/{core.c9bdeacd.js → data-sheet.e09ffc66.js} +183 -82
  36. package/dist/esm/data-sheet.e09ffc66.js.map +1 -0
  37. package/dist/esm/{components.f832ecf3.js → data-sheet.e37b4bd3.js} +5 -5
  38. package/dist/esm/{components.f832ecf3.js.map → data-sheet.e37b4bd3.js.map} +1 -1
  39. package/dist/esm/data-sheet.ef63e366.css +110 -0
  40. package/dist/esm/data-sheet.ef63e366.css.map +1 -0
  41. package/dist/esm/index.d.ts +38 -24
  42. package/dist/esm/index.d.ts.map +1 -1
  43. package/dist/esm/index.js +3 -3
  44. package/dist/node/data-sheet.0f66147e.js +2 -0
  45. package/dist/node/data-sheet.0f66147e.js.map +1 -0
  46. package/dist/node/data-sheet.171105c1.js +2 -0
  47. package/dist/node/data-sheet.171105c1.js.map +1 -0
  48. package/dist/node/data-sheet.1a487c3c.js +2 -0
  49. package/dist/node/data-sheet.1a487c3c.js.map +1 -0
  50. package/dist/node/data-sheet.28641e23.css +2 -0
  51. package/dist/node/data-sheet.28641e23.css.map +1 -0
  52. package/dist/node/data-sheet.2cac1a8c.js +2 -0
  53. package/dist/node/data-sheet.2cac1a8c.js.map +1 -0
  54. package/dist/node/data-sheet.2f64274d.css +2 -0
  55. package/dist/node/data-sheet.2f64274d.css.map +1 -0
  56. package/dist/node/data-sheet.3680e59d.js +2 -0
  57. package/dist/node/data-sheet.3680e59d.js.map +1 -0
  58. package/dist/node/data-sheet.47e3f95c.js +2 -0
  59. package/dist/node/data-sheet.47e3f95c.js.map +1 -0
  60. package/dist/node/data-sheet.50d0742f.js +2 -0
  61. package/dist/node/data-sheet.50d0742f.js.map +1 -0
  62. package/dist/node/data-sheet.599efaa9.js +2 -0
  63. package/dist/node/data-sheet.599efaa9.js.map +1 -0
  64. package/dist/node/data-sheet.7b95fbc1.css +2 -0
  65. package/dist/node/data-sheet.7b95fbc1.css.map +1 -0
  66. package/dist/node/data-sheet.7bbad640.js +2 -0
  67. package/dist/node/data-sheet.7bbad640.js.map +1 -0
  68. package/dist/node/data-sheet.945becc3.js +2 -0
  69. package/dist/node/data-sheet.945becc3.js.map +1 -0
  70. package/dist/node/data-sheet.95445483.js +2 -0
  71. package/dist/node/data-sheet.95445483.js.map +1 -0
  72. package/dist/node/data-sheet.a65463ef.js +2 -0
  73. package/dist/node/data-sheet.a65463ef.js.map +1 -0
  74. package/dist/node/data-sheet.c3eefdc9.js +2 -0
  75. package/dist/node/data-sheet.c3eefdc9.js.map +1 -0
  76. package/dist/node/data-sheet.e6e07d4a.js +2 -0
  77. package/dist/node/data-sheet.e6e07d4a.js.map +1 -0
  78. package/dist/node/data-sheet.f0223f39.js +2 -0
  79. package/dist/node/data-sheet.f0223f39.js.map +1 -0
  80. package/dist/node/{actions.module.565df529.css → data-sheet.ffaf8ac7.css} +1 -1
  81. package/dist/node/data-sheet.ffaf8ac7.css.map +1 -0
  82. package/dist/node/index.js +1 -1
  83. package/dist/node/index.js.map +1 -1
  84. package/package.json +8 -6
  85. package/src/__archive/base.ts +1 -1
  86. package/src/__archive/components/column-utils.ts +1 -1
  87. package/src/__archive/components/index.ts +3 -3
  88. package/src/__archive/components/toolbar.ts +4 -4
  89. package/src/__archive/editors/index.ts +2 -2
  90. package/src/__archive/main.ts +6 -6
  91. package/src/__archive/provider.ts +1 -1
  92. package/src/__archive/test-sheet/index.ts +5 -5
  93. package/src/__archive/virtualized.ts +2 -2
  94. package/src/components/colors.ts +38 -22
  95. package/src/components/editor-popup.ts +28 -6
  96. package/src/components/main.module.sass +33 -0
  97. package/src/components/text-areas.ts +2 -1
  98. package/src/core.ts +262 -105
  99. package/src/main.module.sass +19 -0
  100. package/src/postgrest-table/data-loaders.ts +44 -12
  101. package/src/postgrest-table/index.ts +104 -45
  102. package/src/postgrest-table/main.module.sass +6 -4
  103. package/src/provider.ts +289 -98
  104. package/src/utils/column-spec.ts +42 -3
  105. package/dist/esm/cell-renderers.8222e82a.js +0 -31
  106. package/dist/esm/cell-renderers.8222e82a.js.map +0 -1
  107. package/dist/esm/colors.75a92ad3.js.map +0 -1
  108. package/dist/esm/column-spec.e56f4d75.js.map +0 -1
  109. package/dist/esm/core.c9bdeacd.js.map +0 -1
  110. package/dist/esm/data-loaders.b7de291b.js.map +0 -1
  111. package/dist/esm/editor-popup.819ce365.js.map +0 -1
  112. package/dist/esm/main.module.658cf7b2.css.map +0 -1
  113. package/dist/esm/main.module.7e0903d4.js.map +0 -1
  114. package/dist/esm/main.module.83442ac4.js.map +0 -1
  115. package/dist/esm/main.module.b66a4bc1.css +0 -91
  116. package/dist/esm/main.module.b66a4bc1.css.map +0 -1
  117. package/dist/esm/main.module.bd60788c.js.map +0 -1
  118. package/dist/esm/main.module.df43976f.css.map +0 -1
  119. package/dist/esm/postgrest-table.d1f8b3a4.js.map +0 -1
  120. package/dist/esm/provider.7942302e.js.map +0 -1
  121. package/dist/esm/text-areas.ccfcf204.js.map +0 -1
  122. package/dist/node/actions.4dfe63d8.js +0 -2
  123. package/dist/node/actions.4dfe63d8.js.map +0 -1
  124. package/dist/node/actions.module.565df529.css.map +0 -1
  125. package/dist/node/actions.module.61991621.js +0 -2
  126. package/dist/node/actions.module.61991621.js.map +0 -1
  127. package/dist/node/cell-renderers.bbaaeb83.js +0 -2
  128. package/dist/node/cell-renderers.bbaaeb83.js.map +0 -1
  129. package/dist/node/colors.fee61100.js +0 -2
  130. package/dist/node/colors.fee61100.js.map +0 -1
  131. package/dist/node/column-spec.da7354f5.js +0 -2
  132. package/dist/node/column-spec.da7354f5.js.map +0 -1
  133. package/dist/node/components.213ca3fc.js +0 -2
  134. package/dist/node/components.213ca3fc.js.map +0 -1
  135. package/dist/node/core.c404e4d4.js +0 -2
  136. package/dist/node/core.c404e4d4.js.map +0 -1
  137. package/dist/node/data-loaders.50ce46a4.js +0 -2
  138. package/dist/node/data-loaders.50ce46a4.js.map +0 -1
  139. package/dist/node/editor-popup.e19a3668.js +0 -2
  140. package/dist/node/editor-popup.e19a3668.js.map +0 -1
  141. package/dist/node/main.module.0802fb12.js +0 -2
  142. package/dist/node/main.module.0802fb12.js.map +0 -1
  143. package/dist/node/main.module.273015bb.js +0 -2
  144. package/dist/node/main.module.273015bb.js.map +0 -1
  145. package/dist/node/main.module.4cad6bbb.js +0 -2
  146. package/dist/node/main.module.4cad6bbb.js.map +0 -1
  147. package/dist/node/main.module.8370d601.css +0 -2
  148. package/dist/node/main.module.8370d601.css.map +0 -1
  149. package/dist/node/main.module.a197ee6f.css +0 -2
  150. package/dist/node/main.module.a197ee6f.css.map +0 -1
  151. package/dist/node/main.module.e5354239.css +0 -2
  152. package/dist/node/main.module.e5354239.css.map +0 -1
  153. package/dist/node/postgrest-table.49926421.js +0 -2
  154. package/dist/node/postgrest-table.49926421.js.map +0 -1
  155. package/dist/node/provider.f11d5828.js +0 -2
  156. package/dist/node/provider.f11d5828.js.map +0 -1
  157. package/dist/node/text-areas.64832f7d.js +0 -2
  158. package/dist/node/text-areas.64832f7d.js.map +0 -1
  159. package/dist/node/utils.897d92e2.js +0 -2
  160. package/dist/node/utils.897d92e2.js.map +0 -1
  161. package/src/postgrest-table/cell-renderers.ts +0 -24
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useAsyncEffect } from "@macrostrat/ui-components";
4
4
  import { debounce } from "underscore";
5
- import { useCallback, useMemo, useReducer } from "react";
5
+ import { useCallback, useMemo, useReducer, useRef } from "react";
6
6
  import update, { Spec } from "immutability-helper";
7
7
 
8
8
  interface ChunkIndex {
@@ -11,7 +11,11 @@ interface ChunkIndex {
11
11
  lastValue: any;
12
12
  }
13
13
 
14
- import { PostgrestClient, PostgrestQueryBuilder } from "@supabase/postgrest-js";
14
+ import {
15
+ PostgrestClient,
16
+ PostgrestQueryBuilder,
17
+ PostgrestFilterBuilder,
18
+ } from "@supabase/postgrest-js";
15
19
 
16
20
  interface LazyLoaderState<T> {
17
21
  data: (T | null)[];
@@ -40,7 +44,7 @@ function adjustArraySize<T>(arr: T[], newSize: number) {
40
44
 
41
45
  function lazyLoadingReducer<T>(
42
46
  state: LazyLoaderState<T>,
43
- action: LazyLoaderAction<T>
47
+ action: LazyLoaderAction<T>,
44
48
  ): LazyLoaderState<T> {
45
49
  console.log(action);
46
50
  switch (action.type) {
@@ -108,7 +112,7 @@ function distanceToNextNonEmptyRow(
108
112
  data: any[],
109
113
  start: number,
110
114
  direction: LoadDirection,
111
- limit: number
115
+ limit: number,
112
116
  ): number {
113
117
  let i = start;
114
118
  while (i < data.length && i > 0 && limit > 0) {
@@ -122,22 +126,36 @@ function distanceToNextNonEmptyRow(
122
126
  }
123
127
 
124
128
  interface QueryConfig {
125
- columns?: string;
129
+ columns?: string | string[];
126
130
  count?: "exact" | "estimated";
127
131
  limit?: number;
128
132
  offset?: number;
129
133
  order?: { key: string; ascending: boolean };
130
134
  after?: any;
135
+ filter?: (
136
+ query: PostgrestFilterBuilder<any, any, any>,
137
+ ) => PostgrestFilterBuilder<any, any, any>;
131
138
  }
132
139
 
133
140
  function buildQuery<T>(
134
141
  client: PostgrestQueryBuilder<T, any>,
135
- config: QueryConfig
142
+ config: QueryConfig,
136
143
  ) {
137
144
  const { columns = "*", count } = config;
138
145
  const opts = { count };
139
146
 
140
- let query = client.select(columns, opts);
147
+ let cols: string;
148
+ if (Array.isArray(columns)) {
149
+ cols = columns.join(", ");
150
+ } else {
151
+ cols = columns ?? "*";
152
+ }
153
+
154
+ let query = client.select(cols, opts);
155
+
156
+ if (config.filter) {
157
+ query = config.filter(query);
158
+ }
141
159
 
142
160
  if (config.order != null) {
143
161
  query = query.order(config.order.key, {
@@ -163,7 +181,7 @@ function _loadMoreData<T>(
163
181
  client: PostgrestQueryBuilder<T, any>,
164
182
  config: QueryConfig & { chunkSize: number },
165
183
  state: LazyLoaderState<T>,
166
- dispatch: any
184
+ dispatch: any,
167
185
  ) {
168
186
  const rowIndex = indexOfFirstNullInRegion(state.data, state.visibleRegion);
169
187
  if (state.loading || rowIndex == null) {
@@ -217,12 +235,15 @@ const loadMoreData = debounce(_loadMoreData, 100);
217
235
  type LazyLoaderOptions = Omit<QueryConfig, "count" | "offset" | "limit"> & {
218
236
  chunkSize?: number;
219
237
  sortKey?: string;
238
+ filter?: (
239
+ query: PostgrestFilterBuilder<any, any, any>,
240
+ ) => PostgrestFilterBuilder<any, any, any>;
220
241
  };
221
242
 
222
243
  export function usePostgRESTLazyLoader(
223
244
  endpoint: string,
224
245
  table: string,
225
- config: LazyLoaderOptions = {}
246
+ config: LazyLoaderOptions = {},
226
247
  ) {
227
248
  const initialState: LazyLoaderState<any> = {
228
249
  data: [],
@@ -247,14 +268,25 @@ export function usePostgRESTLazyLoader(
247
268
  state.visibleRegion.rowIndexEnd,
248
269
  ]);
249
270
 
271
+ // Reference to hold onto the scroll position
272
+ const ref = useRef(null);
273
+
250
274
  const onScroll = useCallback(
251
275
  debounce((visibleCells: RowRegion) => {
276
+ if (
277
+ visibleCells.rowIndexEnd == ref.current?.rowIndexEnd &&
278
+ visibleCells.rowIndexStart == ref.current?.rowIndexStart
279
+ ) {
280
+ return;
281
+ }
282
+ console.log("Visible cells changed", visibleCells);
252
283
  dispatch({
253
284
  type: "set-visible",
254
285
  region: visibleCells,
255
286
  });
287
+ ref.current = visibleCells;
256
288
  }, 500),
257
- [dispatch]
289
+ [dispatch],
258
290
  );
259
291
 
260
292
  return {
@@ -269,14 +301,14 @@ export function usePostgRESTLazyLoader(
269
301
  function getRowIndexToLoadFrom<T>(
270
302
  data: (T | null)[],
271
303
  visibleRegion: RowRegion,
272
- chunkSize: number
304
+ chunkSize: number,
273
305
  ) {
274
306
  return indexOfFirstNullInRegion(data, visibleRegion);
275
307
  }
276
308
 
277
309
  function indexOfFirstNullInRegion(
278
310
  data: any[],
279
- region: RowRegion
311
+ region: RowRegion,
280
312
  ): number | null {
281
313
  for (let i = region.rowIndexStart; i < region.rowIndexEnd; i++) {
282
314
  if (data[i] == null) {
@@ -1,30 +1,53 @@
1
- import { OverlayToaster, Tag } from "@blueprintjs/core";
1
+ import { Toaster, HotkeysProvider } from "@blueprintjs/core";
2
2
  import hyper from "@macrostrat/hyper";
3
3
  import styles from "./main.module.sass";
4
- import { DataSheet, ColorCell } from "../core"; //getRowsToDelete
5
- import { LithologyTag } from "./cell-renderers";
4
+ import { DataSheet, ColorCell, getRowsToDelete } from "../core"; //getRowsToDelete
5
+ import { LithologyTag, Tag, TagSize } from "@macrostrat/data-components";
6
6
  import { usePostgRESTLazyLoader } from "./data-loaders";
7
7
  import { Spinner } from "@blueprintjs/core";
8
8
 
9
9
  export * from "./data-loaders";
10
- import { useCallback, useRef } from "react";
11
- import { ErrorBoundary } from "@macrostrat/ui-components";
10
+ import { useCallback } from "react";
11
+ import {
12
+ ErrorBoundary,
13
+ ToasterContext,
14
+ useToaster,
15
+ } from "@macrostrat/ui-components";
12
16
  import { Spec } from "immutability-helper";
13
17
  import { DataSheetProviderProps } from "../provider";
18
+ import { PostgrestFilterBuilder } from "@supabase/postgrest-js";
19
+ import type {
20
+ GenericFunction,
21
+ GenericTable,
22
+ GenericView,
23
+ } from "@supabase/postgrest-js/dist/cjs/types";
14
24
 
15
25
  const h = hyper.styled(styles);
16
26
 
17
- interface PostgRESTTableViewProps<T> extends DataSheetProviderProps<T> {
27
+ export type GenericSchema = {
28
+ Tables: Record<string, GenericTable>;
29
+ Views: Record<string, GenericView>;
30
+ Functions: Record<string, GenericFunction>;
31
+ };
32
+
33
+ interface PostgRESTTableViewProps<T extends object>
34
+ extends DataSheetProviderProps<T> {
18
35
  endpoint: string;
19
36
  table: string;
20
37
  columnOptions?: any;
21
38
  order?: any;
22
39
  columns?: string;
23
40
  editable?: boolean;
41
+ filter(
42
+ query: PostgrestFilterBuilder<T, any, any>,
43
+ ): PostgrestFilterBuilder<T, any, any>;
24
44
  }
25
45
 
26
46
  export function PostgRESTTableView<T>(props: PostgRESTTableViewProps<T>) {
27
- return h(ErrorBoundary, h(_PostgRESTTableView, props));
47
+ return h(
48
+ ErrorBoundary,
49
+ h(HotkeysProvider, h(ToasterContext, h(_PostgRESTTableView, props))),
50
+ );
28
51
  }
29
52
 
30
53
  const successResponses = [200, 201];
@@ -36,6 +59,8 @@ function _PostgRESTTableView<T>({
36
59
  order,
37
60
  columns,
38
61
  editable = false,
62
+ filter,
63
+ identityKey = "id",
39
64
  ...rest
40
65
  }: PostgRESTTableViewProps<T>) {
41
66
  const { data, onScroll, dispatch, client } = usePostgRESTLazyLoader(
@@ -44,37 +69,25 @@ function _PostgRESTTableView<T>({
44
69
  {
45
70
  order,
46
71
  columns,
47
- }
72
+ filter,
73
+ },
48
74
  );
49
75
 
50
- const toasterRef = useRef(null);
76
+ const toaster = useToaster();
51
77
 
52
78
  const finishResponse = useCallback(
53
79
  (promisedResult, changes) => {
54
- promisedResult
55
- .then((res) => {
56
- if (!successResponses.includes(res.status)) {
57
- // Throw an error with the status code
58
- let err = new Error(res.error.message);
59
- err["status"] = res.status;
60
- throw err;
61
- }
62
-
80
+ wrapWithErrorHandling(toaster, promisedResult).then((res) => {
81
+ if (res == null) {
82
+ throw new Error("Could not complete action");
83
+ } else {
63
84
  // Merge new data with old data
85
+ console.log("Updating data", changes);
64
86
  dispatch({ type: "update-data", changes });
65
- })
66
- .catch((err: Error) => {
67
- const status = err["status"];
68
- toasterRef.current?.show({
69
- message: h([
70
- h.if(status != null)([h("code", status), " "]),
71
- err.message,
72
- ]),
73
- intent: "danger",
74
- });
75
- });
87
+ }
88
+ });
76
89
  },
77
- [dispatch]
90
+ [dispatch, toaster],
78
91
  );
79
92
 
80
93
  if (data == null) {
@@ -82,7 +95,6 @@ function _PostgRESTTableView<T>({
82
95
  }
83
96
 
84
97
  return h("div.data-sheet-outer", [
85
- h(OverlayToaster, { usePortal: false, ref: toasterRef }),
86
98
  h(DataSheet, {
87
99
  ...rest,
88
100
  data,
@@ -92,13 +104,15 @@ function _PostgRESTTableView<T>({
92
104
  onDeleteRows(selection) {
93
105
  if (!editable) return;
94
106
 
95
- const rowIndices = console.log(rowIndices); //getRowsToDelete(selection);
107
+ const rowIndices = getRowsToDelete(selection);
96
108
 
97
- const ids = rowIndices.map((i) => data[i].id);
109
+ const ids = rowIndices.map((i) => data[i][identityKey]);
98
110
 
99
111
  dispatch({ type: "start-loading" });
100
112
 
101
- const query = client.delete().in("id", ids);
113
+ let query = client.delete().in(identityKey, ids);
114
+
115
+ query = filter?.(query) ?? query;
102
116
 
103
117
  finishResponse(query, { $delete: Array.from(rowIndices.keys()) });
104
118
  },
@@ -118,7 +132,9 @@ function _PostgRESTTableView<T>({
118
132
  dispatch({ type: "start-loading" });
119
133
 
120
134
  // Save data
121
- const query = client.upsert(updateRows, { defaultToNull: false });
135
+ let query = client.upsert(updateRows, { defaultToNull: false });
136
+
137
+ query = filter?.(query) ?? query;
122
138
 
123
139
  finishResponse(query, changes);
124
140
  },
@@ -126,6 +142,52 @@ function _PostgRESTTableView<T>({
126
142
  ]);
127
143
  }
128
144
 
145
+ export function notifyOnError(toaster: Toaster, error: any) {
146
+ console.error(error);
147
+ const { message, status, code, details } = error;
148
+
149
+ let errorDetails = null;
150
+
151
+ if (details != null) {
152
+ if (typeof details === "string") {
153
+ errorDetails = h("p.error-details", details);
154
+ } else {
155
+ errorDetails = h("div.error-details", [
156
+ h("h4", "Error details"),
157
+ h("pre", JSON.stringify(details, null, 2)),
158
+ ]);
159
+ }
160
+ }
161
+
162
+ toaster.show({
163
+ message: h([
164
+ h.if(status != null)([h("code.bp5-code", status), " "]),
165
+ h.if(code != null)([h("code.bp5-code", code), " "]),
166
+ message ?? "An error occurred",
167
+ errorDetails,
168
+ ]),
169
+ intent: "danger",
170
+ });
171
+ }
172
+
173
+ export function wrapWithErrorHandling<T = any>(
174
+ toaster: Toaster,
175
+ fnPromise: Promise<T>,
176
+ ): Promise<T | null> {
177
+ return fnPromise
178
+ .then((p) => {
179
+ if (p.error != null) {
180
+ // Rethrow error
181
+ throw p.error;
182
+ }
183
+ return p;
184
+ })
185
+ .catch((err) => {
186
+ notifyOnError(toaster, err);
187
+ return null;
188
+ });
189
+ }
190
+
129
191
  export function LongTextViewer({ value, onChange }) {
130
192
  return h("div.long-text", value);
131
193
  }
@@ -135,9 +197,10 @@ export function IntervalCell({ value, children, ...rest }) {
135
197
  }
136
198
 
137
199
  export function lithologyRenderer(value) {
138
- return h("span.liths", [
139
- addJoiner(value?.map((d) => h(LithologyTag, { data: d }))),
140
- ]);
200
+ return h(
201
+ "span.tag-cell-content.liths",
202
+ value?.map((d) => h(LithologyTag, { data: d, key: d.id })),
203
+ );
141
204
  }
142
205
 
143
206
  export function ExpandedLithologies({ value, onChange }) {
@@ -153,20 +216,16 @@ export function ExpandedLithologies({ value, onChange }) {
153
216
  h(
154
217
  "td.basis-col",
155
218
  d.basis_col?.map((d) => {
156
- return h(Tag, { minimal: true, key: d }, [
219
+ return h(Tag, { size: TagSize.Small, key: d }, [
157
220
  h("span.tag-header", "Column"),
158
221
  " ",
159
222
  h("code", d),
160
223
  ]);
161
- })
224
+ }),
162
225
  ),
163
226
  ]);
164
- })
227
+ }),
165
228
  ),
166
229
  ]),
167
230
  ]);
168
231
  }
169
-
170
- function addJoiner(arr) {
171
- return arr?.reduce((acc, curr) => [acc, " ", curr]);
172
- }
@@ -5,7 +5,7 @@
5
5
  border-radius: 0.5em
6
6
 
7
7
  .inline-lithology .lithology
8
- line-height: 1.2em
8
+ line-height: 1em
9
9
 
10
10
  .basis-panel
11
11
  :global(.bp5-tag)
@@ -41,12 +41,14 @@
41
41
  .basis-col
42
42
  max-width: 15em
43
43
 
44
- .liths :global(.bp5-tag)
45
- padding: 0px 4px
46
- min-height: 16px
44
+ .liths>*
45
+ margin-right: 0.5em
47
46
 
48
47
  .data-sheet-outer
49
48
  position: relative
50
49
  flex: 1
51
50
  display: flex
52
51
  min-height: 0
52
+
53
+ .tag-cell-content
54
+ line-height: 1