@vuu-ui/vuu-table-extras 4.0.0-alpha.1 → 4.0.0-alpha.2
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 +52 -32
- package/src/csv-upload/parse/csv-constants.js +2 -2
- package/src/csv-upload/parse/csv-errors.js +1 -0
- package/src/csv-upload/parse/csv-schema-validation.js +9 -0
- package/src/csv-upload/useCsvUpload.js +7 -5
- package/types/csv-upload/CsvUpload.d.ts +2 -1
- package/types/csv-upload/data-upload-preview/useDataUploadPreview.d.ts +1 -1
- package/types/csv-upload/index.d.ts +1 -1
- package/types/csv-upload/parse/csv-constants.d.ts +2 -2
- package/types/csv-upload/parse/csv-errors.d.ts +2 -1
- package/types/csv-upload/parse/csv-schema-validation.d.ts +2 -0
- package/types/csv-upload/parse/index.d.ts +1 -1
- package/types/csv-upload/useCsvUpload.d.ts +3 -2
- package/types/src/csv-upload/CsvUpload.d.ts +2 -1
- package/types/src/csv-upload/index.d.ts +1 -1
- package/types/src/csv-upload/parse/csv-constants.d.ts +2 -2
- package/types/src/csv-upload/parse/csv-errors.d.ts +2 -1
- package/types/src/csv-upload/parse/csv-schema-validation.d.ts +2 -0
- package/types/src/csv-upload/parse/index.d.ts +1 -1
- package/types/src/csv-upload/useCsvUpload.d.ts +3 -2
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.0.0-alpha.
|
|
2
|
+
"version": "4.0.0-alpha.2",
|
|
3
3
|
"author": "heswell",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
"lezer-generate:column": "lezer-generator --output ./src/column-expression-input/column-language-parser/generated/column-parser.ts ./src/column-expression-input/column-language-parser/grammar/column.grammar"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@vuu-ui/vuu-filter-types": "4.0.0-alpha.
|
|
16
|
-
"@vuu-ui/vuu-protocol-types": "4.0.0-alpha.
|
|
15
|
+
"@vuu-ui/vuu-filter-types": "4.0.0-alpha.2",
|
|
16
|
+
"@vuu-ui/vuu-protocol-types": "4.0.0-alpha.2"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@vuu-ui/vuu-codemirror": "4.0.0-alpha.
|
|
20
|
-
"@vuu-ui/vuu-data-editing": "4.0.0-alpha.
|
|
21
|
-
"@vuu-ui/vuu-data-react": "4.0.0-alpha.
|
|
22
|
-
"@vuu-ui/vuu-data-types": "4.0.0-alpha.
|
|
23
|
-
"@vuu-ui/vuu-table-types": "4.0.0-alpha.
|
|
24
|
-
"@vuu-ui/vuu-popups": "4.0.0-alpha.
|
|
25
|
-
"@vuu-ui/vuu-table": "4.0.0-alpha.
|
|
26
|
-
"@vuu-ui/vuu-utils": "4.0.0-alpha.
|
|
27
|
-
"@vuu-ui/vuu-ui-controls": "4.0.0-alpha.
|
|
19
|
+
"@vuu-ui/vuu-codemirror": "4.0.0-alpha.2",
|
|
20
|
+
"@vuu-ui/vuu-data-editing": "4.0.0-alpha.2",
|
|
21
|
+
"@vuu-ui/vuu-data-react": "4.0.0-alpha.2",
|
|
22
|
+
"@vuu-ui/vuu-data-types": "4.0.0-alpha.2",
|
|
23
|
+
"@vuu-ui/vuu-table-types": "4.0.0-alpha.2",
|
|
24
|
+
"@vuu-ui/vuu-popups": "4.0.0-alpha.2",
|
|
25
|
+
"@vuu-ui/vuu-table": "4.0.0-alpha.2",
|
|
26
|
+
"@vuu-ui/vuu-utils": "4.0.0-alpha.2",
|
|
27
|
+
"@vuu-ui/vuu-ui-controls": "4.0.0-alpha.2",
|
|
28
28
|
"@lezer/lr": "1.4.2",
|
|
29
29
|
"@salt-ds/core": "1.67.0",
|
|
30
30
|
"@salt-ds/lab": "1.0.0-alpha.99",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, Dialog, DialogActions, DialogContent, DialogHeader, FileDropZone, FileDropZoneIcon, FileDropZoneTrigger } from "@salt-ds/core";
|
|
2
|
+
import { Button, Dialog, DialogActions, DialogContent, DialogHeader, FileDropZone, FileDropZoneIcon, FileDropZoneTrigger, Text } from "@salt-ds/core";
|
|
3
3
|
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
4
4
|
import { useWindow } from "@salt-ds/window";
|
|
5
5
|
import { useCallback, useState } from "react";
|
|
@@ -18,6 +18,10 @@ const CsvUpload_CsvUpload = (props)=>{
|
|
|
18
18
|
window: targetWindow
|
|
19
19
|
});
|
|
20
20
|
const { canImport, cancelImport, isProcessingFile, isImporting, importData, onDrop, onTriggerChange, schema, validation, error } = useCsvUpload(props);
|
|
21
|
+
const fileErrors = validation?.errors.filter((e)=>e.column in validation.errorMap.fileErrors) ?? [];
|
|
22
|
+
const hasErrors = !!error || validation && validation.errors.length > 0;
|
|
23
|
+
const isUploaded = canImport || isImporting;
|
|
24
|
+
const status = hasErrors ? "error" : isUploaded ? "success" : void 0;
|
|
21
25
|
const handleCancel = useCallback(async ()=>{
|
|
22
26
|
await cancelImport();
|
|
23
27
|
if (!isControlledOpen) setInternalOpen(false);
|
|
@@ -36,38 +40,55 @@ const CsvUpload_CsvUpload = (props)=>{
|
|
|
36
40
|
const content = /*#__PURE__*/ jsxs("div", {
|
|
37
41
|
className: classBase,
|
|
38
42
|
children: [
|
|
39
|
-
/*#__PURE__*/
|
|
43
|
+
/*#__PURE__*/ jsx(FileDropZone, {
|
|
40
44
|
className: `${classBase}-dropZone`,
|
|
41
45
|
disabled: void 0 === schema || isProcessingFile || isImporting,
|
|
42
46
|
onDrop: onDrop,
|
|
43
|
-
status:
|
|
44
|
-
children:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
status: status,
|
|
48
|
+
children: isUploaded ? /*#__PURE__*/ jsxs(Fragment, {
|
|
49
|
+
children: [
|
|
50
|
+
/*#__PURE__*/ jsx(FileDropZoneIcon, {
|
|
51
|
+
status: "success"
|
|
52
|
+
}),
|
|
53
|
+
/*#__PURE__*/ jsx("strong", {
|
|
54
|
+
children: "Upload completed"
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
58
|
+
children: [
|
|
59
|
+
/*#__PURE__*/ jsx(FileDropZoneIcon, {
|
|
60
|
+
status: hasErrors ? "error" : void 0
|
|
61
|
+
}),
|
|
62
|
+
validation && validation.errors.length > 0 ? /*#__PURE__*/ jsxs(Fragment, {
|
|
63
|
+
children: [
|
|
64
|
+
/*#__PURE__*/ jsx("div", {
|
|
65
|
+
children: "Your file contains errors"
|
|
66
|
+
}),
|
|
67
|
+
fileErrors.length > 0 && /*#__PURE__*/ jsx("ul", {
|
|
68
|
+
className: `${classBase}-errorList`,
|
|
69
|
+
children: fileErrors.map((error, i)=>/*#__PURE__*/ jsx("li", {
|
|
70
|
+
className: `${classBase}-errorItem`,
|
|
71
|
+
children: error.message
|
|
72
|
+
}, `${error.column}-${error.message}-${i}`))
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ jsx("div", {
|
|
75
|
+
children: "Please rectify and reupload"
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
}) : /*#__PURE__*/ jsx("div", {
|
|
79
|
+
children: "Drop a file here or"
|
|
80
|
+
}),
|
|
81
|
+
/*#__PURE__*/ jsx(FileDropZoneTrigger, {
|
|
82
|
+
accept: ".csv,text/csv",
|
|
83
|
+
onChange: onTriggerChange,
|
|
84
|
+
children: "BROWSE FILES"
|
|
85
|
+
}),
|
|
86
|
+
/*#__PURE__*/ jsx(Text, {
|
|
87
|
+
children: "Only .csv files"
|
|
88
|
+
}),
|
|
89
|
+
children
|
|
90
|
+
]
|
|
91
|
+
})
|
|
71
92
|
}),
|
|
72
93
|
error && (renderError ? renderError(error) : /*#__PURE__*/ jsxs("div", {
|
|
73
94
|
className: `${classBase}-errors`,
|
|
@@ -81,8 +102,7 @@ const CsvUpload_CsvUpload = (props)=>{
|
|
|
81
102
|
children: error.errors.importError?.message || error.errors.schemaError?.message || error.errors.validationError?.message || "An unexpected error occurred during import."
|
|
82
103
|
})
|
|
83
104
|
]
|
|
84
|
-
}))
|
|
85
|
-
children
|
|
105
|
+
}))
|
|
86
106
|
]
|
|
87
107
|
});
|
|
88
108
|
const actions = /*#__PURE__*/ jsxs(DialogActions, {
|
|
@@ -15,6 +15,7 @@ var csv_errors_CsvValidationErrorEnum = /*#__PURE__*/ function(CsvValidationErro
|
|
|
15
15
|
CsvValidationErrorEnum["MAX_ROWS_EXCEEDED"] = "MAX_ROWS_EXCEEDED";
|
|
16
16
|
CsvValidationErrorEnum["EMPTY_NON_STRING_VALUE"] = "EMPTY_NON_STRING_VALUE";
|
|
17
17
|
CsvValidationErrorEnum["TYPE_MISMATCH"] = "TYPE_MISMATCH";
|
|
18
|
+
CsvValidationErrorEnum["CUSTOM_VALIDATION"] = "CUSTOM_VALIDATION";
|
|
18
19
|
return CsvValidationErrorEnum;
|
|
19
20
|
}({});
|
|
20
21
|
const createCsvErrorState = ()=>({
|
|
@@ -20,6 +20,10 @@ const validateCsvAgainstSchema = (parsed, tableSchema, options)=>{
|
|
|
20
20
|
parsed.rows.forEach((rowValues, rowIndex)=>{
|
|
21
21
|
const rowNum = rowIndex + CSV_FIRST_DATA_ROW_NUMBER;
|
|
22
22
|
const typedRow = {};
|
|
23
|
+
const rawRow = parsed.header.reduce((acc, headerCol, idx)=>{
|
|
24
|
+
acc[headerCol] = rowValues[idx];
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
23
27
|
parsed.header.forEach((columnName, columnIndex)=>{
|
|
24
28
|
const rawValue = rowValues[columnIndex];
|
|
25
29
|
const schemaType = schemaColumns.get(columnName);
|
|
@@ -33,6 +37,11 @@ const validateCsvAgainstSchema = (parsed, tableSchema, options)=>{
|
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
39
|
if (void 0 === value) return void addCsvRowError(errorState, rowNum, columnName, CsvValidationErrorEnum.TYPE_MISMATCH, `Value '${rawValue}' is not a valid ${toType}`, rawValue);
|
|
40
|
+
const customValidator = options?.validators?.[columnName];
|
|
41
|
+
if (customValidator) {
|
|
42
|
+
const validationResult = customValidator(rawValue, columnName, rawRow);
|
|
43
|
+
if (true !== validationResult) return void addCsvRowError(errorState, rowNum, columnName, CsvValidationErrorEnum.CUSTOM_VALIDATION, "string" == typeof validationResult ? validationResult : `Value '${rawValue}' failed custom validation.`, rawValue);
|
|
44
|
+
}
|
|
36
45
|
typedRow[columnName] = value;
|
|
37
46
|
});
|
|
38
47
|
typedRows.push(typedRow);
|
|
@@ -5,7 +5,7 @@ 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", importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults })=>{
|
|
8
|
+
const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, validators })=>{
|
|
9
9
|
const { getServerAPI } = useData();
|
|
10
10
|
const [validation, setValidation] = useState();
|
|
11
11
|
const [sessionTable, setSessionTable] = useState();
|
|
@@ -140,7 +140,7 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
|
|
|
140
140
|
if (rowNum < CSV_FIRST_DATA_ROW_NUMBER) continue;
|
|
141
141
|
const existing = vuuMsgByRow.get(rowNum);
|
|
142
142
|
const columnError = `${column}: ${message}`;
|
|
143
|
-
vuuMsgByRow.set(rowNum, existing ? `${existing}; ${columnError}` : `Row ${rowNum}: ${columnError}`);
|
|
143
|
+
vuuMsgByRow.set(rowNum, existing ? `${existing}; ${columnError}` : `${0 === rowNum ? "Header" : `Row ${rowNum}`}: ${columnError}`);
|
|
144
144
|
}
|
|
145
145
|
const parsedRowCount = mergedValidation.rows.length;
|
|
146
146
|
const unparsedErrorRows = [
|
|
@@ -174,7 +174,7 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
|
|
|
174
174
|
if (isRpcError(result)) throw Error(result.errorMessage);
|
|
175
175
|
if ("string" == typeof result) throw Error(result);
|
|
176
176
|
} catch (error) {
|
|
177
|
-
rpcErrors.push(`Row ${rowNum}: ${toErrorMessage(error)}`);
|
|
177
|
+
rpcErrors.push(`${0 === rowNum ? "Header" : `Row ${rowNum}`}: ${toErrorMessage(error)}`);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
if (rpcErrors.length > 0) throw Error(buildRowErrorMessage("Import failed", rpcErrors));
|
|
@@ -240,7 +240,8 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
|
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
242
|
const schemaValidation = validateCsvAgainstSchema(parsedCsv, schema, {
|
|
243
|
-
maxRows
|
|
243
|
+
maxRows,
|
|
244
|
+
validators
|
|
244
245
|
});
|
|
245
246
|
if (Object.keys(schemaValidation.errorMap.fileErrors).length > 0) {
|
|
246
247
|
setValidation(schemaValidation);
|
|
@@ -288,7 +289,8 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
|
|
|
288
289
|
dataSource.table,
|
|
289
290
|
table,
|
|
290
291
|
endEditSessionAndNotify,
|
|
291
|
-
schema
|
|
292
|
+
schema,
|
|
293
|
+
validators
|
|
292
294
|
]);
|
|
293
295
|
const handleFiles = useCallback(async (files)=>{
|
|
294
296
|
const file = files[0];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { RowDefaultDataItemValues, EditSession } from "@vuu-ui/vuu-data-editing";
|
|
3
3
|
import type { CsvParseError, CsvParseOptions } from "./parse/csv-parse";
|
|
4
|
-
import type { CsvValidationStructuredError } from "./parse/csv-schema-validation";
|
|
4
|
+
import type { CsvValidationStructuredError, CsvColumnValidator } from "./parse/csv-schema-validation";
|
|
5
5
|
import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
|
|
6
6
|
import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
|
|
7
7
|
import type { CsvUploadTableData } from "./parse/csv-upload-utils";
|
|
@@ -60,6 +60,7 @@ export interface CsvUploadProps {
|
|
|
60
60
|
parseOptions?: CsvParseOptions;
|
|
61
61
|
importMode?: "direct" | "preview";
|
|
62
62
|
rowDefaults?: RowDefaultDataItemValues;
|
|
63
|
+
validators?: Record<string, CsvColumnValidator>;
|
|
63
64
|
/**
|
|
64
65
|
* Custom renderer for the error panel.
|
|
65
66
|
*/
|
|
@@ -11,7 +11,7 @@ export declare const useDataUploadPreview: ({ dataSource, editSession, onClose,
|
|
|
11
11
|
canSave: boolean;
|
|
12
12
|
hasSelection: boolean;
|
|
13
13
|
onCancel: () => Promise<void>;
|
|
14
|
-
onDelete: () => Promise<
|
|
14
|
+
onDelete: () => Promise<import("@vuu-ui/vuu-protocol-types").RpcResult>;
|
|
15
15
|
onSave: (force?: boolean) => Promise<void>;
|
|
16
16
|
sessionError: string | undefined;
|
|
17
17
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CsvUpload, type CsvUploadError, type CsvUploadProps, type CsvUploadErrorResult, type CsvUploadErrors, type CsvUploadPhase, type CsvUploadImportedResult, type CsvUploadPreviewResult, type CsvUploadSessionEndReason, type CsvUploadSessionEndResult, type CsvUploadSessionTable, } from "./CsvUpload";
|
|
2
2
|
export { useCsvUpload, type CsvUploadHookProps, type UseCsvUploadReturn, } from "./useCsvUpload";
|
|
3
3
|
export { DataUploadPreview, type DataUploadPreviewProps, } from "./data-upload-preview/DataUploadPreview";
|
|
4
|
-
export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
|
|
4
|
+
export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
|
|
5
5
|
export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./parse/csv-parse";
|
|
6
6
|
export { CsvValidationErrorEnum, CsvParseErrorEnum, type CsvError, type CsvErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, type CsvParseError, type CsvParseErrorMap, } from "./parse/csv-errors";
|
|
7
7
|
export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./parse/csv-constants";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const CSV_HEADER_ROW_NUMBER =
|
|
2
|
-
export declare const CSV_FIRST_DATA_ROW_NUMBER =
|
|
1
|
+
export declare const CSV_HEADER_ROW_NUMBER = 0;
|
|
2
|
+
export declare const CSV_FIRST_DATA_ROW_NUMBER = 1;
|
|
3
3
|
export declare const MAX_ROWS_IN_CSV = 10000;
|
|
@@ -12,7 +12,8 @@ export declare enum CsvValidationErrorEnum {
|
|
|
12
12
|
UNKNOWN_COLUMN = "UNKNOWN_COLUMN",
|
|
13
13
|
MAX_ROWS_EXCEEDED = "MAX_ROWS_EXCEEDED",
|
|
14
14
|
EMPTY_NON_STRING_VALUE = "EMPTY_NON_STRING_VALUE",
|
|
15
|
-
TYPE_MISMATCH = "TYPE_MISMATCH"
|
|
15
|
+
TYPE_MISMATCH = "TYPE_MISMATCH",
|
|
16
|
+
CUSTOM_VALIDATION = "CUSTOM_VALIDATION"
|
|
16
17
|
}
|
|
17
18
|
export type CsvErrorMap<TError extends string> = {
|
|
18
19
|
rowErrors: Record<number, Record<string, TError[]>>;
|
|
@@ -3,6 +3,7 @@ import type { VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
|
|
|
3
3
|
import type { CsvValidationError, CsvValidationErrorMap, CsvParseError } from "./csv-errors";
|
|
4
4
|
import type { CsvParseResult } from "./csv-parse";
|
|
5
5
|
export { CsvValidationErrorEnum, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, } from "./csv-errors";
|
|
6
|
+
export type CsvColumnValidator = (value: string, columnName: string, row: Record<string, string>) => boolean | string;
|
|
6
7
|
export type CsvValidationResult = {
|
|
7
8
|
columns: string[];
|
|
8
9
|
errorMap: CsvValidationErrorMap;
|
|
@@ -12,5 +13,6 @@ export type CsvValidationResult = {
|
|
|
12
13
|
};
|
|
13
14
|
export type CsvValidationOptions = {
|
|
14
15
|
maxRows?: number;
|
|
16
|
+
validators?: Record<string, CsvColumnValidator>;
|
|
15
17
|
};
|
|
16
18
|
export declare const validateCsvAgainstSchema: (parsed: CsvParseResult, tableSchema: TableSchema, options?: CsvValidationOptions) => CsvValidationResult;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./csv-constants";
|
|
2
2
|
export { CsvParseErrorEnum, CsvValidationErrorEnum, type CsvError, type CsvErrorMap, type CsvErrorState, type CsvParseError, type CsvParseErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, addCsvFileError, addCsvRowError, createCsvErrorState, hasCsvErrors, } from "./csv-errors";
|
|
3
3
|
export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./csv-parse";
|
|
4
|
-
export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
|
|
4
|
+
export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
|
|
5
5
|
export { buildRowErrorMessage, executeBatchRpcCalls, hasFileParseErrors, isCsvParseError, mergeValidationWithParseErrors, normalizeTableData, toErrorMessage, toValidationErrorsFromParseRowErrors, type CsvUploadTableData, type RpcBatchResult, } from "./csv-upload-utils";
|
|
@@ -2,7 +2,7 @@ import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
|
|
|
2
2
|
import { type RowDefaultDataItemValues } from "@vuu-ui/vuu-data-editing";
|
|
3
3
|
import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
|
|
4
4
|
import { type CsvParseOptions } from "./parse/csv-parse";
|
|
5
|
-
import { type CsvValidationResult } from "./parse/csv-schema-validation";
|
|
5
|
+
import { type CsvValidationResult, type CsvColumnValidator } from "./parse/csv-schema-validation";
|
|
6
6
|
import type { CsvUploadErrorResult, CsvUploadImportedResult, CsvUploadPreviewResult, CsvUploadSessionEndResult, CsvUploadSessionTable } from "./CsvUpload";
|
|
7
7
|
export interface CsvUploadHookProps {
|
|
8
8
|
dataSource: DataSource;
|
|
@@ -25,6 +25,7 @@ export interface CsvUploadHookProps {
|
|
|
25
25
|
parseOptions?: CsvParseOptions;
|
|
26
26
|
/** Default column values applied to every addRow call. Pass a stable reference — a new object triggers EditSession recreation. */
|
|
27
27
|
rowDefaults?: RowDefaultDataItemValues;
|
|
28
|
+
validators?: Record<string, CsvColumnValidator>;
|
|
28
29
|
}
|
|
29
30
|
export type UseCsvUploadReturn = {
|
|
30
31
|
canImport: boolean;
|
|
@@ -39,4 +40,4 @@ export type UseCsvUploadReturn = {
|
|
|
39
40
|
validation: CsvValidationResult | undefined;
|
|
40
41
|
error: CsvUploadErrorResult | undefined;
|
|
41
42
|
};
|
|
42
|
-
export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, }: CsvUploadHookProps) => UseCsvUploadReturn;
|
|
43
|
+
export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, validators, }: CsvUploadHookProps) => UseCsvUploadReturn;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { RowDefaultDataItemValues, EditSession } from "@vuu-ui/vuu-data-editing";
|
|
3
3
|
import type { CsvParseError, CsvParseOptions } from "./parse/csv-parse";
|
|
4
|
-
import type { CsvValidationStructuredError } from "./parse/csv-schema-validation";
|
|
4
|
+
import type { CsvValidationStructuredError, CsvColumnValidator } from "./parse/csv-schema-validation";
|
|
5
5
|
import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
|
|
6
6
|
import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
|
|
7
7
|
import type { CsvUploadTableData } from "./parse/csv-upload-utils";
|
|
@@ -60,6 +60,7 @@ export interface CsvUploadProps {
|
|
|
60
60
|
parseOptions?: CsvParseOptions;
|
|
61
61
|
importMode?: "direct" | "preview";
|
|
62
62
|
rowDefaults?: RowDefaultDataItemValues;
|
|
63
|
+
validators?: Record<string, CsvColumnValidator>;
|
|
63
64
|
/**
|
|
64
65
|
* Custom renderer for the error panel.
|
|
65
66
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CsvUpload, type CsvUploadError, type CsvUploadProps, type CsvUploadErrorResult, type CsvUploadErrors, type CsvUploadPhase, type CsvUploadImportedResult, type CsvUploadPreviewResult, type CsvUploadSessionEndReason, type CsvUploadSessionEndResult, type CsvUploadSessionTable, } from "./CsvUpload";
|
|
2
2
|
export { useCsvUpload, type CsvUploadHookProps, type UseCsvUploadReturn, } from "./useCsvUpload";
|
|
3
3
|
export { DataUploadPreview, type DataUploadPreviewProps, } from "./data-upload-preview/DataUploadPreview";
|
|
4
|
-
export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
|
|
4
|
+
export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
|
|
5
5
|
export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./parse/csv-parse";
|
|
6
6
|
export { CsvValidationErrorEnum, CsvParseErrorEnum, type CsvError, type CsvErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, type CsvParseError, type CsvParseErrorMap, } from "./parse/csv-errors";
|
|
7
7
|
export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./parse/csv-constants";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const CSV_HEADER_ROW_NUMBER =
|
|
2
|
-
export declare const CSV_FIRST_DATA_ROW_NUMBER =
|
|
1
|
+
export declare const CSV_HEADER_ROW_NUMBER = 0;
|
|
2
|
+
export declare const CSV_FIRST_DATA_ROW_NUMBER = 1;
|
|
3
3
|
export declare const MAX_ROWS_IN_CSV = 10000;
|
|
@@ -12,7 +12,8 @@ export declare enum CsvValidationErrorEnum {
|
|
|
12
12
|
UNKNOWN_COLUMN = "UNKNOWN_COLUMN",
|
|
13
13
|
MAX_ROWS_EXCEEDED = "MAX_ROWS_EXCEEDED",
|
|
14
14
|
EMPTY_NON_STRING_VALUE = "EMPTY_NON_STRING_VALUE",
|
|
15
|
-
TYPE_MISMATCH = "TYPE_MISMATCH"
|
|
15
|
+
TYPE_MISMATCH = "TYPE_MISMATCH",
|
|
16
|
+
CUSTOM_VALIDATION = "CUSTOM_VALIDATION"
|
|
16
17
|
}
|
|
17
18
|
export type CsvErrorMap<TError extends string> = {
|
|
18
19
|
rowErrors: Record<number, Record<string, TError[]>>;
|
|
@@ -3,6 +3,7 @@ import type { VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
|
|
|
3
3
|
import type { CsvValidationError, CsvValidationErrorMap, CsvParseError } from "./csv-errors";
|
|
4
4
|
import type { CsvParseResult } from "./csv-parse";
|
|
5
5
|
export { CsvValidationErrorEnum, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, } from "./csv-errors";
|
|
6
|
+
export type CsvColumnValidator = (value: string, columnName: string, row: Record<string, string>) => boolean | string;
|
|
6
7
|
export type CsvValidationResult = {
|
|
7
8
|
columns: string[];
|
|
8
9
|
errorMap: CsvValidationErrorMap;
|
|
@@ -12,5 +13,6 @@ export type CsvValidationResult = {
|
|
|
12
13
|
};
|
|
13
14
|
export type CsvValidationOptions = {
|
|
14
15
|
maxRows?: number;
|
|
16
|
+
validators?: Record<string, CsvColumnValidator>;
|
|
15
17
|
};
|
|
16
18
|
export declare const validateCsvAgainstSchema: (parsed: CsvParseResult, tableSchema: TableSchema, options?: CsvValidationOptions) => CsvValidationResult;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./csv-constants";
|
|
2
2
|
export { CsvParseErrorEnum, CsvValidationErrorEnum, type CsvError, type CsvErrorMap, type CsvErrorState, type CsvParseError, type CsvParseErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, addCsvFileError, addCsvRowError, createCsvErrorState, hasCsvErrors, } from "./csv-errors";
|
|
3
3
|
export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./csv-parse";
|
|
4
|
-
export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
|
|
4
|
+
export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
|
|
5
5
|
export { buildRowErrorMessage, executeBatchRpcCalls, hasFileParseErrors, isCsvParseError, mergeValidationWithParseErrors, normalizeTableData, toErrorMessage, toValidationErrorsFromParseRowErrors, type CsvUploadTableData, type RpcBatchResult, } from "./csv-upload-utils";
|
|
@@ -2,7 +2,7 @@ import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
|
|
|
2
2
|
import { type RowDefaultDataItemValues } from "@vuu-ui/vuu-data-editing";
|
|
3
3
|
import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
|
|
4
4
|
import { type CsvParseOptions } from "./parse/csv-parse";
|
|
5
|
-
import { type CsvValidationResult } from "./parse/csv-schema-validation";
|
|
5
|
+
import { type CsvValidationResult, type CsvColumnValidator } from "./parse/csv-schema-validation";
|
|
6
6
|
import type { CsvUploadErrorResult, CsvUploadImportedResult, CsvUploadPreviewResult, CsvUploadSessionEndResult, CsvUploadSessionTable } from "./CsvUpload";
|
|
7
7
|
export interface CsvUploadHookProps {
|
|
8
8
|
dataSource: DataSource;
|
|
@@ -25,6 +25,7 @@ export interface CsvUploadHookProps {
|
|
|
25
25
|
parseOptions?: CsvParseOptions;
|
|
26
26
|
/** Default column values applied to every addRow call. Pass a stable reference — a new object triggers EditSession recreation. */
|
|
27
27
|
rowDefaults?: RowDefaultDataItemValues;
|
|
28
|
+
validators?: Record<string, CsvColumnValidator>;
|
|
28
29
|
}
|
|
29
30
|
export type UseCsvUploadReturn = {
|
|
30
31
|
canImport: boolean;
|
|
@@ -39,4 +40,4 @@ export type UseCsvUploadReturn = {
|
|
|
39
40
|
validation: CsvValidationResult | undefined;
|
|
40
41
|
error: CsvUploadErrorResult | undefined;
|
|
41
42
|
};
|
|
42
|
-
export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, }: CsvUploadHookProps) => UseCsvUploadReturn;
|
|
43
|
+
export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, validators, }: CsvUploadHookProps) => UseCsvUploadReturn;
|