@firecms/data_import_export 3.0.0-canary.52 → 3.0.0-canary.54
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/dist/export_import/export.d.ts +12 -1
- package/dist/index.es.js +438 -393
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +16 -16
- package/src/export_import/BasicExportAction.tsx +12 -2
- package/src/export_import/ExportCollectionAction.tsx +32 -3
- package/src/export_import/export.ts +24 -10
package/package.json
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
{
|
2
2
|
"name": "@firecms/data_import_export",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.0.0-canary.
|
4
|
+
"version": "3.0.0-canary.54",
|
5
5
|
"access": "public",
|
6
6
|
"main": "./dist/index.umd.js",
|
7
7
|
"module": "./dist/index.es.js",
|
8
8
|
"types": "./dist/index.d.ts",
|
9
9
|
"source": "src/index.ts",
|
10
10
|
"dependencies": {
|
11
|
-
"@firecms/core": "^3.0.0-canary.
|
12
|
-
"@firecms/formex": "^3.0.0-canary.
|
13
|
-
"@firecms/schema_inference": "^3.0.0-canary.
|
14
|
-
"@firecms/ui": "^3.0.0-canary.
|
11
|
+
"@firecms/core": "^3.0.0-canary.54",
|
12
|
+
"@firecms/formex": "^3.0.0-canary.54",
|
13
|
+
"@firecms/schema_inference": "^3.0.0-canary.54",
|
14
|
+
"@firecms/ui": "^3.0.0-canary.54",
|
15
15
|
"xlsx": "^0.18.5"
|
16
16
|
},
|
17
17
|
"peerDependencies": {
|
18
18
|
"firebase": "^10.7.1",
|
19
|
-
"react": "^18.
|
20
|
-
"react-dom": "^18.
|
19
|
+
"react": "^18.3.1",
|
20
|
+
"react-dom": "^18.3.1",
|
21
21
|
"react-router": "^6.22.0",
|
22
22
|
"react-router-dom": "^6.22.0"
|
23
23
|
},
|
@@ -58,23 +58,23 @@
|
|
58
58
|
"@jest/globals": "^29.7.0",
|
59
59
|
"@testing-library/jest-dom": "^6.4.5",
|
60
60
|
"@types/jest": "^29.5.12",
|
61
|
-
"@types/react": "^18.3.
|
61
|
+
"@types/react": "^18.3.3",
|
62
62
|
"@types/react-dom": "^18.3.0",
|
63
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
64
|
-
"@typescript-eslint/parser": "^7.
|
65
|
-
"@vitejs/plugin-react": "^4.
|
63
|
+
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
64
|
+
"@typescript-eslint/parser": "^7.11.0",
|
65
|
+
"@vitejs/plugin-react": "^4.3.0",
|
66
66
|
"babel-jest": "^29.7.0",
|
67
67
|
"eslint": "^8.57.0",
|
68
68
|
"eslint-config-standard": "^17.1.0",
|
69
69
|
"eslint-plugin-import": "^2.29.1",
|
70
70
|
"eslint-plugin-n": "^16.6.2",
|
71
|
-
"eslint-plugin-promise": "^6.
|
72
|
-
"eslint-plugin-react": "^7.34.
|
71
|
+
"eslint-plugin-promise": "^6.2.0",
|
72
|
+
"eslint-plugin-react": "^7.34.2",
|
73
73
|
"eslint-plugin-react-hooks": "^4.6.2",
|
74
74
|
"jest": "^29.7.0",
|
75
|
-
"ts-jest": "^29.1.
|
75
|
+
"ts-jest": "^29.1.4",
|
76
76
|
"typescript": "^5.4.5",
|
77
|
-
"vite": "^5.2.
|
77
|
+
"vite": "^5.2.12",
|
78
78
|
"vite-plugin-fonts": "^0.7.0"
|
79
79
|
},
|
80
80
|
"jest": {
|
@@ -101,5 +101,5 @@
|
|
101
101
|
"publishConfig": {
|
102
102
|
"access": "public"
|
103
103
|
},
|
104
|
-
"gitHead": "
|
104
|
+
"gitHead": "cee5d67f4df03de284b903f636bdaf9b07e8f891"
|
105
105
|
}
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
GetAppIcon,
|
13
13
|
IconButton,
|
14
14
|
Tooltip,
|
15
|
-
Typography
|
15
|
+
Typography
|
16
16
|
} from "@firecms/ui";
|
17
17
|
import { downloadEntitiesExport } from "./export";
|
18
18
|
|
@@ -44,7 +44,17 @@ export function BasicExportAction({
|
|
44
44
|
}, [setOpen]);
|
45
45
|
|
46
46
|
const onOkClicked = useCallback(() => {
|
47
|
-
downloadEntitiesExport(
|
47
|
+
downloadEntitiesExport({
|
48
|
+
data,
|
49
|
+
additionalData: [],
|
50
|
+
properties,
|
51
|
+
propertiesOrder,
|
52
|
+
name: "export.csv",
|
53
|
+
flattenArrays,
|
54
|
+
additionalHeaders: [],
|
55
|
+
exportType,
|
56
|
+
dateExportType
|
57
|
+
});
|
48
58
|
handleClose();
|
49
59
|
}, []);
|
50
60
|
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
Entity,
|
6
6
|
EntityCollection,
|
7
7
|
ExportConfig,
|
8
|
+
getDefaultValuesFor,
|
8
9
|
resolveCollection,
|
9
10
|
ResolvedEntityCollection,
|
10
11
|
useCustomizationController,
|
@@ -26,7 +27,7 @@ import {
|
|
26
27
|
GetAppIcon,
|
27
28
|
IconButton,
|
28
29
|
Tooltip,
|
29
|
-
Typography
|
30
|
+
Typography
|
30
31
|
} from "@firecms/ui";
|
31
32
|
import { downloadEntitiesExport } from "./export";
|
32
33
|
|
@@ -50,6 +51,8 @@ export function ExportCollectionAction<M extends Record<string, any>, UserType e
|
|
50
51
|
const exportConfig = typeof inputCollection.exportable === "object" ? inputCollection.exportable : undefined;
|
51
52
|
|
52
53
|
const dateRef = React.useRef<Date>(new Date());
|
54
|
+
|
55
|
+
const [includeUndefinedValues, setIncludeUndefinedValues] = React.useState<boolean>(false);
|
53
56
|
const [flattenArrays, setFlattenArrays] = React.useState<boolean>(true);
|
54
57
|
const [exportType, setExportType] = React.useState<"csv" | "json">("csv");
|
55
58
|
const [dateExportType, setDateExportType] = React.useState<"timestamp" | "string">("string");
|
@@ -139,7 +142,27 @@ export function ExportCollectionAction<M extends Record<string, any>, UserType e
|
|
139
142
|
...exportConfig?.additionalFields?.map(column => column.key) ?? [],
|
140
143
|
...collection.additionalFields?.map(field => field.key) ?? []
|
141
144
|
];
|
142
|
-
|
145
|
+
|
146
|
+
const dataWithDefaults = includeUndefinedValues
|
147
|
+
? data.map(entity => {
|
148
|
+
const defaultValues = getDefaultValuesFor(collection.properties);
|
149
|
+
return {
|
150
|
+
...entity,
|
151
|
+
values: { ...defaultValues, ...entity.values }
|
152
|
+
};
|
153
|
+
})
|
154
|
+
: data;
|
155
|
+
downloadEntitiesExport({
|
156
|
+
data: dataWithDefaults,
|
157
|
+
additionalData,
|
158
|
+
properties: collection.properties,
|
159
|
+
propertiesOrder: collection.propertiesOrder,
|
160
|
+
name: collection.name,
|
161
|
+
flattenArrays,
|
162
|
+
additionalHeaders,
|
163
|
+
exportType,
|
164
|
+
dateExportType
|
165
|
+
});
|
143
166
|
onAnalyticsEvent?.("export_collection_success", {
|
144
167
|
collection: collection.path
|
145
168
|
});
|
@@ -150,7 +173,7 @@ export function ExportCollectionAction<M extends Record<string, any>, UserType e
|
|
150
173
|
})
|
151
174
|
.finally(() => setDataLoading(false));
|
152
175
|
|
153
|
-
}, [onAnalyticsEvent, dataSource, path, fetchAdditionalFields, flattenArrays, exportType, dateExportType]);
|
176
|
+
}, [onAnalyticsEvent, dataSource, path, fetchAdditionalFields, includeUndefinedValues, flattenArrays, exportType, dateExportType]);
|
154
177
|
|
155
178
|
const onOkClicked = useCallback(() => {
|
156
179
|
doDownload(collection, exportConfig);
|
@@ -232,6 +255,12 @@ export function ExportCollectionAction<M extends Record<string, any>, UserType e
|
|
232
255
|
onValueChange={setFlattenArrays}
|
233
256
|
label={"Flatten arrays"}/>
|
234
257
|
|
258
|
+
<BooleanSwitchWithLabel
|
259
|
+
size={"small"}
|
260
|
+
value={includeUndefinedValues}
|
261
|
+
onValueChange={setIncludeUndefinedValues}
|
262
|
+
label={"Include undefined values"}/>
|
263
|
+
|
235
264
|
{!canExport && notAllowedView}
|
236
265
|
|
237
266
|
</DialogContent>
|
@@ -13,15 +13,29 @@ interface Header {
|
|
13
13
|
label: string;
|
14
14
|
}
|
15
15
|
|
16
|
-
export
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
export interface DownloadEntitiesExportParams<M extends Record<string, any>> {
|
17
|
+
data: Entity<M>[];
|
18
|
+
additionalData: Record<string, any>[] | undefined;
|
19
|
+
properties: ResolvedProperties<M>;
|
20
|
+
propertiesOrder: string[] | undefined;
|
21
|
+
name: string;
|
22
|
+
flattenArrays: boolean;
|
23
|
+
additionalHeaders: string[] | undefined;
|
24
|
+
exportType: "csv" | "json";
|
25
|
+
dateExportType: "timestamp" | "string";
|
26
|
+
}
|
27
|
+
|
28
|
+
export function downloadEntitiesExport<M extends Record<string, any>>({
|
29
|
+
data,
|
30
|
+
additionalData,
|
31
|
+
properties,
|
32
|
+
propertiesOrder,
|
33
|
+
name,
|
34
|
+
flattenArrays,
|
35
|
+
additionalHeaders,
|
36
|
+
exportType,
|
37
|
+
dateExportType
|
38
|
+
}: DownloadEntitiesExportParams<M>
|
25
39
|
) {
|
26
40
|
|
27
41
|
console.debug("Downloading export", {
|
@@ -101,7 +115,7 @@ function getExportHeaders<M extends Record<string, any>>(properties: ResolvedPro
|
|
101
115
|
...(propertiesOrder ?? Object.keys(properties))
|
102
116
|
.flatMap((childKey) => {
|
103
117
|
const property = properties[childKey];
|
104
|
-
if(!property) {
|
118
|
+
if (!property) {
|
105
119
|
console.warn("Property not found", childKey, properties);
|
106
120
|
return [];
|
107
121
|
}
|