@vuu-ui/vuu-table-extras 4.0.0-alpha.2 → 4.0.0-alpha.20
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/package.json +15 -13
- package/src/calculated-column/CalculatedColumnPanel.js +2 -2
- package/src/calculated-column/useEditCalculatedColumn.js +1 -1
- package/src/column-expression-input/useColumnExpressionSuggestionProvider.js +2 -2
- package/src/column-formatting-settings/ColumnFormattingPanel.js +12 -9
- package/src/column-formatting-settings/DateTimeFormattingSettings.js +107 -3
- package/src/column-formatting-settings/LongTypeFormattingSettings.js +8 -3
- package/src/column-picker/ColumnModel.js +14 -25
- package/src/column-picker/ColumnPicker.css.js +0 -86
- package/src/column-picker/ColumnPicker.js +12 -180
- package/src/column-picker/useColumnPicker.js +28 -22
- package/src/csv-export/export-utils.js +66 -19
- package/src/csv-export/index.js +1 -1
- package/src/csv-export/useCsvExport.js +9 -1
- package/src/csv-upload/CsvUpload.css.js +34 -0
- package/src/csv-upload/CsvUpload.js +107 -63
- package/src/csv-upload/parse/csv-errors.js +1 -1
- package/src/csv-upload/parse/csv-parse.js +1 -1
- package/src/csv-upload/parse/csv-schema-validation.js +46 -7
- package/src/csv-upload/useCsvUpload.js +12 -14
- package/src/tabbed-table-config-panel/TabbedTableConfigPanel.js +17 -8
- package/src/tabbed-table-config-panel/useTabbedTableConfigPanel.js +1 -1
- package/src/table-footer/TableFooter.js +3 -3
- package/types/calculated-column/CalculatedColumnPanel.d.ts +2 -2
- package/types/column-formatting-settings/DateTimeFormattingSettings.d.ts +1 -1
- package/types/column-picker/ColumnModel.d.ts +4 -3
- package/types/column-picker/ColumnPicker.d.ts +4 -6
- package/types/column-picker/useColumnPicker.d.ts +7 -10
- package/types/column-settings-panel/useColumnSettings.d.ts +3 -3
- package/types/csv-export/export-utils.d.ts +22 -9
- package/types/csv-export/index.d.ts +1 -1
- package/types/csv-export/useCsvExport.d.ts +5 -2
- package/types/csv-upload/CsvUpload.d.ts +1 -5
- package/types/csv-upload/parse/csv-errors.d.ts +1 -1
- package/types/csv-upload/parse/csv-schema-validation.d.ts +8 -2
- package/types/csv-upload/useCsvUpload.d.ts +2 -2
- package/types/index.d.ts +0 -1
- package/types/inline-add-row/useInlineAddRow.d.ts +2 -1
- package/types/tabbed-table-config-panel/useTabbedTableConfigPanel.d.ts +4 -3
- package/types/table-footer/TableFooter.d.ts +2 -2
|
@@ -1,204 +1,36 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
3
3
|
import { useWindow } from "@salt-ds/window";
|
|
4
|
-
import { DragDropProvider, getColumnLabel, isCalculatedColumn, useSortable } from "@vuu-ui/vuu-utils";
|
|
5
4
|
import clsx from "clsx";
|
|
6
|
-
import { forwardRef
|
|
7
|
-
import { Button, Input, ListBox, Option } from "@salt-ds/core";
|
|
8
|
-
import { applyHighlighting } from "@vuu-ui/vuu-table";
|
|
9
|
-
import { Icon, IconButton } from "@vuu-ui/vuu-ui-controls";
|
|
10
|
-
import { ColumnChangeSource } from "./ColumnModel.js";
|
|
5
|
+
import { forwardRef } from "react";
|
|
11
6
|
import { useColumnPicker } from "./useColumnPicker.js";
|
|
7
|
+
import { ItemPicker } from "@vuu-ui/vuu-ui-controls";
|
|
12
8
|
import ColumnPicker_0 from "./ColumnPicker.css";
|
|
13
9
|
const classBase = "vuuColumnPicker";
|
|
14
10
|
const classBaseListItem = "vuuColumnPickerListItem";
|
|
15
|
-
const searchIcon = /*#__PURE__*/ jsx("span", {
|
|
16
|
-
"data-icon": "search"
|
|
17
|
-
});
|
|
18
11
|
const NO_SELECTION = [];
|
|
19
|
-
const
|
|
20
|
-
const { handleRef: sortableHandleRef, ref: sortableRef } = useSortable({
|
|
21
|
-
id,
|
|
22
|
-
index
|
|
23
|
-
});
|
|
24
|
-
const [handleRef, ref] = useMemo(()=>[
|
|
25
|
-
sortableHandleRef,
|
|
26
|
-
sortableRef
|
|
27
|
-
], [
|
|
28
|
-
sortableHandleRef,
|
|
29
|
-
sortableRef
|
|
30
|
-
]);
|
|
31
|
-
return {
|
|
32
|
-
handleRef,
|
|
33
|
-
ref
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const SelectedColumnListItem = ({ className: classNameProp, index, column, onRemove, searchPattern = "", ...optionProps })=>{
|
|
37
|
-
const { handleRef, ref } = useSorting(column.name, index);
|
|
38
|
-
const value = getColumnLabel(column);
|
|
39
|
-
const valueWithHighlighting = applyHighlighting(value, searchPattern);
|
|
40
|
-
const handleRemoveButtonClick = useCallback((e)=>{
|
|
41
|
-
e.stopPropagation();
|
|
42
|
-
onRemove?.(e);
|
|
43
|
-
}, [
|
|
44
|
-
onRemove
|
|
45
|
-
]);
|
|
46
|
-
return /*#__PURE__*/ jsxs(Option, {
|
|
47
|
-
...optionProps,
|
|
48
|
-
className: clsx(classNameProp, classBaseListItem),
|
|
49
|
-
"data-name": column.name,
|
|
50
|
-
ref: ref,
|
|
51
|
-
children: [
|
|
52
|
-
/*#__PURE__*/ jsx(IconButton, {
|
|
53
|
-
"data-embedded": true,
|
|
54
|
-
appearance: "transparent",
|
|
55
|
-
icon: "draggable",
|
|
56
|
-
ref: handleRef,
|
|
57
|
-
size: 16
|
|
58
|
-
}),
|
|
59
|
-
isCalculatedColumn(column.name) ? /*#__PURE__*/ jsx(Icon, {
|
|
60
|
-
className: "vuuCalculatedColumnIcon",
|
|
61
|
-
name: "function"
|
|
62
|
-
}) : null,
|
|
63
|
-
/*#__PURE__*/ jsx("span", {
|
|
64
|
-
className: `${classBase}-text`,
|
|
65
|
-
children: valueWithHighlighting
|
|
66
|
-
}),
|
|
67
|
-
/*#__PURE__*/ jsx(IconButton, {
|
|
68
|
-
className: `${classBaseListItem}-action`,
|
|
69
|
-
"data-embedded": true,
|
|
70
|
-
appearance: "transparent",
|
|
71
|
-
icon: "cross",
|
|
72
|
-
onClick: handleRemoveButtonClick,
|
|
73
|
-
size: 16
|
|
74
|
-
})
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
const AvailableColumnListItem = ({ className: classNameProp, index, column: item, onAdd, searchPattern = "", ...optionProps })=>{
|
|
79
|
-
const value = getColumnLabel(item);
|
|
80
|
-
const valueWithHighlighting = applyHighlighting(value, searchPattern);
|
|
81
|
-
return /*#__PURE__*/ jsxs(Option, {
|
|
82
|
-
...optionProps,
|
|
83
|
-
className: clsx(classNameProp, classBaseListItem),
|
|
84
|
-
"data-name": item.name,
|
|
85
|
-
children: [
|
|
86
|
-
/*#__PURE__*/ jsx("span", {
|
|
87
|
-
className: `${classBase}-text`,
|
|
88
|
-
children: valueWithHighlighting
|
|
89
|
-
}),
|
|
90
|
-
/*#__PURE__*/ jsx(IconButton, {
|
|
91
|
-
className: `${classBaseListItem}-action`,
|
|
92
|
-
"data-embedded": true,
|
|
93
|
-
appearance: "transparent",
|
|
94
|
-
icon: "plus",
|
|
95
|
-
onClick: onAdd,
|
|
96
|
-
size: 16
|
|
97
|
-
})
|
|
98
|
-
]
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
const ColumnPicker_ColumnPicker = /*#__PURE__*/ forwardRef(function({ allowCreateCalculatedColumn, columnModel, className, onClickCreateCalculatedColumn, onSelectionChange, selected = NO_SELECTION, ...htmlAttributes }, forwardedRef) {
|
|
12
|
+
const ColumnPicker_ColumnPicker = /*#__PURE__*/ forwardRef(function({ columnModel, className, onSelectionChange, selected = NO_SELECTION, ...htmlAttributes }, forwardedRef) {
|
|
102
13
|
const targetWindow = useWindow();
|
|
103
14
|
useComponentCssInjection({
|
|
104
15
|
testId: "vuu-column-picker",
|
|
105
16
|
css: ColumnPicker_0,
|
|
106
17
|
window: targetWindow
|
|
107
18
|
});
|
|
108
|
-
const
|
|
109
|
-
setTimeout(()=>{
|
|
110
|
-
el?.querySelector("input")?.focus();
|
|
111
|
-
}, 100);
|
|
112
|
-
}, []);
|
|
113
|
-
const { availableColumns, onAddItemToSelectedList, onChangeSearchInput, onRemoveItemFromSelectedList, searchText, selectedColumns } = useColumnPicker({
|
|
19
|
+
const { allItems, selectedItems, oneOrMoreColumnsIsCalculated, handleSelectedItemsChange } = useColumnPicker({
|
|
114
20
|
columnModel: columnModel
|
|
115
21
|
});
|
|
116
|
-
|
|
117
|
-
const getOptionName = (option)=>{
|
|
118
|
-
if (option) {
|
|
119
|
-
const { name } = option.dataset;
|
|
120
|
-
if (name) return name;
|
|
121
|
-
}
|
|
122
|
-
throw Error("[ColumnPicker] list option has no data-name");
|
|
123
|
-
};
|
|
124
|
-
const handleDragEnd = useCallback(()=>{
|
|
125
|
-
setTimeout(()=>{
|
|
126
|
-
const listItems = listRef.current?.querySelectorAll(".saltOption");
|
|
127
|
-
if (listItems) {
|
|
128
|
-
const orderedColumnNames = Array.from(listItems).map(getOptionName);
|
|
129
|
-
columnModel.reorderSelectedColumns(orderedColumnNames, ColumnChangeSource.ColumnPicker);
|
|
130
|
-
}
|
|
131
|
-
}, 300);
|
|
132
|
-
}, [
|
|
133
|
-
columnModel
|
|
134
|
-
]);
|
|
135
|
-
const oneOrMoreColumnsIsCalculated = selectedColumns.some((column)=>isCalculatedColumn(column.name));
|
|
136
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
22
|
+
return /*#__PURE__*/ jsx(ItemPicker, {
|
|
137
23
|
...htmlAttributes,
|
|
138
24
|
className: clsx(classBase, className, {
|
|
139
25
|
[`${classBase}-withCalculated`]: oneOrMoreColumnsIsCalculated
|
|
140
26
|
}),
|
|
27
|
+
allItems: allItems,
|
|
28
|
+
selectedItems: selectedItems,
|
|
29
|
+
itemTypeName: "column",
|
|
30
|
+
onSelectedItemsChange: handleSelectedItemsChange,
|
|
31
|
+
onSelectionChange: onSelectionChange,
|
|
141
32
|
ref: forwardedRef,
|
|
142
|
-
|
|
143
|
-
/*#__PURE__*/ jsx("form", {
|
|
144
|
-
className: `${classBase}-search`,
|
|
145
|
-
role: "search",
|
|
146
|
-
children: /*#__PURE__*/ jsx(Input, {
|
|
147
|
-
startAdornment: searchIcon,
|
|
148
|
-
placeholder: "Find column",
|
|
149
|
-
ref: searchCallbackRef,
|
|
150
|
-
value: searchText,
|
|
151
|
-
onChange: onChangeSearchInput
|
|
152
|
-
})
|
|
153
|
-
}),
|
|
154
|
-
/*#__PURE__*/ jsxs("div", {
|
|
155
|
-
className: `${classBase}-scrollContainer vuuScrollable`,
|
|
156
|
-
children: [
|
|
157
|
-
/*#__PURE__*/ jsx("div", {
|
|
158
|
-
className: `${classBase}-sectionHeader`,
|
|
159
|
-
children: "Columns in view"
|
|
160
|
-
}),
|
|
161
|
-
/*#__PURE__*/ jsx(DragDropProvider, {
|
|
162
|
-
onDragEnd: handleDragEnd,
|
|
163
|
-
children: /*#__PURE__*/ jsx(ListBox, {
|
|
164
|
-
className: `${classBase}-selectedList`,
|
|
165
|
-
onSelectionChange: onSelectionChange,
|
|
166
|
-
ref: listRef,
|
|
167
|
-
selected: selected,
|
|
168
|
-
children: selectedColumns.map((column, index)=>/*#__PURE__*/ jsx(SelectedColumnListItem, {
|
|
169
|
-
column: column,
|
|
170
|
-
index: index,
|
|
171
|
-
onRemove: onRemoveItemFromSelectedList,
|
|
172
|
-
searchPattern: searchText.toLowerCase(),
|
|
173
|
-
value: column
|
|
174
|
-
}, column.name))
|
|
175
|
-
})
|
|
176
|
-
}),
|
|
177
|
-
/*#__PURE__*/ jsx("div", {
|
|
178
|
-
className: clsx(`${classBase}-sectionHeader`, `${classBase}-availableHeader`),
|
|
179
|
-
children: "Available columns"
|
|
180
|
-
}),
|
|
181
|
-
/*#__PURE__*/ jsx(ListBox, {
|
|
182
|
-
className: `${classBase}-availableList`,
|
|
183
|
-
selected: NO_SELECTION,
|
|
184
|
-
children: availableColumns.map((column, index)=>/*#__PURE__*/ jsx(AvailableColumnListItem, {
|
|
185
|
-
column: column,
|
|
186
|
-
index: index,
|
|
187
|
-
onAdd: onAddItemToSelectedList,
|
|
188
|
-
searchPattern: searchText.toLowerCase(),
|
|
189
|
-
value: column
|
|
190
|
-
}, column.name))
|
|
191
|
-
})
|
|
192
|
-
]
|
|
193
|
-
}),
|
|
194
|
-
allowCreateCalculatedColumn ? /*#__PURE__*/ jsx("div", {
|
|
195
|
-
className: `${classBase}-column-buttons`,
|
|
196
|
-
children: /*#__PURE__*/ jsx(Button, {
|
|
197
|
-
onClick: onClickCreateCalculatedColumn,
|
|
198
|
-
children: "Create calculated column"
|
|
199
|
-
})
|
|
200
|
-
}) : null
|
|
201
|
-
]
|
|
33
|
+
selected: selected
|
|
202
34
|
});
|
|
203
35
|
});
|
|
204
36
|
export { ColumnPicker_ColumnPicker as ColumnPicker, classBaseListItem };
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
1
|
+
import { isCalculatedColumn } from "@vuu-ui/vuu-utils";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { ColumnChangeSource } from "./ColumnModel.js";
|
|
4
4
|
const SOURCE = ColumnChangeSource.ColumnPicker;
|
|
5
|
-
const columnName = (target)=>{
|
|
6
|
-
const listItem = queryClosest(target, ".saltOption", true);
|
|
7
|
-
const { name } = listItem.dataset;
|
|
8
|
-
if (name) return name;
|
|
9
|
-
throw Error("[useColumnPicker] column name could not be identified, data-name attribute not found");
|
|
10
|
-
};
|
|
11
5
|
const useColumnPicker = ({ columnModel: model })=>{
|
|
12
6
|
const [, forceRender] = useState({});
|
|
13
7
|
useEffect(()=>{
|
|
@@ -18,25 +12,37 @@ const useColumnPicker = ({ columnModel: model })=>{
|
|
|
18
12
|
}, [
|
|
19
13
|
model
|
|
20
14
|
]);
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
15
|
+
const allItems = useMemo(()=>{
|
|
16
|
+
const itemDescriptors = model.allColumns.map((column)=>({
|
|
17
|
+
name: column.name,
|
|
18
|
+
label: column.label,
|
|
19
|
+
icon: isCalculatedColumn(column.name) ? "vuuCalculatedColumnIcon" : void 0
|
|
20
|
+
}));
|
|
21
|
+
return itemDescriptors;
|
|
24
22
|
}, [
|
|
25
|
-
model
|
|
23
|
+
model.allColumns
|
|
26
24
|
]);
|
|
27
|
-
const
|
|
28
|
-
model
|
|
25
|
+
const selectedItems = useMemo(()=>{
|
|
26
|
+
const itemDescriptors = model.selectedColumns.map((column)=>allItems.find((item)=>item.name === column.name));
|
|
27
|
+
return itemDescriptors;
|
|
28
|
+
}, [
|
|
29
|
+
model.selectedColumns,
|
|
30
|
+
allItems
|
|
29
31
|
]);
|
|
30
|
-
const
|
|
31
|
-
model
|
|
32
|
+
const oneOrMoreColumnsIsCalculated = useMemo(()=>model.selectedColumns.some((column)=>isCalculatedColumn(column.name)), [
|
|
33
|
+
model.selectedColumns
|
|
34
|
+
]);
|
|
35
|
+
const handleSelectedItemsChange = useCallback((newSelectedItems)=>{
|
|
36
|
+
const newSelectedColumns = newSelectedItems.map((item)=>model.allColumns.find((column)=>column.name === item.name));
|
|
37
|
+
model.addRemoveOrReorderSelectedColumns(newSelectedColumns, SOURCE);
|
|
38
|
+
}, [
|
|
39
|
+
model.allColumns
|
|
32
40
|
]);
|
|
33
41
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
searchText: model.searchPattern,
|
|
39
|
-
selectedColumns: model.selectedColumns
|
|
42
|
+
allItems,
|
|
43
|
+
selectedItems,
|
|
44
|
+
oneOrMoreColumnsIsCalculated,
|
|
45
|
+
handleSelectedItemsChange
|
|
40
46
|
};
|
|
41
47
|
};
|
|
42
48
|
export { useColumnPicker };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Range, isSessionTable, metadataKeys } from "@vuu-ui/vuu-utils";
|
|
1
|
+
import { Range, buildColumnMap, getValueFormatter, isSessionTable, metadataKeys } from "@vuu-ui/vuu-utils";
|
|
2
2
|
const EXPORT_EXCLUDED_COLUMNS = new Set([
|
|
3
3
|
"vuuMsg",
|
|
4
4
|
"vuuAction",
|
|
@@ -28,10 +28,31 @@ const triggerCsvDownload = (csv, filename)=>{
|
|
|
28
28
|
document.body.removeChild(a);
|
|
29
29
|
setTimeout(()=>URL.revokeObjectURL(url), 10000);
|
|
30
30
|
};
|
|
31
|
+
const createRowAccessor = (row, columnMap)=>new Proxy({}, {
|
|
32
|
+
get (_, prop) {
|
|
33
|
+
if ("string" == typeof prop) {
|
|
34
|
+
const idx = columnMap[prop];
|
|
35
|
+
if (void 0 !== idx) return row[idx];
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
has (_, prop) {
|
|
39
|
+
return "string" == typeof prop && void 0 !== columnMap[prop];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const isExportableColumn = (descriptor)=>{
|
|
43
|
+
if (!descriptor) return true;
|
|
44
|
+
if (false === descriptor.exportable) return false;
|
|
45
|
+
if (descriptor.hidden) return false;
|
|
46
|
+
if (descriptor.isSystemColumn) return false;
|
|
47
|
+
if (true === descriptor.exportable) return true;
|
|
48
|
+
if ("client" === descriptor.source && !descriptor.exportFormatter) return false;
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
31
51
|
const exportCsvTemplate = async (dataSource, options = {})=>{
|
|
32
52
|
const { filename = "template.csv", excludeColumns = [], columns, overrides, timeout = DEFAULT_TEMPLATE_TIMEOUT, onError, onSuccess } = options;
|
|
33
|
-
const
|
|
34
|
-
|
|
53
|
+
const targetColumnNames = columns ? columns.filter((col)=>"string" == typeof col ? true : isExportableColumn(col) && "client" !== col.source).map((col)=>"string" == typeof col ? col : col.name) : void 0;
|
|
54
|
+
const sessionOverrides = overrides ?? (targetColumnNames ? {
|
|
55
|
+
columns: targetColumnNames
|
|
35
56
|
} : void 0);
|
|
36
57
|
if (!isSessionTable(dataSource.table) && dataSource.createSessionDataSource && "initialising" !== dataSource.status && "unsubscribed" !== dataSource.status) try {
|
|
37
58
|
const sessionDataSource = await dataSource.createSessionDataSource("Empty", "export", sessionOverrides);
|
|
@@ -72,7 +93,7 @@ const exportCsvTemplate = async (dataSource, options = {})=>{
|
|
|
72
93
|
console.warn("[exportCsvTemplate] createSessionDataSource failed, falling back to tableSchema", error);
|
|
73
94
|
}
|
|
74
95
|
const schema = dataSource.tableSchema;
|
|
75
|
-
const targetColumns =
|
|
96
|
+
const targetColumns = targetColumnNames ?? overrides?.columns;
|
|
76
97
|
if (void 0 !== targetColumns) {
|
|
77
98
|
if (schema) {
|
|
78
99
|
const schemaColumnNames = new Set(schema.columns.map((col)=>col.name));
|
|
@@ -99,7 +120,18 @@ const exportCsvTemplate = async (dataSource, options = {})=>{
|
|
|
99
120
|
onSuccess?.();
|
|
100
121
|
};
|
|
101
122
|
const exportSessionTableToCsv = async (dataSource, options = {})=>{
|
|
102
|
-
const { filename = "export.csv", copyOption = "All", excludeColumns = [], maxRows = MAX_EXPORT_ROWS, columnDescriptors, overrides, timeout = DEFAULT_EXPORT_TIMEOUT, onError, onSuccess } = options;
|
|
123
|
+
const { filename = "export.csv", copyOption = "All", excludeColumns = [], maxRows = MAX_EXPORT_ROWS, columnDescriptors: rawColumnDescriptors, columns: rawColumns, overrides, timeout = DEFAULT_EXPORT_TIMEOUT, onError, onSuccess } = options;
|
|
124
|
+
const rawInputColumns = rawColumns ?? rawColumnDescriptors;
|
|
125
|
+
const columnDescriptors = rawInputColumns?.map((col)=>"string" == typeof col ? {
|
|
126
|
+
name: col
|
|
127
|
+
} : col);
|
|
128
|
+
const sessionOverrides = overrides ? {
|
|
129
|
+
...overrides,
|
|
130
|
+
columns: overrides.columns?.filter((name)=>{
|
|
131
|
+
const desc = columnDescriptors?.find((d)=>d.name === name);
|
|
132
|
+
return desc?.source !== "client";
|
|
133
|
+
})
|
|
134
|
+
} : void 0;
|
|
103
135
|
const isRemote = !!dataSource.isRemote;
|
|
104
136
|
if (isRemote && !isSessionTable(dataSource.table) && ("initialising" === dataSource.status || "unsubscribed" === dataSource.status)) {
|
|
105
137
|
const error = new Error(`exportSessionTableToCsv: dataSource must be subscribed before exporting (current status: "${dataSource.status}")`);
|
|
@@ -108,7 +140,7 @@ const exportSessionTableToCsv = async (dataSource, options = {})=>{
|
|
|
108
140
|
}
|
|
109
141
|
let sessionDataSource;
|
|
110
142
|
if (!isSessionTable(dataSource.table) && dataSource.createSessionDataSource) try {
|
|
111
|
-
sessionDataSource = await dataSource.createSessionDataSource(copyOption, "export",
|
|
143
|
+
sessionDataSource = await dataSource.createSessionDataSource(copyOption, "export", sessionOverrides);
|
|
112
144
|
} catch (err) {
|
|
113
145
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
114
146
|
if (onError) return void onError(error);
|
|
@@ -152,18 +184,23 @@ const exportSessionTableToCsv = async (dataSource, options = {})=>{
|
|
|
152
184
|
const { columns } = message;
|
|
153
185
|
if (columnDescriptors) {
|
|
154
186
|
const subscribedSet = new Set(columns);
|
|
155
|
-
const unknown = columnDescriptors.filter((d)
|
|
187
|
+
const unknown = columnDescriptors.filter((d)=>"client" !== d.source && !excluded.has(d.name) && !subscribedSet.has(d.name)).map((d)=>d.name);
|
|
156
188
|
if (unknown.length > 0) return void fail(new Error(`exportToCsv: unknown column(s) in columnDescriptors: ${unknown.join(", ")}`));
|
|
157
189
|
descriptorMap = Object.fromEntries(columnDescriptors.map((d)=>[
|
|
158
190
|
d.name,
|
|
159
191
|
d
|
|
160
192
|
]));
|
|
161
193
|
}
|
|
162
|
-
exportCols =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
194
|
+
if (rawColumns) exportCols = rawColumns.map((c)=>"string" == typeof c ? c : c.name).filter((name)=>!excluded.has(name) && isExportableColumn(descriptorMap[name]));
|
|
195
|
+
else if (columnDescriptors?.some((d)=>"client" === d.source)) {
|
|
196
|
+
const definedNames = new Set(columnDescriptors.map((d)=>d.name));
|
|
197
|
+
const remainingSubscribed = columns.filter((name)=>!excluded.has(name) && !definedNames.has(name) && isExportableColumn(descriptorMap[name]));
|
|
198
|
+
exportCols = [
|
|
199
|
+
...columnDescriptors.filter((d)=>!excluded.has(d.name) && isExportableColumn(d)).map((d)=>d.name),
|
|
200
|
+
...remainingSubscribed
|
|
201
|
+
];
|
|
202
|
+
} else exportCols = columns.filter((name)=>!excluded.has(name) && isExportableColumn(descriptorMap[name]));
|
|
203
|
+
colNameToRowIdx = buildColumnMap(columns);
|
|
167
204
|
} else if ("viewport-update" === message.type) {
|
|
168
205
|
if ("size-only" === message.mode) {
|
|
169
206
|
totalSize = message.size ?? 0;
|
|
@@ -191,11 +228,21 @@ const exportSessionTableToCsv = async (dataSource, options = {})=>{
|
|
|
191
228
|
];
|
|
192
229
|
for(let i = 0; i < totalSize; i++){
|
|
193
230
|
const row = collectedRows.get(i);
|
|
194
|
-
if (row)
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
231
|
+
if (row) {
|
|
232
|
+
const rowAccessor = createRowAccessor(row, colNameToRowIdx);
|
|
233
|
+
lines.push(exportCols.map((c)=>{
|
|
234
|
+
const descriptor = descriptorMap[c];
|
|
235
|
+
const isClientCol = descriptor?.source === "client";
|
|
236
|
+
const raw = isClientCol ? void 0 : void 0 !== colNameToRowIdx[c] ? row[colNameToRowIdx[c]] : void 0;
|
|
237
|
+
let formatted;
|
|
238
|
+
if (descriptor?.exportFormatter) formatted = descriptor.exportFormatter(raw, rowAccessor);
|
|
239
|
+
else if (descriptor && ("type" in descriptor || "serverDataType" in descriptor)) {
|
|
240
|
+
const tableFormatter = getValueFormatter(descriptor);
|
|
241
|
+
formatted = tableFormatter(raw);
|
|
242
|
+
} else formatted = raw;
|
|
243
|
+
return csvCell(formatted);
|
|
244
|
+
}).join(","));
|
|
245
|
+
}
|
|
199
246
|
}
|
|
200
247
|
triggerCsvDownload(lines.join("\r\n"), filename);
|
|
201
248
|
onSuccess?.();
|
|
@@ -213,9 +260,9 @@ const exportSessionTableToCsv = async (dataSource, options = {})=>{
|
|
|
213
260
|
};
|
|
214
261
|
activeSessionDataSource.subscribe({
|
|
215
262
|
range: Range(0, 0),
|
|
216
|
-
columns:
|
|
263
|
+
columns: sessionOverrides?.columns
|
|
217
264
|
}, handleMessage);
|
|
218
265
|
});
|
|
219
266
|
};
|
|
220
267
|
const exportToCsv = async (dataSource, options)=>exportSessionTableToCsv(dataSource, options);
|
|
221
|
-
export { exportCsvTemplate, exportSessionTableToCsv, exportToCsv };
|
|
268
|
+
export { exportCsvTemplate, exportSessionTableToCsv, exportToCsv, isExportableColumn };
|
package/src/csv-export/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { exportCsvTemplate, exportSessionTableToCsv, exportToCsv } from "./export-utils.js";
|
|
1
|
+
export { exportCsvTemplate, exportSessionTableToCsv, exportToCsv, isExportableColumn } from "./export-utils.js";
|
|
2
2
|
export { useCsvExport } from "./useCsvExport.js";
|
|
@@ -6,7 +6,7 @@ function useCsvExport(propsOrDataSource) {
|
|
|
6
6
|
const config = propsOrDataSource && "table" in propsOrDataSource ? {
|
|
7
7
|
dataSource: propsOrDataSource
|
|
8
8
|
} : propsOrDataSource ?? {};
|
|
9
|
-
const { dataSource: defaultDataSource, onError, onSuccess } = config;
|
|
9
|
+
const { dataSource: defaultDataSource, tableConfig, columns: defaultColumns, onError, onSuccess } = config;
|
|
10
10
|
const exportCsv = useCallback(async (options, overrideDataSource)=>{
|
|
11
11
|
const activeDataSource = overrideDataSource ?? defaultDataSource;
|
|
12
12
|
if (!activeDataSource) {
|
|
@@ -19,7 +19,9 @@ function useCsvExport(propsOrDataSource) {
|
|
|
19
19
|
setIsExporting(true);
|
|
20
20
|
setError(null);
|
|
21
21
|
try {
|
|
22
|
+
const columnsToExport = options?.columns ?? options?.columnDescriptors ?? defaultColumns ?? tableConfig?.columns;
|
|
22
23
|
await exportToCsv(activeDataSource, {
|
|
24
|
+
columns: columnsToExport,
|
|
23
25
|
...options,
|
|
24
26
|
onError: (err)=>{
|
|
25
27
|
setError(err);
|
|
@@ -42,6 +44,8 @@ function useCsvExport(propsOrDataSource) {
|
|
|
42
44
|
}
|
|
43
45
|
}, [
|
|
44
46
|
defaultDataSource,
|
|
47
|
+
defaultColumns,
|
|
48
|
+
tableConfig,
|
|
45
49
|
onError,
|
|
46
50
|
onSuccess
|
|
47
51
|
]);
|
|
@@ -57,7 +61,9 @@ function useCsvExport(propsOrDataSource) {
|
|
|
57
61
|
setIsExporting(true);
|
|
58
62
|
setError(null);
|
|
59
63
|
try {
|
|
64
|
+
const templateColumns = options?.columns ?? defaultColumns ?? tableConfig?.columns;
|
|
60
65
|
await exportCsvTemplate(activeDataSource, {
|
|
66
|
+
columns: templateColumns,
|
|
61
67
|
...options,
|
|
62
68
|
onError: (err)=>{
|
|
63
69
|
setError(err);
|
|
@@ -80,6 +86,8 @@ function useCsvExport(propsOrDataSource) {
|
|
|
80
86
|
}
|
|
81
87
|
}, [
|
|
82
88
|
defaultDataSource,
|
|
89
|
+
defaultColumns,
|
|
90
|
+
tableConfig,
|
|
83
91
|
onError,
|
|
84
92
|
onSuccess
|
|
85
93
|
]);
|
|
@@ -14,6 +14,40 @@ const css = `
|
|
|
14
14
|
display: grid;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
.vuuCsvUpload-errorContainer {
|
|
18
|
+
margin-top: var(--salt-spacing-100);
|
|
19
|
+
width: 100%;
|
|
20
|
+
max-width: 480px;
|
|
21
|
+
max-height: 120px;
|
|
22
|
+
padding: var(--salt-spacing-100) var(--salt-spacing-200);
|
|
23
|
+
background-color: rgba(var(--salt-palette-interact-error-background), .05);
|
|
24
|
+
border-radius: var(--salt-size-borderRadius);
|
|
25
|
+
text-align: left;
|
|
26
|
+
overflow-y: auto;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.vuuCsvUpload-errorList {
|
|
30
|
+
padding-left: var(--salt-spacing-200);
|
|
31
|
+
margin: 0;
|
|
32
|
+
list-style-type: disc;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.vuuCsvUpload-errorItem {
|
|
36
|
+
font-size: var(--salt-text-fontSize-small);
|
|
37
|
+
color: var(--salt-status-error-foreground);
|
|
38
|
+
line-height: var(--salt-text-lineHeight-small);
|
|
39
|
+
word-break: break-word;
|
|
40
|
+
margin-bottom: var(--salt-spacing-50);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.vuuCsvUpload-importErrorItem {
|
|
44
|
+
text-align: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.vuuCsvUpload-rectifyPrompt {
|
|
48
|
+
margin-top: var(--salt-spacing-100);
|
|
49
|
+
}
|
|
50
|
+
|
|
17
51
|
.vuuCsvUpload-errors {
|
|
18
52
|
border: solid 1px var(--salt-status-error-borderColor);
|
|
19
53
|
border-radius: var(--salt-size-borderRadius);
|