@macrostrat/data-sheet 4.1.1 → 4.2.1
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 +46 -0
- package/dist/actions/builtin.cjs +1 -1
- package/dist/actions/builtin.cjs.map +1 -1
- package/dist/actions/builtin.d.ts +0 -2
- package/dist/actions/builtin.js +1 -1
- package/dist/actions/builtin.js.map +1 -1
- package/dist/actions/clipboard.cjs +1 -1
- package/dist/actions/clipboard.cjs.map +1 -1
- package/dist/actions/clipboard.d.ts +3 -2
- package/dist/actions/clipboard.js +1 -1
- package/dist/actions/clipboard.js.map +1 -1
- package/dist/actions/column-controls.cjs +7 -196
- package/dist/actions/column-controls.cjs.map +1 -1
- package/dist/actions/column-controls.d.ts +1 -1
- package/dist/actions/column-controls.js +5 -194
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/column-filter.cjs +24 -73
- package/dist/actions/column-filter.cjs.map +1 -1
- package/dist/actions/column-filter.d.ts +6 -4
- package/dist/actions/column-filter.js +25 -74
- package/dist/actions/column-filter.js.map +1 -1
- package/dist/actions/context.cjs +147 -0
- package/dist/actions/context.cjs.map +1 -0
- package/dist/actions/context.d.ts +93 -0
- package/dist/actions/context.js +145 -0
- package/dist/actions/context.js.map +1 -0
- package/dist/actions/edit-actions.cjs.map +1 -1
- package/dist/actions/edit-actions.d.ts +3 -1
- package/dist/actions/edit-actions.js.map +1 -1
- package/dist/actions/index.d.ts +2 -3
- package/dist/actions/selection.cjs +70 -115
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.d.ts +22 -12
- package/dist/actions/selection.js +71 -114
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-actions.cjs +41 -0
- package/dist/actions/table-actions.cjs.map +1 -0
- package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
- package/dist/actions/{table-controls.js → table-actions.js} +2 -23
- package/dist/actions/table-actions.js.map +1 -0
- package/dist/actions/types.d.ts +11 -89
- package/dist/components/cell-detail.cjs +6 -6
- package/dist/components/cell-detail.cjs.map +1 -1
- package/dist/components/cell-detail.js +1 -1
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +7 -7
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/indicators/filter-and-sort.cjs +378 -0
- package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.d.ts +59 -0
- package/dist/components/indicators/filter-and-sort.js +376 -0
- package/dist/components/indicators/filter-and-sort.js.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
- package/dist/components/indicators/index.d.ts +4 -0
- package/dist/components/indicators/selection.cjs +113 -0
- package/dist/components/indicators/selection.cjs.map +1 -0
- package/dist/components/indicators/selection.d.ts +3 -0
- package/dist/components/indicators/selection.js +111 -0
- package/dist/components/indicators/selection.js.map +1 -0
- package/dist/components/indicators/selection.module.sass.cjs +19 -0
- package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
- package/dist/components/indicators/selection.module.sass.js +17 -0
- package/dist/components/indicators/selection.module.sass.js.map +1 -0
- package/dist/components/indicators/unified-filters.cjs +130 -0
- package/dist/components/indicators/unified-filters.cjs.map +1 -0
- package/dist/components/indicators/unified-filters.d.ts +10 -0
- package/dist/components/indicators/unified-filters.js +130 -0
- package/dist/components/indicators/unified-filters.js.map +1 -0
- package/dist/components/indicators/view-info.cjs +59 -0
- package/dist/components/indicators/view-info.cjs.map +1 -0
- package/dist/components/indicators/view-info.d.ts +11 -0
- package/dist/components/{view-info.js → indicators/view-info.js} +20 -16
- package/dist/components/indicators/view-info.js.map +1 -0
- package/dist/components/text-areas.cjs +5 -5
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.js +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs +185 -0
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
- package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
- package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
- package/dist/components/toolbars/actions-toolbar.js.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
- package/dist/components/toolbars/active-filters.cjs +120 -0
- package/dist/components/toolbars/active-filters.cjs.map +1 -0
- package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
- package/dist/components/toolbars/active-filters.js +120 -0
- package/dist/components/toolbars/active-filters.js.map +1 -0
- package/dist/components/toolbars/index.d.ts +2 -0
- package/dist/data-panel.cjs +291 -0
- package/dist/data-panel.cjs.map +1 -0
- package/dist/data-panel.d.ts +110 -0
- package/dist/data-panel.js +289 -0
- package/dist/data-panel.js.map +1 -0
- package/dist/data-panel.module.sass.cjs +40 -0
- package/dist/data-panel.module.sass.cjs.map +1 -0
- package/dist/data-panel.module.sass.js +38 -0
- package/dist/data-panel.module.sass.js.map +1 -0
- package/dist/{core.cjs → data-sheet.cjs} +126 -188
- package/dist/data-sheet.cjs.map +1 -0
- package/dist/data-sheet.css +241 -13
- package/dist/data-sheet.d.ts +16 -0
- package/dist/{core.js → data-sheet.js} +95 -157
- package/dist/data-sheet.js.map +1 -0
- package/dist/data-view.cjs +47 -0
- package/dist/data-view.cjs.map +1 -0
- package/dist/data-view.d.ts +15 -0
- package/dist/data-view.js +45 -0
- package/dist/data-view.js.map +1 -0
- package/dist/filters/operators.cjs +19 -2
- package/dist/filters/operators.cjs.map +1 -1
- package/dist/filters/operators.d.ts +4 -3
- package/dist/filters/operators.js +19 -2
- package/dist/filters/operators.js.map +1 -1
- package/dist/index.cjs +106 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +76 -17
- package/dist/index.js.map +1 -1
- package/dist/notifications.cjs +4 -4
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.js +1 -1
- package/dist/postgrest-table/data-loaders.cjs +128 -95
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -82
- package/dist/postgrest-table/data-loaders.js +109 -76
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +18 -17
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +4 -3
- package/dist/postgrest-table/index.js +9 -8
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/{utils → provider}/column-spec.cjs +23 -9
- package/dist/provider/column-spec.cjs.map +1 -0
- package/dist/{utils → provider}/column-spec.d.ts +73 -2
- package/dist/{utils → provider}/column-spec.js +24 -10
- package/dist/provider/column-spec.js.map +1 -0
- package/dist/provider/core.cjs +382 -0
- package/dist/provider/core.cjs.map +1 -0
- package/dist/provider/core.d.ts +74 -0
- package/dist/provider/core.js +380 -0
- package/dist/provider/core.js.map +1 -0
- package/dist/provider/index.d.ts +7 -0
- package/dist/provider/interactions.cjs +128 -0
- package/dist/provider/interactions.cjs.map +1 -0
- package/dist/provider/interactions.d.ts +39 -0
- package/dist/provider/interactions.js +128 -0
- package/dist/provider/interactions.js.map +1 -0
- package/dist/provider/selection.cjs +29 -0
- package/dist/provider/selection.cjs.map +1 -0
- package/dist/provider/selection.d.ts +9 -0
- package/dist/provider/selection.js +29 -0
- package/dist/provider/selection.js.map +1 -0
- package/dist/provider/table-data.cjs +92 -0
- package/dist/provider/table-data.cjs.map +1 -0
- package/dist/provider/table-data.d.ts +81 -0
- package/dist/provider/table-data.js +92 -0
- package/dist/provider/table-data.js.map +1 -0
- package/dist/provider/types.cjs +22 -0
- package/dist/provider/types.cjs.map +1 -0
- package/dist/provider/types.d.ts +256 -0
- package/dist/provider/types.js +22 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
- package/dist/provider/zustand-store.cjs.map +1 -0
- package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
- package/dist/provider/zustand-store.js.map +1 -0
- package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
- package/dist/renderers/cell-renderer.cjs.map +1 -0
- package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
- package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
- package/dist/renderers/cell-renderer.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +21 -13
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +3 -2
- package/dist/renderers/column-header-cell.js +20 -12
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/renderers/index.d.ts +1 -0
- package/dist/types.cjs +7 -19
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +117 -229
- package/dist/types.js +7 -19
- package/dist/types.js.map +1 -1
- package/dist/utils/atoms.cjs +24 -0
- package/dist/utils/atoms.cjs.map +1 -0
- package/dist/utils/atoms.d.ts +4 -0
- package/dist/utils/atoms.js +24 -0
- package/dist/utils/atoms.js.map +1 -0
- package/dist/utils/debug-overlay.cjs.map +1 -1
- package/dist/utils/debug-overlay.js.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/key-handling.cjs +140 -139
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +4 -2
- package/dist/utils/key-handling.js +136 -135
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/utils/validation.cjs +6 -1
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/dist/utils/validation.js +6 -1
- package/dist/utils/validation.js.map +1 -1
- package/package.json +4 -3
- package/src/actions/builtin.ts +1 -4
- package/src/actions/clipboard.ts +4 -3
- package/src/actions/column-controls.ts +12 -245
- package/src/actions/column-filter.ts +28 -92
- package/src/actions/context.ts +299 -0
- package/src/actions/edit-actions.ts +3 -1
- package/src/actions/index.ts +2 -3
- package/src/actions/selection.ts +109 -156
- package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
- package/src/actions/types.ts +17 -101
- package/src/components/colors.ts +1 -1
- package/src/components/index.ts +2 -1
- package/src/components/indicators/filter-and-sort.module.sass +13 -0
- package/src/components/indicators/filter-and-sort.ts +478 -0
- package/src/components/indicators/index.ts +4 -0
- package/src/components/indicators/selection.module.sass +22 -0
- package/src/components/indicators/selection.ts +141 -0
- package/src/components/indicators/unified-filters.ts +161 -0
- package/src/components/{view-info.ts → indicators/view-info.ts} +19 -30
- package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
- package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
- package/src/components/toolbars/active-filters.ts +150 -0
- package/src/components/toolbars/index.ts +2 -0
- package/src/data-panel.module.sass +185 -0
- package/src/data-panel.ts +556 -0
- package/src/{core.ts → data-sheet.ts} +156 -327
- package/src/data-view.ts +70 -0
- package/src/filters/operators.ts +33 -3
- package/src/index.ts +4 -3
- package/src/postgrest-table/data-loaders.ts +244 -171
- package/src/postgrest-table/index.ts +10 -9
- package/src/{utils → provider}/column-spec.ts +30 -15
- package/src/provider/core.ts +585 -0
- package/src/provider/index.ts +7 -0
- package/src/provider/interactions.ts +161 -0
- package/src/provider/selection.ts +31 -0
- package/src/provider/table-data.ts +178 -0
- package/src/provider/types.ts +273 -0
- package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
- package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
- package/src/renderers/column-header-cell.ts +21 -14
- package/src/renderers/index.ts +1 -0
- package/src/types.ts +137 -239
- package/src/utils/atoms.ts +28 -0
- package/src/utils/debug-overlay.ts +1 -1
- package/src/utils/index.ts +2 -8
- package/src/utils/key-handling.ts +170 -164
- package/src/utils/validation.ts +7 -2
- package/dist/actions/filters.cjs +0 -139
- package/dist/actions/filters.cjs.map +0 -1
- package/dist/actions/filters.js +0 -139
- package/dist/actions/filters.js.map +0 -1
- package/dist/actions/table-controls.cjs +0 -62
- package/dist/actions/table-controls.cjs.map +0 -1
- package/dist/actions/table-controls.js.map +0 -1
- package/dist/actions/toolbar.cjs +0 -260
- package/dist/actions/toolbar.cjs.map +0 -1
- package/dist/actions/toolbar.js.map +0 -1
- package/dist/actions/toolbar.module.sass.cjs +0 -27
- package/dist/actions/toolbar.module.sass.cjs.map +0 -1
- package/dist/actions/toolbar.module.sass.js +0 -25
- package/dist/actions/toolbar.module.sass.js.map +0 -1
- package/dist/cell-renderer.cjs.map +0 -1
- package/dist/cell-renderer.js.map +0 -1
- package/dist/components/view-info.cjs +0 -55
- package/dist/components/view-info.cjs.map +0 -1
- package/dist/components/view-info.d.ts +0 -5
- package/dist/components/view-info.js.map +0 -1
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -117
- package/dist/core.js.map +0 -1
- package/dist/provider.cjs +0 -197
- package/dist/provider.cjs.map +0 -1
- package/dist/provider.d.ts +0 -26
- package/dist/provider.js +0 -195
- package/dist/provider.js.map +0 -1
- package/dist/table-updates/data-parameter.d.ts +0 -14
- package/dist/table-updates/filter.d.ts +0 -16
- package/dist/table-updates/index.d.ts +0 -19
- package/dist/utils/column-spec.cjs.map +0 -1
- package/dist/utils/column-spec.js.map +0 -1
- package/dist/utils/index.cjs +0 -9
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js +0 -9
- package/dist/utils/index.js.map +0 -1
- package/dist/zustand-store.cjs.map +0 -1
- package/dist/zustand-store.js.map +0 -1
- package/src/actions/filters.ts +0 -176
- package/src/components/actions.module.sass +0 -8
- package/src/provider.ts +0 -267
- package/src/table-updates/data-parameter.ts +0 -44
- package/src/table-updates/filter.ts +0 -124
- package/src/table-updates/index.ts +0 -239
- /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
|
-
};
|
|
File without changes
|