@vuu-ui/vuu-table-extras 3.2.0 → 3.3.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/package.json +12 -12
- package/src/csv-upload/CsvUpload.js +8 -1
- package/src/csv-upload/data-upload-preview/DataUploadPreview.js +2 -2
- package/src/csv-upload/parse/csv-constants.js +2 -1
- package/src/csv-upload/parse/csv-schema-validation.js +2 -3
- package/src/csv-upload/useCsvUpload.js +14 -6
- package/types/csv-upload/CsvUpload.d.ts +4 -3
- package/types/csv-upload/parse/csv-constants.d.ts +1 -0
- package/types/csv-upload/useCsvUpload.d.ts +4 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.
|
|
2
|
+
"version": "3.3.1",
|
|
3
3
|
"author": "heswell",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
"lezer-generate:column": "lezer-generator --output ./src/column-expression-input/column-language-parser/generated/column-parser.js ./src/column-expression-input/column-language-parser/grammar/column.grammar"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@vuu-ui/vuu-filter-types": "3.
|
|
15
|
-
"@vuu-ui/vuu-protocol-types": "3.
|
|
14
|
+
"@vuu-ui/vuu-filter-types": "3.3.1",
|
|
15
|
+
"@vuu-ui/vuu-protocol-types": "3.3.1"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@vuu-ui/vuu-codemirror": "3.
|
|
19
|
-
"@vuu-ui/vuu-data-editing": "3.
|
|
20
|
-
"@vuu-ui/vuu-data-react": "3.
|
|
21
|
-
"@vuu-ui/vuu-data-types": "3.
|
|
22
|
-
"@vuu-ui/vuu-table-types": "3.
|
|
23
|
-
"@vuu-ui/vuu-popups": "3.
|
|
24
|
-
"@vuu-ui/vuu-table": "3.
|
|
25
|
-
"@vuu-ui/vuu-utils": "3.
|
|
26
|
-
"@vuu-ui/vuu-ui-controls": "3.
|
|
18
|
+
"@vuu-ui/vuu-codemirror": "3.3.1",
|
|
19
|
+
"@vuu-ui/vuu-data-editing": "3.3.1",
|
|
20
|
+
"@vuu-ui/vuu-data-react": "3.3.1",
|
|
21
|
+
"@vuu-ui/vuu-data-types": "3.3.1",
|
|
22
|
+
"@vuu-ui/vuu-table-types": "3.3.1",
|
|
23
|
+
"@vuu-ui/vuu-popups": "3.3.1",
|
|
24
|
+
"@vuu-ui/vuu-table": "3.3.1",
|
|
25
|
+
"@vuu-ui/vuu-utils": "3.3.1",
|
|
26
|
+
"@vuu-ui/vuu-ui-controls": "3.3.1",
|
|
27
27
|
"@lezer/lr": "1.4.2",
|
|
28
28
|
"@salt-ds/core": "1.54.1",
|
|
29
29
|
"@salt-ds/lab": "1.0.0-alpha.83",
|
|
@@ -48,8 +48,15 @@ const CsvUpload_CsvUpload = (props)=>{
|
|
|
48
48
|
/*#__PURE__*/ jsx("div", {
|
|
49
49
|
children: "Your file contains errors"
|
|
50
50
|
}),
|
|
51
|
+
/*#__PURE__*/ jsx("ul", {
|
|
52
|
+
className: `${classBase}-errorList`,
|
|
53
|
+
children: validation.errors.filter((e)=>e.column in validation.errorMap.fileErrors).map((error, i)=>/*#__PURE__*/ jsx("li", {
|
|
54
|
+
className: `${classBase}-errorItem`,
|
|
55
|
+
children: error.message
|
|
56
|
+
}, i))
|
|
57
|
+
}),
|
|
51
58
|
/*#__PURE__*/ jsx("div", {
|
|
52
|
-
children: "
|
|
59
|
+
children: "Please rectify and reupload"
|
|
53
60
|
})
|
|
54
61
|
]
|
|
55
62
|
}) : /*#__PURE__*/ jsx("div", {
|
|
@@ -38,7 +38,7 @@ const DataUploadPreview_DataUploadPreview = ({ className, editSession, onClose,
|
|
|
38
38
|
editSession,
|
|
39
39
|
onClose
|
|
40
40
|
});
|
|
41
|
-
const isRowSelectable = useCallback((dataRow)=>"deleteRow" !== dataRow.
|
|
41
|
+
const isRowSelectable = useCallback((dataRow)=>"deleteRow" !== dataRow.vuuAction, []);
|
|
42
42
|
const config = useMemo(()=>{
|
|
43
43
|
const columns = tableSchema.columns.map((column)=>"vuuMsg" === column.name ? {
|
|
44
44
|
...column,
|
|
@@ -60,7 +60,7 @@ const DataUploadPreview_DataUploadPreview = ({ className, editSession, onClose,
|
|
|
60
60
|
return {
|
|
61
61
|
columns: columns.concat({
|
|
62
62
|
hidden: true,
|
|
63
|
-
name: "
|
|
63
|
+
name: "vuuAction"
|
|
64
64
|
}, undoColumn),
|
|
65
65
|
columnDefaultWidth: 150,
|
|
66
66
|
rowClassNameGenerators: rowClassNameGenerators,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getTypedValue } from "@vuu-ui/vuu-utils";
|
|
2
2
|
import { CsvValidationErrorEnum, addCsvFileError, addCsvRowError, createCsvErrorState } from "./csv-errors.js";
|
|
3
|
-
import { CSV_FIRST_DATA_ROW_NUMBER } from "./csv-constants.js";
|
|
4
|
-
const MAX_ROWS_IN_CSV = 25000;
|
|
3
|
+
import { CSV_FIRST_DATA_ROW_NUMBER, MAX_ROWS_IN_CSV } from "./csv-constants.js";
|
|
5
4
|
const validateCsvAgainstSchema = (parsed, tableSchema, options)=>{
|
|
6
5
|
const schemaColumns = new Map(tableSchema.columns.map((col)=>[
|
|
7
6
|
col.name,
|
|
@@ -11,7 +10,7 @@ const validateCsvAgainstSchema = (parsed, tableSchema, options)=>{
|
|
|
11
10
|
const errorState = createCsvErrorState();
|
|
12
11
|
if (!parsed.header.includes(tableSchema.key)) addCsvFileError(errorState, tableSchema.key, CsvValidationErrorEnum.MISSING_KEY_COLUMN, `CSV must include key column '${tableSchema.key}'.`);
|
|
13
12
|
parsed.header.forEach((column)=>{
|
|
14
|
-
if (!schemaColumns.has(column)) addCsvFileError(errorState, column, CsvValidationErrorEnum.UNKNOWN_COLUMN,
|
|
13
|
+
if (!schemaColumns.has(column)) addCsvFileError(errorState, column, CsvValidationErrorEnum.UNKNOWN_COLUMN, `Column ${column} is not present in table schema.`, column);
|
|
15
14
|
});
|
|
16
15
|
if (parsed.rows.length > maxRows) addCsvFileError(errorState, "*", CsvValidationErrorEnum.MAX_ROWS_EXCEEDED, `CSV row count ${parsed.rows.length} exceeds maxRows ${maxRows}.`, String(parsed.rows.length));
|
|
17
16
|
const typedRows = [];
|
|
@@ -5,13 +5,18 @@ import { parseCsv } from "./parse/csv-parse.js";
|
|
|
5
5
|
import { validateCsvAgainstSchema } from "./parse/csv-schema-validation.js";
|
|
6
6
|
import { buildRowErrorMessage, createUploadError, hasFileParseErrors, isCsvParseError, mergeValidationWithParseErrors, toErrorMessage } from "./parse/csv-upload-utils.js";
|
|
7
7
|
import { CSV_FIRST_DATA_ROW_NUMBER } from "./parse/csv-constants.js";
|
|
8
|
-
const useCsvUpload = ({ dataSource, importMode = "direct", onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions })=>{
|
|
8
|
+
const useCsvUpload = ({ dataSource, importMode = "direct", onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults })=>{
|
|
9
9
|
const [validation, setValidation] = useState();
|
|
10
10
|
const [sessionTable, setSessionTable] = useState();
|
|
11
11
|
const [isProcessingFile, setIsProcessingFile] = useState(false);
|
|
12
12
|
const [isImporting, setIsImporting] = useState(false);
|
|
13
|
-
const editSession = useMemo(()=>new EditSession(
|
|
14
|
-
|
|
13
|
+
const editSession = useMemo(()=>new EditSession({
|
|
14
|
+
dataSource,
|
|
15
|
+
editSessionApi: "createSessionDataSource",
|
|
16
|
+
rowDefaults
|
|
17
|
+
}), [
|
|
18
|
+
dataSource,
|
|
19
|
+
rowDefaults
|
|
15
20
|
]);
|
|
16
21
|
const ownsEditSessionRef = useRef(true);
|
|
17
22
|
const operationIdRef = useRef(0);
|
|
@@ -85,9 +90,12 @@ const useCsvUpload = ({ dataSource, importMode = "direct", onImportSessionEnded,
|
|
|
85
90
|
for (const { rowNum, rowData, vuuMsg } of allRows){
|
|
86
91
|
if (operationId !== operationIdRef.current) return false;
|
|
87
92
|
try {
|
|
88
|
-
const payload = {
|
|
93
|
+
const payload = vuuMsg ? {
|
|
94
|
+
vuuRowNum: rowNum,
|
|
95
|
+
vuuMsg
|
|
96
|
+
} : {
|
|
89
97
|
...rowData,
|
|
90
|
-
rowNum,
|
|
98
|
+
vuuRowNum: rowNum,
|
|
91
99
|
vuuMsg
|
|
92
100
|
};
|
|
93
101
|
const result = await editSession.addRow(payload);
|
|
@@ -103,7 +111,7 @@ const useCsvUpload = ({ dataSource, importMode = "direct", onImportSessionEnded,
|
|
|
103
111
|
editSession
|
|
104
112
|
]);
|
|
105
113
|
const beginEditSession = useCallback(async ()=>{
|
|
106
|
-
const sessionDataSource = await editSession.begin("Empty");
|
|
114
|
+
const sessionDataSource = await editSession.begin("Empty", "import");
|
|
107
115
|
const sessionVuuTable = sessionDataSource?.table;
|
|
108
116
|
if (void 0 === sessionDataSource || void 0 === sessionVuuTable || !isSessionTable(sessionVuuTable)) throw Error("CsvUpload createSessionDataSource returned no session datasource.");
|
|
109
117
|
if (!sessionDataSource.columns.includes("vuuMsg")) sessionDataSource.columns = sessionDataSource.columns.concat("vuuMsg");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
import type { EditSession } from "@vuu-ui/vuu-data-editing";
|
|
4
|
-
import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
|
|
2
|
+
import type { RowDefaultDataItemValues, EditSession } from "@vuu-ui/vuu-data-editing";
|
|
5
3
|
import type { CsvParseError, CsvParseOptions } from "./parse/csv-parse";
|
|
6
4
|
import type { CsvValidationStructuredError } from "./parse/csv-schema-validation";
|
|
5
|
+
import type { DataSource } from "@vuu-ui/vuu-data-types";
|
|
6
|
+
import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
|
|
7
7
|
import type { CsvUploadTableData } from "./parse/csv-upload-utils";
|
|
8
8
|
export type CsvUploadImportedResult = {
|
|
9
9
|
tableData: CsvUploadTableData;
|
|
@@ -51,5 +51,6 @@ export interface CsvUploadProps {
|
|
|
51
51
|
open?: boolean;
|
|
52
52
|
parseOptions?: CsvParseOptions;
|
|
53
53
|
importMode?: "direct" | "preview";
|
|
54
|
+
rowDefaults?: RowDefaultDataItemValues;
|
|
54
55
|
}
|
|
55
56
|
export declare const CsvUpload: (props: CsvUploadProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
|
|
2
|
+
import { type RowDefaultDataItemValues } from "@vuu-ui/vuu-data-editing";
|
|
2
3
|
import { type CsvParseOptions } from "./parse/csv-parse";
|
|
3
4
|
import { type CsvValidationResult } from "./parse/csv-schema-validation";
|
|
4
5
|
import type { CsvUploadErrorResult, CsvUploadImportedResult, CsvUploadPreviewResult, CsvUploadSessionEndResult, CsvUploadSessionTable } from "./CsvUpload";
|
|
@@ -13,6 +14,8 @@ export interface CsvUploadHookProps {
|
|
|
13
14
|
onPreview?: (result: CsvUploadPreviewResult) => void;
|
|
14
15
|
onProcessingStarted?: () => void;
|
|
15
16
|
parseOptions?: CsvParseOptions;
|
|
17
|
+
/** Default column values applied to every addRow call. Pass a stable reference — a new object triggers EditSession recreation. */
|
|
18
|
+
rowDefaults?: RowDefaultDataItemValues;
|
|
16
19
|
}
|
|
17
20
|
export type UseCsvUploadReturn = {
|
|
18
21
|
canImport: boolean;
|
|
@@ -26,4 +29,4 @@ export type UseCsvUploadReturn = {
|
|
|
26
29
|
schema: TableSchema | undefined;
|
|
27
30
|
validation: CsvValidationResult | undefined;
|
|
28
31
|
};
|
|
29
|
-
export declare const useCsvUpload: ({ dataSource, importMode, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, }: CsvUploadHookProps) => UseCsvUploadReturn;
|
|
32
|
+
export declare const useCsvUpload: ({ dataSource, importMode, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, }: CsvUploadHookProps) => UseCsvUploadReturn;
|