@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.
- package/CHANGELOG.md +19 -0
- package/dist/actions/builtin.cjs +56 -0
- package/dist/actions/builtin.cjs.map +1 -0
- package/dist/actions/builtin.d.ts +15 -0
- package/dist/actions/builtin.js +56 -0
- package/dist/actions/builtin.js.map +1 -0
- package/dist/actions/clipboard.cjs +250 -0
- package/dist/actions/clipboard.cjs.map +1 -0
- package/dist/actions/clipboard.d.ts +42 -0
- package/dist/actions/clipboard.js +250 -0
- package/dist/actions/clipboard.js.map +1 -0
- package/dist/actions/filters.cjs +123 -0
- package/dist/actions/filters.cjs.map +1 -0
- package/dist/actions/filters.d.ts +6 -0
- package/dist/actions/filters.js +123 -0
- package/dist/actions/filters.js.map +1 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/selection.cjs +194 -0
- package/dist/actions/selection.cjs.map +1 -0
- package/dist/actions/selection.d.ts +40 -0
- package/dist/actions/selection.js +192 -0
- package/dist/actions/selection.js.map +1 -0
- package/dist/actions/toolbar.cjs +171 -0
- package/dist/actions/toolbar.cjs.map +1 -0
- package/dist/actions/toolbar.d.ts +10 -0
- package/dist/actions/toolbar.js +171 -0
- package/dist/actions/toolbar.js.map +1 -0
- package/dist/actions/toolbar.module.sass.cjs +22 -0
- package/dist/actions/toolbar.module.sass.cjs.map +1 -0
- package/dist/actions/toolbar.module.sass.js +20 -0
- package/dist/actions/toolbar.module.sass.js.map +1 -0
- package/dist/actions/types.d.ts +143 -0
- package/dist/cell-renderer.cjs +44 -41
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.d.ts +1 -6
- package/dist/cell-renderer.js +45 -42
- package/dist/cell-renderer.js.map +1 -1
- package/dist/components/actions.module.sass.cjs +3 -3
- package/dist/components/actions.module.sass.js +2 -2
- package/dist/components/colors.cjs +20 -16
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.d.ts +3 -2
- package/dist/components/colors.js +20 -16
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +4 -3
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +4 -3
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/main.module.sass.cjs +12 -12
- package/dist/components/main.module.sass.js +11 -11
- package/dist/components/text-areas.cjs +23 -18
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.d.ts +8 -4
- package/dist/components/text-areas.js +20 -13
- package/dist/components/text-areas.js.map +1 -1
- package/dist/components/view-info.cjs +18 -0
- package/dist/components/view-info.cjs.map +1 -0
- package/dist/components/view-info.d.ts +1 -0
- package/dist/components/view-info.js +18 -0
- package/dist/components/view-info.js.map +1 -0
- package/dist/core.cjs +184 -156
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +14 -1
- package/dist/core.js +187 -157
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +181 -43
- package/dist/index.cjs +43 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -10
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +15 -14
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +14 -13
- package/dist/main.module.sass.js.map +1 -1
- package/dist/notifications.cjs +19 -0
- package/dist/notifications.cjs.map +1 -0
- package/dist/notifications.d.ts +9 -0
- package/dist/notifications.js +19 -0
- package/dist/notifications.js.map +1 -0
- package/dist/postgrest-table/data-loaders.cjs +181 -104
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -28
- package/dist/postgrest-table/data-loaders.js +181 -104
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +205 -79
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +13 -16
- package/dist/postgrest-table/index.js +186 -58
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
- package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
- package/dist/postgrest-table/lazy-loader-table.js +17 -14
- package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
- package/dist/postgrest-table/loading-utils.cjs +16 -0
- package/dist/postgrest-table/loading-utils.cjs.map +1 -0
- package/dist/postgrest-table/loading-utils.d.ts +13 -0
- package/dist/postgrest-table/loading-utils.js +16 -0
- package/dist/postgrest-table/loading-utils.js.map +1 -0
- package/dist/postgrest-table/main.module.sass.cjs +18 -13
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +18 -13
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/provider.cjs +58 -26
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +57 -23
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
- package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
- package/dist/renderers/column-header-cell-postgrest.js +216 -0
- package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +103 -0
- package/dist/renderers/column-header-cell.cjs.map +1 -0
- package/dist/renderers/column-header-cell.d.ts +30 -0
- package/dist/renderers/column-header-cell.js +101 -0
- package/dist/renderers/column-header-cell.js.map +1 -0
- package/dist/renderers/index.d.ts +2 -0
- package/dist/table-updates/data-parameter.d.ts +14 -0
- package/dist/table-updates/filter.d.ts +16 -0
- package/dist/table-updates/index.d.ts +19 -0
- package/dist/types.cjs +9 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +58 -4
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/column-spec.cjs +9 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +21 -0
- package/dist/utils/column-spec.js +9 -1
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/utils/key-handling.cjs +141 -52
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +2 -3
- package/dist/utils/key-handling.js +142 -53
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/zustand-store.cjs +216 -51
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +197 -32
- package/dist/zustand-store.js.map +1 -1
- package/package.json +5 -5
- package/src/actions/builtin.ts +65 -0
- package/src/actions/clipboard.ts +350 -0
- package/src/actions/filters.ts +150 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/selection.ts +271 -0
- package/src/actions/toolbar.module.sass +30 -0
- package/src/actions/toolbar.ts +212 -0
- package/src/actions/types.ts +159 -0
- package/src/cell-renderer.ts +55 -51
- package/src/components/colors.ts +22 -19
- package/src/components/editor-popup.ts +3 -2
- package/src/components/index.ts +1 -0
- package/src/components/main.module.sass +1 -0
- package/src/components/text-areas.ts +34 -19
- package/src/components/view-info.ts +17 -0
- package/src/core.ts +243 -170
- package/src/index.ts +1 -0
- package/src/main.module.sass +14 -2
- package/src/notifications.ts +22 -0
- package/src/postgrest-table/data-loaders.ts +300 -201
- package/src/postgrest-table/index.ts +258 -84
- package/src/postgrest-table/lazy-loader-table.ts +18 -17
- package/src/postgrest-table/loading-utils.ts +49 -0
- package/src/postgrest-table/main.module.sass +16 -0
- package/src/provider.ts +63 -20
- package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
- package/src/renderers/column-header-cell-postgrest.ts +282 -0
- package/src/renderers/column-header-cell.ts +388 -0
- package/src/renderers/index.ts +2 -0
- package/src/table-updates/data-parameter.ts +44 -0
- package/src/table-updates/filter.ts +124 -0
- package/src/table-updates/index.ts +239 -0
- package/src/types.ts +58 -3
- package/src/utils/column-spec.ts +47 -0
- package/src/utils/key-handling.ts +181 -72
- package/src/zustand-store.ts +241 -36
- package/dist/provider.d.ts +0 -15
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FocusedCellCoordinates,
|
|
3
3
|
Region,
|
|
4
|
+
RegionCardinality,
|
|
4
5
|
Table2,
|
|
5
6
|
} from "@blueprintjs/table";
|
|
6
7
|
import { ColumnSpec, ColumnSpecOptions } from "./utils";
|
|
8
|
+
import { OverlayToaster, Toaster } from "@blueprintjs/core";
|
|
9
|
+
|
|
10
|
+
/** A single column sort entry for client-side sorting.
|
|
11
|
+
* Defined here (rather than in actions/types) to avoid circular imports. */
|
|
12
|
+
export interface ColumnSort {
|
|
13
|
+
key: string;
|
|
14
|
+
ascending: boolean;
|
|
15
|
+
}
|
|
7
16
|
|
|
8
17
|
export interface DataSheetCoreProps<T> {
|
|
9
18
|
data: T[];
|
|
@@ -13,17 +22,51 @@ export interface DataSheetCoreProps<T> {
|
|
|
13
22
|
defaultColumnWidth?: number;
|
|
14
23
|
}
|
|
15
24
|
|
|
25
|
+
export enum TableElementStatus {
|
|
26
|
+
DELETED = "deleted",
|
|
27
|
+
ADDED = "added",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Proxy stored during a copy operation, enabling backend-mediated paste
|
|
31
|
+
* for lazy-loaded tables where not all data is available locally. */
|
|
32
|
+
export interface ClipboardProxy {
|
|
33
|
+
cardinality: RegionCardinality;
|
|
34
|
+
/** Source row indices (for row/cell copies) */
|
|
35
|
+
rowIndices?: number[];
|
|
36
|
+
/** Source column keys (for column/cell copies) */
|
|
37
|
+
columnKeys?: string[];
|
|
38
|
+
/** The plain text written to the clipboard, used to verify the proxy
|
|
39
|
+
* is still valid on paste (i.e., clipboard hasn't been overwritten). */
|
|
40
|
+
text: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
16
43
|
export interface DataSheetState<T> {
|
|
17
44
|
selection: Region[];
|
|
18
45
|
columnSpec: ColumnSpec[];
|
|
19
46
|
fillValueBaseCell: FocusedCellCoordinates | null;
|
|
20
47
|
focusedCell: FocusedCellCoordinates | null;
|
|
21
48
|
topLeftCell: FocusedCellCoordinates | null;
|
|
22
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Set of row indices that have been added to the table,
|
|
51
|
+
* but not yet committed to the underlying data array.
|
|
52
|
+
*
|
|
53
|
+
* This is used to track which rows should be reverted when
|
|
54
|
+
* a "reset" action is performed.
|
|
55
|
+
*/
|
|
56
|
+
rowStatus: TableElementStatus[];
|
|
23
57
|
// Sparse data structure for updated data
|
|
24
58
|
updatedData: T[];
|
|
25
59
|
initialized: boolean;
|
|
26
60
|
columnWidthsIndex: Map<string, number>;
|
|
61
|
+
/** Active column/table filters. Keys are filter IDs, values carry the
|
|
62
|
+
* filter definition and its current configuration state. */
|
|
63
|
+
activeFilters: Map<string, { filter: any; state: any }>;
|
|
64
|
+
/** Clipboard proxy from the last copy operation */
|
|
65
|
+
clipboardProxy: ClipboardProxy | null;
|
|
66
|
+
/** Visible row indices when filters are active. `null` means show all rows. */
|
|
67
|
+
filteredRowIndices: number[] | null;
|
|
68
|
+
/** Active column sort entries for client-side sorting. */
|
|
69
|
+
columnSorts: ColumnSort[];
|
|
27
70
|
}
|
|
28
71
|
|
|
29
72
|
type DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;
|
|
@@ -42,13 +85,24 @@ export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
|
|
|
42
85
|
clearSelection(): void;
|
|
43
86
|
resetChanges(): void;
|
|
44
87
|
addRow(): void;
|
|
88
|
+
/** Activate or update a column/table filter.
|
|
89
|
+
* Filter is any object satisfying `TableFilter` from the actions module. */
|
|
90
|
+
setFilter(filterId: string, filter: any, filterState: any): void;
|
|
91
|
+
/** Remove a filter by ID */
|
|
92
|
+
removeFilter(filterId: string): void;
|
|
93
|
+
/** Remove all active filters */
|
|
94
|
+
clearFilters(): void;
|
|
95
|
+
/** Set or clear a column sort. Pass `null` for ascending to clear. */
|
|
96
|
+
setColumnSort(key: string, ascending: boolean | null): void;
|
|
97
|
+
/** Remove all active column sorts */
|
|
98
|
+
clearColumnSorts(): void;
|
|
99
|
+
/** Store a clipboard proxy for potential backend-mediated paste */
|
|
100
|
+
setClipboardProxy(proxy: ClipboardProxy | null): void;
|
|
45
101
|
initialize(props: Partial<DataSheetStoreMain<T>>): void;
|
|
46
102
|
onSelection(selection: Region[]): void;
|
|
47
103
|
// Internal method used for infinite scrolling
|
|
48
|
-
setVisibleCells(visibleCells: VisibleCells): void;
|
|
49
104
|
scrollToRow(rowIndex: number): void;
|
|
50
105
|
tableRef: React.MutableRefObject<Table2>;
|
|
51
|
-
visibleCellsRef: React.MutableRefObject<VisibleCells>;
|
|
52
106
|
columnWidthsIndex: Map<string, number>;
|
|
53
107
|
defaultColumnWidth: number;
|
|
54
108
|
}
|
|
@@ -56,6 +110,7 @@ export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
|
|
|
56
110
|
export type DataSheetProviderProps<T> = DataSheetCoreProps<T> & {
|
|
57
111
|
children: React.ReactNode;
|
|
58
112
|
columnSpecOptions?: ColumnSpecOptions<T>;
|
|
113
|
+
toaster?: OverlayToaster;
|
|
59
114
|
};
|
|
60
115
|
|
|
61
116
|
export interface VisibleCells {
|
package/src/utils/column-spec.ts
CHANGED
|
@@ -17,6 +17,17 @@ interface ColumnSpecGenerateOptions {
|
|
|
17
17
|
|
|
18
18
|
const defaultWidthForValue = (val) => String(val).length * 8;
|
|
19
19
|
|
|
20
|
+
/** Inferred data type of a column, used to select appropriate
|
|
21
|
+
* sort/filter operators. */
|
|
22
|
+
export type ColumnDataType =
|
|
23
|
+
| "text"
|
|
24
|
+
| "string"
|
|
25
|
+
| "number"
|
|
26
|
+
| "integer"
|
|
27
|
+
| "boolean"
|
|
28
|
+
| "object"
|
|
29
|
+
| "array";
|
|
30
|
+
|
|
20
31
|
export interface ColumnSpec {
|
|
21
32
|
name: string;
|
|
22
33
|
key: string;
|
|
@@ -24,6 +35,7 @@ export interface ColumnSpec {
|
|
|
24
35
|
isValid?: (d: any) => boolean;
|
|
25
36
|
transformValue?: (d: any) => any;
|
|
26
37
|
valueRenderer?: (d: any) => string | React.ReactNode;
|
|
38
|
+
headerRenderer?: (d: any) => string | React.ReactNode;
|
|
27
39
|
dataEditor?: any;
|
|
28
40
|
cellComponent?: any;
|
|
29
41
|
category?: string;
|
|
@@ -31,6 +43,21 @@ export interface ColumnSpec {
|
|
|
31
43
|
inlineEditor?: boolean | React.ComponentType<any> | string | null;
|
|
32
44
|
style?: React.CSSProperties;
|
|
33
45
|
width?: number;
|
|
46
|
+
/** Column-specific table actions (TableAction[]). These appear in the
|
|
47
|
+
* actions toolbar when this column is part of the current selection. */
|
|
48
|
+
actions?: any[];
|
|
49
|
+
/** Column-specific table filters (TableFilter[]). These appear in the
|
|
50
|
+
* filter bar and apply to this column's values. */
|
|
51
|
+
filters?: any[];
|
|
52
|
+
/** Whether this column supports server-side sorting. */
|
|
53
|
+
sortable?: boolean;
|
|
54
|
+
/** Whether this column supports server-side filtering.
|
|
55
|
+
* Set to `true` for default operators, or provide a config object
|
|
56
|
+
* with a custom set of operators. */
|
|
57
|
+
filterable?: boolean | { operators?: string[] };
|
|
58
|
+
/** Inferred data type, used to select context-appropriate filter
|
|
59
|
+
* operators when `filterable` is `true` without explicit operators. */
|
|
60
|
+
dataType?: ColumnDataType;
|
|
34
61
|
}
|
|
35
62
|
|
|
36
63
|
export interface ColumnSpecOptions<T> {
|
|
@@ -89,6 +116,11 @@ export function generateDefaultColumnSpec<T>(
|
|
|
89
116
|
type = "array";
|
|
90
117
|
}
|
|
91
118
|
|
|
119
|
+
// Check if it is strictly a string, if so, we can explicitly mark it as text
|
|
120
|
+
if (type === "string") {
|
|
121
|
+
type = "text";
|
|
122
|
+
}
|
|
123
|
+
|
|
92
124
|
if (types.has(key)) {
|
|
93
125
|
if (types.get(key) !== type) {
|
|
94
126
|
if (type === "number" && types.get(key) === "integer") {
|
|
@@ -118,11 +150,26 @@ export function generateDefaultColumnSpec<T>(
|
|
|
118
150
|
);
|
|
119
151
|
}
|
|
120
152
|
|
|
153
|
+
const dataType = (types.get(key) ?? "string") as ColumnDataType;
|
|
154
|
+
|
|
155
|
+
// Auto-infer sortable/filterable based on data type.
|
|
156
|
+
// Scalar types (string, number, integer, boolean) get sort/filter;
|
|
157
|
+
// complex types (object, array) do not.
|
|
158
|
+
const isScalar =
|
|
159
|
+
dataType === "text" ||
|
|
160
|
+
dataType === "string" ||
|
|
161
|
+
dataType === "number" ||
|
|
162
|
+
dataType === "integer" ||
|
|
163
|
+
dataType === "boolean";
|
|
164
|
+
|
|
121
165
|
spec.push({
|
|
122
166
|
name: key,
|
|
123
167
|
key,
|
|
124
168
|
valueRenderer: defaultRenderers[types.get(key)],
|
|
125
169
|
width,
|
|
170
|
+
dataType,
|
|
171
|
+
sortable: isScalar,
|
|
172
|
+
filterable: isScalar,
|
|
126
173
|
});
|
|
127
174
|
}
|
|
128
175
|
return spec;
|