@macrostrat/data-sheet 4.1.1 → 4.2.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 (303) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/actions/builtin.cjs +1 -1
  3. package/dist/actions/builtin.cjs.map +1 -1
  4. package/dist/actions/builtin.d.ts +0 -2
  5. package/dist/actions/builtin.js +1 -1
  6. package/dist/actions/builtin.js.map +1 -1
  7. package/dist/actions/clipboard.cjs +1 -1
  8. package/dist/actions/clipboard.cjs.map +1 -1
  9. package/dist/actions/clipboard.d.ts +3 -2
  10. package/dist/actions/clipboard.js +1 -1
  11. package/dist/actions/clipboard.js.map +1 -1
  12. package/dist/actions/column-controls.cjs +7 -196
  13. package/dist/actions/column-controls.cjs.map +1 -1
  14. package/dist/actions/column-controls.d.ts +1 -1
  15. package/dist/actions/column-controls.js +5 -194
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -73
  18. package/dist/actions/column-filter.cjs.map +1 -1
  19. package/dist/actions/column-filter.d.ts +6 -4
  20. package/dist/actions/column-filter.js +25 -74
  21. package/dist/actions/column-filter.js.map +1 -1
  22. package/dist/actions/context.cjs +147 -0
  23. package/dist/actions/context.cjs.map +1 -0
  24. package/dist/actions/context.d.ts +93 -0
  25. package/dist/actions/context.js +145 -0
  26. package/dist/actions/context.js.map +1 -0
  27. package/dist/actions/edit-actions.cjs.map +1 -1
  28. package/dist/actions/edit-actions.d.ts +3 -1
  29. package/dist/actions/edit-actions.js.map +1 -1
  30. package/dist/actions/index.d.ts +2 -3
  31. package/dist/actions/selection.cjs +70 -115
  32. package/dist/actions/selection.cjs.map +1 -1
  33. package/dist/actions/selection.d.ts +22 -12
  34. package/dist/actions/selection.js +71 -114
  35. package/dist/actions/selection.js.map +1 -1
  36. package/dist/actions/table-actions.cjs +41 -0
  37. package/dist/actions/table-actions.cjs.map +1 -0
  38. package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
  39. package/dist/actions/{table-controls.js → table-actions.js} +2 -23
  40. package/dist/actions/table-actions.js.map +1 -0
  41. package/dist/actions/types.d.ts +11 -89
  42. package/dist/components/cell-detail.cjs +6 -6
  43. package/dist/components/cell-detail.cjs.map +1 -1
  44. package/dist/components/cell-detail.js +1 -1
  45. package/dist/components/colors.cjs.map +1 -1
  46. package/dist/components/colors.js.map +1 -1
  47. package/dist/components/editor-popup.cjs +7 -7
  48. package/dist/components/editor-popup.cjs.map +1 -1
  49. package/dist/components/editor-popup.js +1 -1
  50. package/dist/components/index.d.ts +2 -1
  51. package/dist/components/indicators/filter-and-sort.cjs +378 -0
  52. package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
  53. package/dist/components/indicators/filter-and-sort.d.ts +59 -0
  54. package/dist/components/indicators/filter-and-sort.js +376 -0
  55. package/dist/components/indicators/filter-and-sort.js.map +1 -0
  56. package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
  57. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
  58. package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
  59. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
  60. package/dist/components/indicators/index.d.ts +4 -0
  61. package/dist/components/indicators/selection.cjs +113 -0
  62. package/dist/components/indicators/selection.cjs.map +1 -0
  63. package/dist/components/indicators/selection.d.ts +3 -0
  64. package/dist/components/indicators/selection.js +111 -0
  65. package/dist/components/indicators/selection.js.map +1 -0
  66. package/dist/components/indicators/selection.module.sass.cjs +19 -0
  67. package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
  68. package/dist/components/indicators/selection.module.sass.js +17 -0
  69. package/dist/components/indicators/selection.module.sass.js.map +1 -0
  70. package/dist/components/indicators/unified-filters.cjs +130 -0
  71. package/dist/components/indicators/unified-filters.cjs.map +1 -0
  72. package/dist/components/indicators/unified-filters.d.ts +10 -0
  73. package/dist/components/indicators/unified-filters.js +130 -0
  74. package/dist/components/indicators/unified-filters.js.map +1 -0
  75. package/dist/components/indicators/view-info.cjs +59 -0
  76. package/dist/components/indicators/view-info.cjs.map +1 -0
  77. package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
  79. package/dist/components/indicators/view-info.js.map +1 -0
  80. package/dist/components/text-areas.cjs +5 -5
  81. package/dist/components/text-areas.cjs.map +1 -1
  82. package/dist/components/text-areas.js +1 -1
  83. package/dist/components/toolbars/actions-toolbar.cjs +185 -0
  84. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
  85. package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
  86. package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
  87. package/dist/components/toolbars/actions-toolbar.js.map +1 -0
  88. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
  89. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
  90. package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
  91. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
  92. package/dist/components/toolbars/active-filters.cjs +120 -0
  93. package/dist/components/toolbars/active-filters.cjs.map +1 -0
  94. package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
  95. package/dist/components/toolbars/active-filters.js +120 -0
  96. package/dist/components/toolbars/active-filters.js.map +1 -0
  97. package/dist/components/toolbars/index.d.ts +2 -0
  98. package/dist/data-panel.cjs +291 -0
  99. package/dist/data-panel.cjs.map +1 -0
  100. package/dist/data-panel.d.ts +110 -0
  101. package/dist/data-panel.js +289 -0
  102. package/dist/data-panel.js.map +1 -0
  103. package/dist/data-panel.module.sass.cjs +40 -0
  104. package/dist/data-panel.module.sass.cjs.map +1 -0
  105. package/dist/data-panel.module.sass.js +38 -0
  106. package/dist/data-panel.module.sass.js.map +1 -0
  107. package/dist/{core.cjs → data-sheet.cjs} +123 -190
  108. package/dist/data-sheet.cjs.map +1 -0
  109. package/dist/data-sheet.css +241 -13
  110. package/dist/data-sheet.d.ts +16 -0
  111. package/dist/{core.js → data-sheet.js} +92 -159
  112. package/dist/data-sheet.js.map +1 -0
  113. package/dist/data-view.cjs +47 -0
  114. package/dist/data-view.cjs.map +1 -0
  115. package/dist/data-view.d.ts +15 -0
  116. package/dist/data-view.js +45 -0
  117. package/dist/data-view.js.map +1 -0
  118. package/dist/filters/operators.cjs +19 -2
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +4 -3
  121. package/dist/filters/operators.js +19 -2
  122. package/dist/filters/operators.js.map +1 -1
  123. package/dist/index.cjs +106 -47
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +4 -3
  126. package/dist/index.js +76 -17
  127. package/dist/index.js.map +1 -1
  128. package/dist/notifications.cjs +4 -4
  129. package/dist/notifications.cjs.map +1 -1
  130. package/dist/notifications.js +1 -1
  131. package/dist/postgrest-table/data-loaders.cjs +128 -95
  132. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  133. package/dist/postgrest-table/data-loaders.d.ts +52 -82
  134. package/dist/postgrest-table/data-loaders.js +109 -76
  135. package/dist/postgrest-table/data-loaders.js.map +1 -1
  136. package/dist/postgrest-table/index.cjs +18 -17
  137. package/dist/postgrest-table/index.cjs.map +1 -1
  138. package/dist/postgrest-table/index.d.ts +4 -3
  139. package/dist/postgrest-table/index.js +9 -8
  140. package/dist/postgrest-table/index.js.map +1 -1
  141. package/dist/{utils → provider}/column-spec.cjs +23 -9
  142. package/dist/provider/column-spec.cjs.map +1 -0
  143. package/dist/{utils → provider}/column-spec.d.ts +73 -2
  144. package/dist/{utils → provider}/column-spec.js +24 -10
  145. package/dist/provider/column-spec.js.map +1 -0
  146. package/dist/provider/core.cjs +382 -0
  147. package/dist/provider/core.cjs.map +1 -0
  148. package/dist/provider/core.d.ts +74 -0
  149. package/dist/provider/core.js +380 -0
  150. package/dist/provider/core.js.map +1 -0
  151. package/dist/provider/index.d.ts +7 -0
  152. package/dist/provider/interactions.cjs +128 -0
  153. package/dist/provider/interactions.cjs.map +1 -0
  154. package/dist/provider/interactions.d.ts +39 -0
  155. package/dist/provider/interactions.js +128 -0
  156. package/dist/provider/interactions.js.map +1 -0
  157. package/dist/provider/selection.cjs +29 -0
  158. package/dist/provider/selection.cjs.map +1 -0
  159. package/dist/provider/selection.d.ts +9 -0
  160. package/dist/provider/selection.js +29 -0
  161. package/dist/provider/selection.js.map +1 -0
  162. package/dist/provider/table-data.cjs +92 -0
  163. package/dist/provider/table-data.cjs.map +1 -0
  164. package/dist/provider/table-data.d.ts +81 -0
  165. package/dist/provider/table-data.js +92 -0
  166. package/dist/provider/table-data.js.map +1 -0
  167. package/dist/provider/types.cjs +22 -0
  168. package/dist/provider/types.cjs.map +1 -0
  169. package/dist/provider/types.d.ts +256 -0
  170. package/dist/provider/types.js +22 -0
  171. package/dist/provider/types.js.map +1 -0
  172. package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
  177. package/dist/renderers/cell-renderer.cjs.map +1 -0
  178. package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
  179. package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +21 -13
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +3 -2
  184. package/dist/renderers/column-header-cell.js +20 -12
  185. package/dist/renderers/column-header-cell.js.map +1 -1
  186. package/dist/renderers/index.d.ts +1 -0
  187. package/dist/types.cjs +7 -19
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.ts +117 -229
  190. package/dist/types.js +7 -19
  191. package/dist/types.js.map +1 -1
  192. package/dist/utils/atoms.cjs +24 -0
  193. package/dist/utils/atoms.cjs.map +1 -0
  194. package/dist/utils/atoms.d.ts +4 -0
  195. package/dist/utils/atoms.js +24 -0
  196. package/dist/utils/atoms.js.map +1 -0
  197. package/dist/utils/debug-overlay.cjs.map +1 -1
  198. package/dist/utils/debug-overlay.js.map +1 -1
  199. package/dist/utils/index.d.ts +2 -3
  200. package/dist/utils/key-handling.cjs +140 -139
  201. package/dist/utils/key-handling.cjs.map +1 -1
  202. package/dist/utils/key-handling.d.ts +4 -2
  203. package/dist/utils/key-handling.js +136 -135
  204. package/dist/utils/key-handling.js.map +1 -1
  205. package/dist/utils/validation.cjs +6 -1
  206. package/dist/utils/validation.cjs.map +1 -1
  207. package/dist/utils/validation.d.ts +1 -1
  208. package/dist/utils/validation.js +6 -1
  209. package/dist/utils/validation.js.map +1 -1
  210. package/package.json +4 -3
  211. package/src/actions/builtin.ts +1 -4
  212. package/src/actions/clipboard.ts +4 -3
  213. package/src/actions/column-controls.ts +12 -245
  214. package/src/actions/column-filter.ts +28 -92
  215. package/src/actions/context.ts +299 -0
  216. package/src/actions/edit-actions.ts +3 -1
  217. package/src/actions/index.ts +2 -3
  218. package/src/actions/selection.ts +109 -156
  219. package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
  220. package/src/actions/types.ts +17 -101
  221. package/src/components/colors.ts +1 -1
  222. package/src/components/index.ts +2 -1
  223. package/src/components/indicators/filter-and-sort.module.sass +13 -0
  224. package/src/components/indicators/filter-and-sort.ts +478 -0
  225. package/src/components/indicators/index.ts +4 -0
  226. package/src/components/indicators/selection.module.sass +22 -0
  227. package/src/components/indicators/selection.ts +141 -0
  228. package/src/components/indicators/unified-filters.ts +161 -0
  229. package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
  230. package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
  231. package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
  232. package/src/components/toolbars/active-filters.ts +150 -0
  233. package/src/components/toolbars/index.ts +2 -0
  234. package/src/data-panel.module.sass +185 -0
  235. package/src/data-panel.ts +556 -0
  236. package/src/{core.ts → data-sheet.ts} +145 -330
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +33 -3
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +244 -171
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +30 -15
  243. package/src/provider/core.ts +585 -0
  244. package/src/provider/index.ts +7 -0
  245. package/src/provider/interactions.ts +161 -0
  246. package/src/provider/selection.ts +31 -0
  247. package/src/provider/table-data.ts +178 -0
  248. package/src/provider/types.ts +273 -0
  249. package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
  251. package/src/renderers/column-header-cell.ts +21 -14
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +137 -239
  254. package/src/utils/atoms.ts +28 -0
  255. package/src/utils/debug-overlay.ts +1 -1
  256. package/src/utils/index.ts +2 -8
  257. package/src/utils/key-handling.ts +170 -164
  258. package/src/utils/validation.ts +7 -2
  259. package/dist/actions/filters.cjs +0 -139
  260. package/dist/actions/filters.cjs.map +0 -1
  261. package/dist/actions/filters.js +0 -139
  262. package/dist/actions/filters.js.map +0 -1
  263. package/dist/actions/table-controls.cjs +0 -62
  264. package/dist/actions/table-controls.cjs.map +0 -1
  265. package/dist/actions/table-controls.js.map +0 -1
  266. package/dist/actions/toolbar.cjs +0 -260
  267. package/dist/actions/toolbar.cjs.map +0 -1
  268. package/dist/actions/toolbar.js.map +0 -1
  269. package/dist/actions/toolbar.module.sass.cjs +0 -27
  270. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  271. package/dist/actions/toolbar.module.sass.js +0 -25
  272. package/dist/actions/toolbar.module.sass.js.map +0 -1
  273. package/dist/cell-renderer.cjs.map +0 -1
  274. package/dist/cell-renderer.js.map +0 -1
  275. package/dist/components/view-info.cjs +0 -55
  276. package/dist/components/view-info.cjs.map +0 -1
  277. package/dist/components/view-info.js.map +0 -1
  278. package/dist/core.cjs.map +0 -1
  279. package/dist/core.d.ts +0 -117
  280. package/dist/core.js.map +0 -1
  281. package/dist/provider.cjs +0 -197
  282. package/dist/provider.cjs.map +0 -1
  283. package/dist/provider.d.ts +0 -26
  284. package/dist/provider.js +0 -195
  285. package/dist/provider.js.map +0 -1
  286. package/dist/table-updates/data-parameter.d.ts +0 -14
  287. package/dist/table-updates/filter.d.ts +0 -16
  288. package/dist/table-updates/index.d.ts +0 -19
  289. package/dist/utils/column-spec.cjs.map +0 -1
  290. package/dist/utils/column-spec.js.map +0 -1
  291. package/dist/utils/index.cjs +0 -9
  292. package/dist/utils/index.cjs.map +0 -1
  293. package/dist/utils/index.js +0 -9
  294. package/dist/utils/index.js.map +0 -1
  295. package/dist/zustand-store.cjs.map +0 -1
  296. package/dist/zustand-store.js.map +0 -1
  297. package/src/actions/filters.ts +0 -176
  298. package/src/components/actions.module.sass +0 -8
  299. package/src/provider.ts +0 -267
  300. package/src/table-updates/data-parameter.ts +0 -44
  301. package/src/table-updates/filter.ts +0 -124
  302. package/src/table-updates/index.ts +0 -239
  303. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -1,44 +0,0 @@
1
- import { Filter } from "./filter";
2
-
3
- interface DataParameters {
4
- group?: string;
5
- select: {
6
- page?: string;
7
- pageSize?: string;
8
- };
9
- filter: {
10
- [key: string]: Filter; // Used for filters
11
- };
12
- }
13
-
14
- const cloneDataParameters = (
15
- dataParameters: DataParameters
16
- ): DataParameters => {
17
- return {
18
- group: dataParameters?.group,
19
- select: { ...dataParameters?.select },
20
- filter: Object.entries(dataParameters?.filter).reduce(
21
- (acc, [key, value]) => {
22
- acc[key] = value.clone();
23
- return acc;
24
- },
25
- {}
26
- ),
27
- };
28
- };
29
-
30
- /*
31
- * Check if a column is active in the data parameters
32
- */
33
- export const isColumnActive = (
34
- dataParameters: DataParameters,
35
- column: string
36
- ) => {
37
- return (
38
- (column in dataParameters.filter &&
39
- dataParameters.filter[column].is_valid()) ||
40
- column == dataParameters?.group
41
- );
42
- };
43
-
44
- export { cloneDataParameters, DataParameters };
@@ -1,124 +0,0 @@
1
- import { ColumnOperators } from "../tables/defs";
2
-
3
- export class Filter {
4
- readonly column_name: string;
5
- readonly operator: ColumnOperators | undefined;
6
- readonly value: string | boolean | number | null;
7
-
8
- constructor(
9
- column_name: string,
10
- operator: ColumnOperators | undefined,
11
- value: string | boolean | number | null
12
- ) {
13
- this.column_name = column_name;
14
- this.operator = operator;
15
- this.value = value;
16
- }
17
-
18
- get formattedValue() {
19
- switch (this.operator) {
20
- case "in":
21
- return `(${this.value})`;
22
- default:
23
- return this.value;
24
- }
25
- }
26
-
27
- get urlValue() {
28
- return `${this.operator}.${this.formattedValue}`;
29
- }
30
-
31
- clone = () => {
32
- return new Filter(this.column_name, this.operator, this.value);
33
- };
34
-
35
- passes = (data: Record<string, string | boolean | number | null>) => {
36
- const filterValue = data[this.column_name];
37
- switch (this.operator) {
38
- case "eq":
39
- return filterValue == this.value;
40
- case "lt":
41
- return filterValue < this.value;
42
- case "le":
43
- return filterValue <= this.value;
44
- case "gt":
45
- return filterValue > this.value;
46
- case "ge":
47
- return filterValue >= this.value;
48
- case "ne":
49
- return filterValue != this.value;
50
- case "is_distinct_from":
51
- return filterValue != this.value;
52
- case "is_not_distinct_from":
53
- return filterValue == this.value;
54
- case "like":
55
- if (typeof filterValue != "string" || typeof this.value != "string") {
56
- return false;
57
- }
58
- return filterValue.includes(this.value);
59
- case "in":
60
- if (typeof filterValue != "string" || typeof this.value != "string") {
61
- return false;
62
- }
63
- return this.value.includes(filterValue);
64
- case "is":
65
- return filterValue == this.value;
66
- default:
67
- return false;
68
- }
69
- };
70
-
71
- is_valid = () => {
72
- if (this.operator == undefined) {
73
- return false;
74
- }
75
- return true;
76
- };
77
-
78
- to_array = () => {
79
- return [this.column_name, this.operator + "." + this.formattedValue];
80
- };
81
- }
82
-
83
- /*
84
- * Convert url and filter to a parameterized URL
85
- */
86
- export const addFilterToURL = (url: URL, filter: Filter) => {
87
- if (filter.is_valid()) {
88
- const [columnName, filterValue] = filter.to_array();
89
- url.searchParams.append(columnName, filterValue);
90
- }
91
- return url;
92
- };
93
-
94
- /*
95
- * Sort the filters by column name and stringify
96
- */
97
- export const createFiltersKey = (filters: Filter[]) => {
98
- const sortFilterEntries = (a: Filter, b: Filter) => {
99
- return a.column_name.localeCompare(b.column_name);
100
- };
101
-
102
- return filters
103
- .filter((filter) => filter.is_valid())
104
- .sort(sortFilterEntries)
105
- .map((filter) => filter.urlValue)
106
- .join("&");
107
- };
108
-
109
- export const rowPassesFilters = (
110
- row: Record<string, string | boolean | number | null>,
111
- filters: Filter[] | undefined
112
- ) => {
113
- for (const filter of filters) {
114
- // If the filter is invalid skip it
115
- if (!filter.is_valid()) {
116
- continue;
117
- }
118
-
119
- if (!filter.passes(row)) {
120
- return false;
121
- }
122
- }
123
- return true;
124
- };
@@ -1,239 +0,0 @@
1
- import {
2
- Filter,
3
- createFiltersKey,
4
- addFilterToURL,
5
- rowPassesFilters,
6
- } from "./filter";
7
- import { DataParameters, cloneDataParameters } from "./data-parameter";
8
- import {
9
- ProgressPopoverProps,
10
- submitColumnCopy,
11
- } from "#/maps/ingestion/@id/components";
12
-
13
- export interface TableUpdate {
14
- // Used to merge updates
15
- key?: string;
16
- // Column
17
- column: string;
18
- // Helpful for debugging
19
- description?: string;
20
- // Function to execute this update
21
- execute: () => Promise<void>;
22
- // Function to lyTablely this update to a cell
23
- applyToCell: (
24
- currentValue: boolean | string | number | null,
25
- row: Record<string, boolean | string | number | null>,
26
- cellColumnName: string,
27
- ) => string;
28
- }
29
-
30
- export const applyTableUpdate = (
31
- data: Record<string, boolean | string | number | null>[],
32
- tableUpdate: TableUpdate,
33
- ) => {
34
- for (const [rowIndex, row] of data.entries()) {
35
- data[rowIndex][tableUpdate.column] = tableUpdate.applyToCell(
36
- data[rowIndex][tableUpdate.column],
37
- row,
38
- tableUpdate.column,
39
- );
40
- }
41
-
42
- return data;
43
- };
44
-
45
- export const applyTableUpdates = (
46
- data: Record<string, boolean | string | number | null>[],
47
- tableUpdates: TableUpdate[],
48
- ) => {
49
- for (const tableUpdate of tableUpdates) {
50
- data = applyTableUpdate(data, tableUpdate);
51
- }
52
- return data;
53
- };
54
-
55
- export const createTableUpdateCopyColumn = (
56
- url: string,
57
- selectedColumn: string,
58
- copiedColumn: string,
59
- dataParameters: DataParameters,
60
- ): TableUpdate => {
61
- dataParameters = cloneDataParameters(dataParameters);
62
-
63
- return {
64
- column: selectedColumn,
65
- description: `Copy column ${copiedColumn} to ${selectedColumn}`,
66
- applyToCell: (value, row, cellColumnName) => {
67
- if (!rowPassesFilters(row, Object.values(dataParameters.filter))) {
68
- return value;
69
- }
70
-
71
- if (cellColumnName == selectedColumn) {
72
- return row[copiedColumn];
73
- }
74
-
75
- return value;
76
- },
77
- execute: async () => {
78
- await submitColumnCopy(url, copiedColumn, selectedColumn, dataParameters);
79
- },
80
- };
81
- };
82
-
83
- export const createTableUpdate = (
84
- url: string,
85
- value: string,
86
- columnName: string,
87
- row: Record<string, boolean | string | number | null>,
88
- dataParameters: DataParameters,
89
- ): TableUpdate => {
90
- /** Create an update operation that is queued for application to the
91
- * table
92
- */
93
- console.log(url, value, columnName, row, dataParameters);
94
- let newDataParameters = cloneDataParameters(dataParameters);
95
-
96
- // If we are grouped by a column, set the filter based on that.
97
-
98
- const group = newDataParameters.group;
99
-
100
- if (group != undefined) {
101
- if (group != null) {
102
- newDataParameters.filter[group] = new Filter(group, "eq", row[group]);
103
- } else {
104
- // special case for remaining elements not in a group
105
- newDataParameters.filter[group] = new Filter(group, "is", "null");
106
- }
107
- } else {
108
- newDataParameters.filter["_pkid"] = new Filter("_pkid", "eq", row["_pkid"]);
109
- }
110
-
111
- console.log(newDataParameters.filter);
112
-
113
- const execute = async () =>
114
- submitChange(url, value, [columnName], newDataParameters.filter);
115
-
116
- const apply = (
117
- currentValue: string,
118
- row: { [key: string]: string },
119
- cellColumnName: string,
120
- ) => {
121
- // If this row doesn't pass all the filters skip it
122
- if (!rowPassesFilters(row, Object.values(newDataParameters.filter))) {
123
- return currentValue;
124
- }
125
-
126
- // Return the new value
127
- return value;
128
- };
129
-
130
- const filterKey = createFiltersKey(Object.values(newDataParameters.filter));
131
-
132
- return {
133
- column: columnName,
134
- key: filterKey,
135
- description: `Update ${columnName} to ${value} for ${filterKey}`,
136
- execute: execute,
137
- applyToCell: apply,
138
- } as TableUpdate;
139
- };
140
-
141
- export const submitChange = async (
142
- url: string,
143
- value: string,
144
- columns: string[],
145
- filters: { [key: string]: Filter },
146
- ) => {
147
- for (const column of columns) {
148
- let updateURL = new URL(url);
149
-
150
- // Add the filters to the query parameters
151
- Object.values(filters).forEach((filter) => {
152
- addFilterToURL(updateURL, filter);
153
- });
154
-
155
- // Create the request body
156
- let patch = { [column]: value };
157
-
158
- // Send the request
159
- let response = await fetch(updateURL, {
160
- method: "PATCH",
161
- headers: {
162
- "Content-Type": "application/json",
163
- },
164
- body: JSON.stringify(patch),
165
- });
166
-
167
- if (response.status != 204) {
168
- // Stop execution if the request failed
169
- throw Error("Failed to update");
170
- }
171
- }
172
- };
173
-
174
- /*
175
- * Squash adjacent updates with the same key
176
- *
177
- * If one update is followed by another update to the same set of cells
178
- * remove the first update
179
- */
180
- export const squashTableUpdates = (
181
- tableUpdates: TableUpdate[],
182
- ): TableUpdate[] => {
183
- let squashedTableUpdates = [];
184
- let lastTableUpdate = null;
185
- for (const tableUpdate of tableUpdates) {
186
- if (
187
- tableUpdate.key == lastTableUpdate?.key &&
188
- tableUpdate.column == lastTableUpdate?.column
189
- ) {
190
- squashedTableUpdates.pop();
191
- }
192
- squashedTableUpdates.push(tableUpdate);
193
- lastTableUpdate = tableUpdate;
194
- }
195
-
196
- return squashedTableUpdates;
197
- };
198
-
199
- /*
200
- * Submit table updates, returning any updates that were not submitted
201
- */
202
- export const submitTableUpdates = async (
203
- tableUpdates: TableUpdate[],
204
- setProgress: (p: ProgressPopoverProps) => void,
205
- ): Promise<TableUpdate[]> => {
206
- let index = 0;
207
- for (const tableUpdate of tableUpdates) {
208
- setProgress({
209
- text: tableUpdate?.description ?? "Submitting changes",
210
- });
211
-
212
- try {
213
- await tableUpdate.execute();
214
- } catch (e) {
215
- // If there is an error, set the progress to an error state and stop submitting
216
- setProgress({
217
- progressBarProps: { intent: "danger" },
218
- value: 1,
219
- text: "Error submitting changes",
220
- });
221
-
222
- setTimeout(() => {
223
- setProgress(undefined);
224
- }, 5000);
225
-
226
- // Return remaining table updates
227
- return tableUpdates.slice(index);
228
- }
229
-
230
- index += 1;
231
- setProgress({
232
- value: index / tableUpdates.length,
233
- });
234
- }
235
-
236
- setProgress(undefined);
237
-
238
- return [];
239
- };