@payloadcms/plugin-import-export 4.0.0-internal.435b2d6 → 4.0.0-internal.442e8b6
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/components/CollectionField/index.d.ts +3 -2
- package/dist/components/CollectionField/index.d.ts.map +1 -1
- package/dist/components/CollectionField/index.js.map +1 -1
- package/dist/components/ExportListMenuItem/index.d.ts.map +1 -1
- package/dist/components/ExportListMenuItem/index.js +14 -12
- package/dist/components/ExportListMenuItem/index.js.map +1 -1
- package/dist/components/ExportPreview/index.css +0 -3
- package/dist/components/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js +11 -1
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/FieldsToExport/index.d.ts +3 -2
- package/dist/components/FieldsToExport/index.d.ts.map +1 -1
- package/dist/components/FieldsToExport/index.js.map +1 -1
- package/dist/components/FormatField/index.d.ts +3 -2
- package/dist/components/FormatField/index.d.ts.map +1 -1
- package/dist/components/FormatField/index.js.map +1 -1
- package/dist/components/ImportListMenuItem/index.d.ts.map +1 -1
- package/dist/components/ImportListMenuItem/index.js +14 -12
- package/dist/components/ImportListMenuItem/index.js.map +1 -1
- package/dist/components/ImportPreview/index.css +0 -3
- package/dist/components/ImportPreview/index.d.ts.map +1 -1
- package/dist/components/ImportPreview/index.js +27 -8
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/components/LimitField/index.d.ts +3 -2
- package/dist/components/LimitField/index.d.ts.map +1 -1
- package/dist/components/LimitField/index.js.map +1 -1
- package/dist/components/LocaleField/index.d.ts +3 -2
- package/dist/components/LocaleField/index.d.ts.map +1 -1
- package/dist/components/LocaleField/index.js.map +1 -1
- package/dist/components/Page/index.d.ts +3 -2
- package/dist/components/Page/index.d.ts.map +1 -1
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts +7 -0
- package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts.map +1 -0
- package/dist/components/RelationshipCell/getRelationshipGroupKey.js +3 -0
- package/dist/components/RelationshipCell/getRelationshipGroupKey.js.map +1 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.d.ts +43 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.d.ts.map +1 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.js +109 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.js.map +1 -0
- package/dist/components/RelationshipCell/index.css +30 -0
- package/dist/components/RelationshipCell/index.d.ts +15 -0
- package/dist/components/RelationshipCell/index.d.ts.map +1 -0
- package/dist/components/RelationshipCell/index.js +57 -0
- package/dist/components/RelationshipCell/index.js.map +1 -0
- package/dist/components/SortBy/index.d.ts +3 -2
- package/dist/components/SortBy/index.d.ts.map +1 -1
- package/dist/components/SortBy/index.js.map +1 -1
- package/dist/components/SortOrder/index.d.ts +3 -2
- package/dist/components/SortOrder/index.d.ts.map +1 -1
- package/dist/components/SortOrder/index.js.map +1 -1
- package/dist/export/batchProcessor.d.ts +2 -1
- package/dist/export/batchProcessor.d.ts.map +1 -1
- package/dist/export/batchProcessor.js +6 -2
- package/dist/export/batchProcessor.js.map +1 -1
- package/dist/export/createExport.d.ts +2 -0
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +6 -1
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +11 -0
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getExportCollection.js +5 -0
- package/dist/export/getExportCollection.js.map +1 -1
- package/dist/export/handleDownload.d.ts.map +1 -1
- package/dist/export/handleDownload.js +7 -3
- package/dist/export/handleDownload.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +24 -5
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/batchProcessor.d.ts +2 -1
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js +15 -8
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts +3 -2
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +8 -1
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
- package/dist/import/getCreateImportCollectionTask.js +5 -2
- package/dist/import/getCreateImportCollectionTask.js.map +1 -1
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/getImportCollection.js +2 -0
- package/dist/import/getImportCollection.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/import/handlePreview.js +5 -1
- package/dist/import/handlePreview.js.map +1 -1
- package/dist/types.d.ts +17 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +64 -27
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getFileFromDoc.js +3 -3
- package/dist/utilities/getFileFromDoc.js.map +1 -1
- package/dist/utilities/getSelect.d.ts.map +1 -1
- package/dist/utilities/getSelect.js +11 -3
- package/dist/utilities/getSelect.js.map +1 -1
- package/dist/utilities/getSubmittedFormValues.d.ts +12 -0
- package/dist/utilities/getSubmittedFormValues.d.ts.map +1 -0
- package/dist/utilities/getSubmittedFormValues.js +24 -0
- package/dist/utilities/getSubmittedFormValues.js.map +1 -0
- package/dist/utilities/setNestedValue.d.ts +2 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.js +65 -34
- package/dist/utilities/setNestedValue.js.map +1 -1
- package/package.json +9 -9
- package/dist/components/FieldsToExport/reduceFields.spec.js +0 -239
- package/dist/components/FieldsToExport/reduceFields.spec.js.map +0 -1
- package/dist/utilities/applyFieldHooks.spec.js +0 -205
- package/dist/utilities/applyFieldHooks.spec.js.map +0 -1
- package/dist/utilities/buildDisabledFieldRegex.spec.js +0 -64
- package/dist/utilities/buildDisabledFieldRegex.spec.js.map +0 -1
- package/dist/utilities/fieldToRegex.spec.js +0 -151
- package/dist/utilities/fieldToRegex.spec.js.map +0 -1
- package/dist/utilities/filterToSelectedFields.spec.js +0 -204
- package/dist/utilities/filterToSelectedFields.spec.js.map +0 -1
- package/dist/utilities/flattenObject.spec.js +0 -158
- package/dist/utilities/flattenObject.spec.js.map +0 -1
- package/dist/utilities/getExportFieldFunctions.spec.js +0 -50
- package/dist/utilities/getExportFieldFunctions.spec.js.map +0 -1
- package/dist/utilities/getImportFieldFunctions.spec.js +0 -167
- package/dist/utilities/getImportFieldFunctions.spec.js.map +0 -1
- package/dist/utilities/getSchemaColumns.spec.js +0 -157
- package/dist/utilities/getSchemaColumns.spec.js.map +0 -1
- package/dist/utilities/parseCSV.spec.js +0 -195
- package/dist/utilities/parseCSV.spec.js.map +0 -1
- package/dist/utilities/processRichTextField.spec.js +0 -308
- package/dist/utilities/processRichTextField.spec.js.map +0 -1
- package/dist/utilities/siblingDoc.spec.js +0 -278
- package/dist/utilities/siblingDoc.spec.js.map +0 -1
- package/dist/utilities/unflattenObject.spec.js +0 -819
- package/dist/utilities/unflattenObject.spec.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { TextFieldClientProps } from 'payload';
|
|
2
|
+
import type React from 'react';
|
|
3
|
+
export declare const CollectionField: React.FC<TextFieldClientProps>;
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CollectionField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CollectionField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AACnD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAE1D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/CollectionField/index.tsx"],"sourcesContent":["'use client'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/CollectionField/index.tsx"],"sourcesContent":["'use client'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\n\nimport { CollectionSelectField } from '../CollectionSelectField/index.js'\n\nexport const CollectionField: React.FC<TextFieldClientProps> = (props) => {\n return <CollectionSelectField textFieldProps={props} />\n}\n"],"names":["CollectionSelectField","CollectionField","props","textFieldProps"],"mappings":"AAAA;;AAIA,SAASA,qBAAqB,QAAQ,oCAAmC;AAEzE,OAAO,MAAMC,kBAAkD,CAACC;IAC9D,qBAAO,KAACF;QAAsBG,gBAAgBD;;AAChD,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportListMenuItem/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportListMenuItem/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoB,MAAM,OAAO,CAAA;AAWxC,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;IACxC,cAAc,EAAE,MAAM,CAAA;IACtB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAqCA,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
-
import {
|
|
4
|
+
import { useConfig, useDocumentDrawer, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import React, { useEffect } from 'react';
|
|
6
6
|
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
7
7
|
const baseClass = 'export-list-menu-item';
|
|
@@ -11,6 +11,10 @@ export const ExportListMenuItem = ({ collectionSlug, exportCollectionSlug })=>{
|
|
|
11
11
|
const currentCollectionConfig = getEntityConfig({
|
|
12
12
|
collectionSlug
|
|
13
13
|
});
|
|
14
|
+
const collectionLabel = getTranslation(currentCollectionConfig.labels.plural, i18n);
|
|
15
|
+
const actionLabel = t('plugin-import-export:exportDocumentLabel', {
|
|
16
|
+
label: collectionLabel
|
|
17
|
+
});
|
|
14
18
|
const [DocumentDrawer, DocumentDrawerToggler] = useDocumentDrawer({
|
|
15
19
|
collectionSlug: exportCollectionSlug
|
|
16
20
|
});
|
|
@@ -22,18 +26,16 @@ export const ExportListMenuItem = ({ collectionSlug, exportCollectionSlug })=>{
|
|
|
22
26
|
currentCollectionConfig,
|
|
23
27
|
setCollection
|
|
24
28
|
]);
|
|
25
|
-
return /*#__PURE__*/ _jsxs(
|
|
26
|
-
className: baseClass,
|
|
29
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
27
30
|
children: [
|
|
28
31
|
/*#__PURE__*/ _jsx(DocumentDrawerToggler, {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
32
|
+
"aria-label": actionLabel,
|
|
33
|
+
className: `popup-button-list__button ${baseClass}`,
|
|
34
|
+
role: "menuitem",
|
|
35
|
+
tabIndex: -1,
|
|
36
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
37
|
+
className: "popup-button-list__label",
|
|
38
|
+
children: actionLabel
|
|
37
39
|
})
|
|
38
40
|
}),
|
|
39
41
|
/*#__PURE__*/ _jsx(DocumentDrawer, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/ExportListMenuItem/index.tsx"],"sourcesContent":["'use client'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/ExportListMenuItem/index.tsx"],"sourcesContent":["'use client'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { useConfig, useDocumentDrawer, useTranslation } from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\n\nconst baseClass = 'export-list-menu-item'\n\nexport const ExportListMenuItem: React.FC<{\n collectionSlug: string\n exportCollectionSlug: string\n}> = ({ collectionSlug, exportCollectionSlug }) => {\n const { getEntityConfig } = useConfig()\n\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const currentCollectionConfig = getEntityConfig({ collectionSlug })\n const collectionLabel = getTranslation(currentCollectionConfig.labels.plural, i18n)\n const actionLabel = t('plugin-import-export:exportDocumentLabel', {\n label: collectionLabel,\n })\n\n const [DocumentDrawer, DocumentDrawerToggler] = useDocumentDrawer({\n collectionSlug: exportCollectionSlug,\n })\n const { setCollection } = useImportExport()\n\n // Set collection and selected items on mount or when selection changes\n useEffect(() => {\n setCollection(currentCollectionConfig.slug ?? '')\n }, [currentCollectionConfig, setCollection])\n\n return (\n <>\n <DocumentDrawerToggler\n aria-label={actionLabel}\n className={`popup-button-list__button ${baseClass}`}\n role=\"menuitem\"\n tabIndex={-1}\n >\n <span className=\"popup-button-list__label\">{actionLabel}</span>\n </DocumentDrawerToggler>\n <DocumentDrawer initialData={{ collectionSlug }} />\n </>\n )\n}\n"],"names":["getTranslation","useConfig","useDocumentDrawer","useTranslation","React","useEffect","useImportExport","baseClass","ExportListMenuItem","collectionSlug","exportCollectionSlug","getEntityConfig","i18n","t","currentCollectionConfig","collectionLabel","labels","plural","actionLabel","label","DocumentDrawer","DocumentDrawerToggler","setCollection","slug","aria-label","className","role","tabIndex","span","initialData"],"mappings":"AAAA;;AAEA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,iBAAgB;AAC7E,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAOxC,SAASC,eAAe,QAAQ,mCAAkC;AAElE,MAAMC,YAAY;AAElB,OAAO,MAAMC,qBAGR,CAAC,EAAEC,cAAc,EAAEC,oBAAoB,EAAE;IAC5C,MAAM,EAAEC,eAAe,EAAE,GAAGV;IAE5B,MAAM,EAAEW,IAAI,EAAEC,CAAC,EAAE,GAAGV;IAKpB,MAAMW,0BAA0BH,gBAAgB;QAAEF;IAAe;IACjE,MAAMM,kBAAkBf,eAAec,wBAAwBE,MAAM,CAACC,MAAM,EAAEL;IAC9E,MAAMM,cAAcL,EAAE,4CAA4C;QAChEM,OAAOJ;IACT;IAEA,MAAM,CAACK,gBAAgBC,sBAAsB,GAAGnB,kBAAkB;QAChEO,gBAAgBC;IAClB;IACA,MAAM,EAAEY,aAAa,EAAE,GAAGhB;IAE1B,uEAAuE;IACvED,UAAU;QACRiB,cAAcR,wBAAwBS,IAAI,IAAI;IAChD,GAAG;QAACT;QAAyBQ;KAAc;IAE3C,qBACE;;0BACE,KAACD;gBACCG,cAAYN;gBACZO,WAAW,CAAC,0BAA0B,EAAElB,WAAW;gBACnDmB,MAAK;gBACLC,UAAU,CAAC;0BAEX,cAAA,KAACC;oBAAKH,WAAU;8BAA4BP;;;0BAE9C,KAACE;gBAAeS,aAAa;oBAAEpB;gBAAe;;;;AAGpD,EAAC"}
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
|
|
16
16
|
.export-preview__export-count {
|
|
17
17
|
color: var(--color-text-secondary);
|
|
18
|
-
font-family: var(--text-body-medium-font-family);
|
|
19
18
|
font-size: var(--text-body-medium-font-size);
|
|
20
19
|
font-weight: var(--text-body-medium-font-weight);
|
|
21
20
|
line-height: var(--text-body-medium-line-height);
|
|
@@ -23,7 +22,6 @@
|
|
|
23
22
|
|
|
24
23
|
.export-preview__limit-capped {
|
|
25
24
|
color: var(--color-text-warning);
|
|
26
|
-
font-family: var(--text-body-medium-font-family);
|
|
27
25
|
font-size: var(--text-body-medium-font-size);
|
|
28
26
|
font-weight: var(--text-body-medium-font-weight);
|
|
29
27
|
line-height: var(--text-body-medium-line-height);
|
|
@@ -46,7 +44,6 @@
|
|
|
46
44
|
|
|
47
45
|
.export-preview__page-info {
|
|
48
46
|
color: var(--color-text-secondary);
|
|
49
|
-
font-family: var(--text-body-medium-font-family);
|
|
50
47
|
font-size: var(--text-body-medium-font-size);
|
|
51
48
|
font-weight: var(--text-body-medium-font-weight);
|
|
52
49
|
line-height: var(--text-body-medium-line-height);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportPreview/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportPreview/index.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAqD,MAAM,OAAO,CAAA;AAczE,OAAO,aAAa,CAAA;AAIpB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAuRjC,CAAA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
-
import { CodeEditorLazy, Pagination, PerPage, Table, Translation, useConfig, useDebouncedEffect, useDocumentInfo, useFormFields, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import { CodeEditorLazy, Pagination, PerPage, Table, Translation, useConfig, useDebouncedEffect, useDocumentInfo, useForm, useFormFields, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import React, { useEffect, useRef, useState, useTransition } from 'react';
|
|
6
6
|
import { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js';
|
|
7
|
+
import { getFormStateSignature, getSubmittedFormValues } from '../../utilities/getSubmittedFormValues.js';
|
|
7
8
|
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
8
9
|
import './index.css';
|
|
9
10
|
const baseClass = 'export-preview';
|
|
@@ -23,6 +24,10 @@ export const ExportPreview = ()=>{
|
|
|
23
24
|
where: fields['where']?.value
|
|
24
25
|
};
|
|
25
26
|
});
|
|
27
|
+
const { getData } = useForm();
|
|
28
|
+
const formStateSignature = useFormFields(([fields])=>getFormStateSignature({
|
|
29
|
+
fields
|
|
30
|
+
}));
|
|
26
31
|
const [dataToRender, setDataToRender] = useState([]);
|
|
27
32
|
const [exportTotalDocs, setExportTotalDocs] = useState(0);
|
|
28
33
|
const [maxLimit, setMaxLimit] = useState(undefined);
|
|
@@ -82,6 +87,9 @@ export const ExportPreview = ()=>{
|
|
|
82
87
|
draft,
|
|
83
88
|
fields,
|
|
84
89
|
format,
|
|
90
|
+
formData: getSubmittedFormValues({
|
|
91
|
+
formData: getData()
|
|
92
|
+
}),
|
|
85
93
|
limit,
|
|
86
94
|
locale,
|
|
87
95
|
previewLimit,
|
|
@@ -156,6 +164,8 @@ export const ExportPreview = ()=>{
|
|
|
156
164
|
draft,
|
|
157
165
|
fields,
|
|
158
166
|
format,
|
|
167
|
+
formStateSignature,
|
|
168
|
+
getData,
|
|
159
169
|
i18n,
|
|
160
170
|
limit,
|
|
161
171
|
locale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/ExportPreview/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Column, PaginatedDocs, Where } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n CodeEditorLazy,\n Pagination,\n PerPage,\n Table,\n Translation,\n useConfig,\n useDebouncedEffect,\n useDocumentInfo,\n useFormFields,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useEffect, useRef, useState, useTransition } from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\nimport type { ExportPreviewResponse } from '../../types.js'\n\nimport { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js'\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.css'\n\nconst baseClass = 'export-preview'\n\nexport const ExportPreview: React.FC = () => {\n const [isPending, startTransition] = useTransition()\n const { collection } = useImportExport()\n const {\n config,\n config: { routes },\n } = useConfig()\n const { collectionSlug } = useDocumentInfo()\n const { draft, fields, format, limit, locale, sort, where } = useFormFields(([fields]) => {\n return {\n draft: fields['drafts']?.value,\n fields: fields['fields']?.value,\n format: fields['format']?.value,\n limit: fields['limit']?.value as number,\n locale: fields['locale']?.value as string,\n sort: fields['sort']?.value as string,\n where: fields['where']?.value as Where,\n }\n })\n const [dataToRender, setDataToRender] = useState<any[]>([])\n const [exportTotalDocs, setExportTotalDocs] = useState<number>(0)\n const [maxLimit, setMaxLimit] = useState<number | undefined>(undefined)\n const [columns, setColumns] = useState<Column[]>([])\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n // Preview pagination state (separate from export config)\n const [previewPage, setPreviewPage] = useState(1)\n const [previewLimit, setPreviewLimit] = useState(DEFAULT_PREVIEW_LIMIT)\n const [paginationData, setPaginationData] = useState<null | Pick<\n PaginatedDocs,\n 'hasNextPage' | 'hasPrevPage' | 'limit' | 'nextPage' | 'page' | 'prevPage' | 'totalPages'\n >>(null)\n\n // Track previous export config to reset preview page when it changes\n const prevExportConfigRef = useRef({ draft, fields, format, limit, locale, sort, where })\n\n // Reset preview page when export config changes\n useEffect(() => {\n const prevConfig = prevExportConfigRef.current\n const configChanged =\n prevConfig.draft !== draft ||\n prevConfig.limit !== limit ||\n prevConfig.locale !== locale ||\n prevConfig.sort !== sort ||\n JSON.stringify(prevConfig.fields) !== JSON.stringify(fields) ||\n JSON.stringify(prevConfig.where) !== JSON.stringify(where)\n\n if (configChanged) {\n setPreviewPage(1)\n prevExportConfigRef.current = { draft, fields, format, limit, locale, sort, where }\n }\n }, [draft, fields, format, limit, locale, sort, where])\n\n const targetCollectionSlug = typeof collection === 'string' && collection\n\n const isCSV = format === 'csv'\n\n useDebouncedEffect(\n () => {\n if (!collectionSlug || !targetCollectionSlug) {\n return\n }\n\n const abortController = new AbortController()\n\n const fetchData = async () => {\n try {\n const res = await fetch(`${routes.api}/${collectionSlug}/export-preview`, {\n body: JSON.stringify({\n collectionSlug: targetCollectionSlug,\n draft,\n fields,\n format,\n limit,\n locale,\n previewLimit,\n previewPage,\n sort,\n where,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n signal: abortController.signal,\n })\n\n if (!res.ok) {\n return\n }\n\n const {\n columns: serverColumns,\n docs,\n exportTotalDocs: serverExportTotalDocs,\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n maxLimit: serverMaxLimit,\n page: responsePage,\n totalPages,\n }: ExportPreviewResponse = await res.json()\n\n // For CSV: use server-provided columns (from getSchemaColumns) for consistent ordering\n // For JSON: derive keys from docs\n const allKeys = Array.from(new Set(docs.flatMap((doc) => Object.keys(doc))))\n\n // Use server columns if available (CSV format), otherwise fall back to data-derived keys\n const fieldKeys = serverColumns && serverColumns.length > 0 ? serverColumns : allKeys\n\n // Build columns based on field keys\n const newColumns: Column[] = fieldKeys.map((key) => ({\n accessor: key,\n active: true,\n field: { name: key } as ClientField,\n Heading: getTranslation(key, i18n),\n renderedCells: docs.map((doc: Record<string, unknown>) => {\n const val = doc[key]\n\n if (val === undefined || val === null) {\n return null\n }\n\n // Avoid ESLint warning by type-checking before calling String()\n if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {\n return String(val)\n }\n\n if (Array.isArray(val)) {\n return val.map(String).join(', ')\n }\n\n return JSON.stringify(val)\n }),\n }))\n\n setExportTotalDocs(serverExportTotalDocs)\n setMaxLimit(serverMaxLimit)\n setPaginationData({\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n nextPage: responsePage + 1,\n page: responsePage,\n prevPage: responsePage - 1,\n totalPages,\n })\n setColumns(newColumns)\n setDataToRender(docs)\n } catch (error) {\n console.error('Error fetching preview data:', error)\n }\n }\n\n startTransition(async () => await fetchData())\n\n return () => {\n if (!abortController.signal.aborted) {\n abortController.abort('Component unmounted')\n }\n }\n },\n [\n collectionSlug,\n draft,\n fields,\n format,\n i18n,\n limit,\n locale,\n previewLimit,\n previewPage,\n sort,\n where,\n routes.api,\n targetCollectionSlug,\n ],\n 500,\n )\n\n const handlePageChange = (page: number) => {\n setPreviewPage(page)\n }\n\n const handlePerPageChange = (newLimit: number) => {\n setPreviewLimit(newLimit)\n setPreviewPage(1)\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {exportTotalDocs > 0 && !isPending && (\n <div className={`${baseClass}__export-info`}>\n <span className={`${baseClass}__export-count`}>\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:documentsToExport\"\n t={t}\n variables={{\n count: exportTotalDocs,\n }}\n />\n </span>\n {typeof maxLimit === 'number' &&\n maxLimit > 0 &&\n typeof limit === 'number' &&\n limit > maxLimit && (\n <span className={`${baseClass}__limit-capped`}>\n <Translation\n // @ts-expect-error - plugin translations not typed\n i18nKey=\"plugin-import-export:limitCapped\"\n t={t}\n variables={{\n limit: maxLimit,\n }}\n />\n </span>\n )}\n </div>\n )}\n </div>\n {isPending && !dataToRender && (\n <div className={`${baseClass}__loading`}>\n <Translation i18nKey=\"general:loading\" t={t} />\n </div>\n )}\n {dataToRender &&\n (isCSV ? (\n <Table columns={columns} data={dataToRender} />\n ) : (\n <CodeEditorLazy language=\"json\" readOnly value={JSON.stringify(dataToRender, null, 2)} />\n ))}\n {paginationData && exportTotalDocs > 0 && (\n <div className={`${baseClass}__pagination`}>\n {paginationData.totalPages > 1 && (\n <Pagination\n hasNextPage={paginationData.hasNextPage}\n hasPrevPage={paginationData.hasPrevPage}\n nextPage={paginationData.nextPage ?? undefined}\n numberOfNeighbors={1}\n onChange={handlePageChange}\n page={paginationData.page}\n prevPage={paginationData.prevPage ?? undefined}\n totalPages={paginationData.totalPages}\n />\n )}\n <span className={`${baseClass}__page-info`}>\n <Translation\n // @ts-expect-error - plugin translations not typed\n i18nKey=\"plugin-import-export:previewPageInfo\"\n t={t}\n variables={{\n end: Math.min((paginationData.page ?? 1) * previewLimit, exportTotalDocs),\n start: ((paginationData.page ?? 1) - 1) * previewLimit + 1,\n total: exportTotalDocs,\n }}\n />\n </span>\n <PerPage\n handleChange={handlePerPageChange}\n limit={previewLimit}\n limits={PREVIEW_LIMIT_OPTIONS}\n />\n </div>\n )}\n </div>\n )\n}\n"],"names":["getTranslation","CodeEditorLazy","Pagination","PerPage","Table","Translation","useConfig","useDebouncedEffect","useDocumentInfo","useFormFields","useTranslation","React","useEffect","useRef","useState","useTransition","DEFAULT_PREVIEW_LIMIT","PREVIEW_LIMIT_OPTIONS","useImportExport","baseClass","ExportPreview","isPending","startTransition","collection","config","routes","collectionSlug","draft","fields","format","limit","locale","sort","where","value","dataToRender","setDataToRender","exportTotalDocs","setExportTotalDocs","maxLimit","setMaxLimit","undefined","columns","setColumns","i18n","t","previewPage","setPreviewPage","previewLimit","setPreviewLimit","paginationData","setPaginationData","prevExportConfigRef","prevConfig","current","configChanged","JSON","stringify","targetCollectionSlug","isCSV","abortController","AbortController","fetchData","res","fetch","api","body","credentials","headers","method","signal","ok","serverColumns","docs","serverExportTotalDocs","hasNextPage","hasPrevPage","responseLimit","serverMaxLimit","page","responsePage","totalPages","json","allKeys","Array","from","Set","flatMap","doc","Object","keys","fieldKeys","length","newColumns","map","key","accessor","active","field","name","Heading","renderedCells","val","String","isArray","join","nextPage","prevPage","error","console","aborted","abort","handlePageChange","handlePerPageChange","newLimit","div","className","h3","i18nKey","span","variables","count","data","language","readOnly","numberOfNeighbors","onChange","end","Math","min","start","total","handleChange","limits"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,cAAc,EACdC,UAAU,EACVC,OAAO,EACPC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,kBAAkB,EAClBC,eAAe,EACfC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,QAAO;AAQzE,SAASC,qBAAqB,EAAEC,qBAAqB,QAAQ,qBAAoB;AACjF,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAAO,cAAa;AAEpB,MAAMC,YAAY;AAElB,OAAO,MAAMC,gBAA0B;IACrC,MAAM,CAACC,WAAWC,gBAAgB,GAAGP;IACrC,MAAM,EAAEQ,UAAU,EAAE,GAAGL;IACvB,MAAM,EACJM,MAAM,EACNA,QAAQ,EAAEC,MAAM,EAAE,EACnB,GAAGnB;IACJ,MAAM,EAAEoB,cAAc,EAAE,GAAGlB;IAC3B,MAAM,EAAEmB,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGxB,cAAc,CAAC,CAACmB,OAAO;QACnF,OAAO;YACLD,OAAOC,MAAM,CAAC,SAAS,EAAEM;YACzBN,QAAQA,MAAM,CAAC,SAAS,EAAEM;YAC1BL,QAAQD,MAAM,CAAC,SAAS,EAAEM;YAC1BJ,OAAOF,MAAM,CAAC,QAAQ,EAAEM;YACxBH,QAAQH,MAAM,CAAC,SAAS,EAAEM;YAC1BF,MAAMJ,MAAM,CAAC,OAAO,EAAEM;YACtBD,OAAOL,MAAM,CAAC,QAAQ,EAAEM;QAC1B;IACF;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,cAAcX;gCACzD6F,OAAO,AAAC,CAAA,AAAChF,CAAAA,eAAe6B,IAAI,IAAI,CAAA,IAAK,CAAA,IAAK/B,eAAe;gCACzDmF,OAAO9F;4BACT;;;kCAGJ,KAAClC;wBACCiI,cAAcnB;wBACdnF,OAAOkB;wBACPqF,QAAQpH;;;;;;AAMpB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/ExportPreview/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Column, PaginatedDocs, Where } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n CodeEditorLazy,\n Pagination,\n PerPage,\n Table,\n Translation,\n useConfig,\n useDebouncedEffect,\n useDocumentInfo,\n useForm,\n useFormFields,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useEffect, useRef, useState, useTransition } from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\nimport type { ExportPreviewResponse } from '../../types.js'\n\nimport { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js'\nimport {\n getFormStateSignature,\n getSubmittedFormValues,\n} from '../../utilities/getSubmittedFormValues.js'\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.css'\n\nconst baseClass = 'export-preview'\n\nexport const ExportPreview: React.FC = () => {\n const [isPending, startTransition] = useTransition()\n const { collection } = useImportExport()\n const {\n config,\n config: { routes },\n } = useConfig()\n const { collectionSlug } = useDocumentInfo()\n const { draft, fields, format, limit, locale, sort, where } = useFormFields(([fields]) => {\n return {\n draft: fields['drafts']?.value,\n fields: fields['fields']?.value,\n format: fields['format']?.value,\n limit: fields['limit']?.value as number,\n locale: fields['locale']?.value as string,\n sort: fields['sort']?.value as string,\n where: fields['where']?.value as Where,\n }\n })\n const { getData } = useForm()\n const formStateSignature = useFormFields(([fields]) => getFormStateSignature({ fields }))\n const [dataToRender, setDataToRender] = useState<any[]>([])\n const [exportTotalDocs, setExportTotalDocs] = useState<number>(0)\n const [maxLimit, setMaxLimit] = useState<number | undefined>(undefined)\n const [columns, setColumns] = useState<Column[]>([])\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n // Preview pagination state (separate from export config)\n const [previewPage, setPreviewPage] = useState(1)\n const [previewLimit, setPreviewLimit] = useState(DEFAULT_PREVIEW_LIMIT)\n const [paginationData, setPaginationData] = useState<null | Pick<\n PaginatedDocs,\n 'hasNextPage' | 'hasPrevPage' | 'limit' | 'nextPage' | 'page' | 'prevPage' | 'totalPages'\n >>(null)\n\n // Track previous export config to reset preview page when it changes\n const prevExportConfigRef = useRef({ draft, fields, format, limit, locale, sort, where })\n\n // Reset preview page when export config changes\n useEffect(() => {\n const prevConfig = prevExportConfigRef.current\n const configChanged =\n prevConfig.draft !== draft ||\n prevConfig.limit !== limit ||\n prevConfig.locale !== locale ||\n prevConfig.sort !== sort ||\n JSON.stringify(prevConfig.fields) !== JSON.stringify(fields) ||\n JSON.stringify(prevConfig.where) !== JSON.stringify(where)\n\n if (configChanged) {\n setPreviewPage(1)\n prevExportConfigRef.current = { draft, fields, format, limit, locale, sort, where }\n }\n }, [draft, fields, format, limit, locale, sort, where])\n\n const targetCollectionSlug = typeof collection === 'string' && collection\n\n const isCSV = format === 'csv'\n\n useDebouncedEffect(\n () => {\n if (!collectionSlug || !targetCollectionSlug) {\n return\n }\n\n const abortController = new AbortController()\n\n const fetchData = async () => {\n try {\n const res = await fetch(`${routes.api}/${collectionSlug}/export-preview`, {\n body: JSON.stringify({\n collectionSlug: targetCollectionSlug,\n draft,\n fields,\n format,\n formData: getSubmittedFormValues({ formData: getData() }),\n limit,\n locale,\n previewLimit,\n previewPage,\n sort,\n where,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n signal: abortController.signal,\n })\n\n if (!res.ok) {\n return\n }\n\n const {\n columns: serverColumns,\n docs,\n exportTotalDocs: serverExportTotalDocs,\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n maxLimit: serverMaxLimit,\n page: responsePage,\n totalPages,\n }: ExportPreviewResponse = await res.json()\n\n // For CSV: use server-provided columns (from getSchemaColumns) for consistent ordering\n // For JSON: derive keys from docs\n const allKeys = Array.from(new Set(docs.flatMap((doc) => Object.keys(doc))))\n\n // Use server columns if available (CSV format), otherwise fall back to data-derived keys\n const fieldKeys = serverColumns && serverColumns.length > 0 ? serverColumns : allKeys\n\n // Build columns based on field keys\n const newColumns: Column[] = fieldKeys.map((key) => ({\n accessor: key,\n active: true,\n field: { name: key } as ClientField,\n Heading: getTranslation(key, i18n),\n renderedCells: docs.map((doc: Record<string, unknown>) => {\n const val = doc[key]\n\n if (val === undefined || val === null) {\n return null\n }\n\n // Avoid ESLint warning by type-checking before calling String()\n if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {\n return String(val)\n }\n\n if (Array.isArray(val)) {\n return val.map(String).join(', ')\n }\n\n return JSON.stringify(val)\n }),\n }))\n\n setExportTotalDocs(serverExportTotalDocs)\n setMaxLimit(serverMaxLimit)\n setPaginationData({\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n nextPage: responsePage + 1,\n page: responsePage,\n prevPage: responsePage - 1,\n totalPages,\n })\n setColumns(newColumns)\n setDataToRender(docs)\n } catch (error) {\n console.error('Error fetching preview data:', error)\n }\n }\n\n startTransition(async () => await fetchData())\n\n return () => {\n if (!abortController.signal.aborted) {\n abortController.abort('Component unmounted')\n }\n }\n },\n [\n collectionSlug,\n draft,\n fields,\n format,\n formStateSignature,\n getData,\n i18n,\n limit,\n locale,\n previewLimit,\n previewPage,\n sort,\n where,\n routes.api,\n targetCollectionSlug,\n ],\n 500,\n )\n\n const handlePageChange = (page: number) => {\n setPreviewPage(page)\n }\n\n const handlePerPageChange = (newLimit: number) => {\n setPreviewLimit(newLimit)\n setPreviewPage(1)\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {exportTotalDocs > 0 && !isPending && (\n <div className={`${baseClass}__export-info`}>\n <span className={`${baseClass}__export-count`}>\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:documentsToExport\"\n t={t}\n variables={{\n count: exportTotalDocs,\n }}\n />\n </span>\n {typeof maxLimit === 'number' &&\n maxLimit > 0 &&\n typeof limit === 'number' &&\n limit > maxLimit && (\n <span className={`${baseClass}__limit-capped`}>\n <Translation\n // @ts-expect-error - plugin translations not typed\n i18nKey=\"plugin-import-export:limitCapped\"\n t={t}\n variables={{\n limit: maxLimit,\n }}\n />\n </span>\n )}\n </div>\n )}\n </div>\n {isPending && !dataToRender && (\n <div className={`${baseClass}__loading`}>\n <Translation i18nKey=\"general:loading\" t={t} />\n </div>\n )}\n {dataToRender &&\n (isCSV ? (\n <Table columns={columns} data={dataToRender} />\n ) : (\n <CodeEditorLazy language=\"json\" readOnly value={JSON.stringify(dataToRender, null, 2)} />\n ))}\n {paginationData && exportTotalDocs > 0 && (\n <div className={`${baseClass}__pagination`}>\n {paginationData.totalPages > 1 && (\n <Pagination\n hasNextPage={paginationData.hasNextPage}\n hasPrevPage={paginationData.hasPrevPage}\n nextPage={paginationData.nextPage ?? undefined}\n numberOfNeighbors={1}\n onChange={handlePageChange}\n page={paginationData.page}\n prevPage={paginationData.prevPage ?? undefined}\n totalPages={paginationData.totalPages}\n />\n )}\n <span className={`${baseClass}__page-info`}>\n <Translation\n // @ts-expect-error - plugin translations not typed\n i18nKey=\"plugin-import-export:previewPageInfo\"\n t={t}\n variables={{\n end: Math.min((paginationData.page ?? 1) * previewLimit, exportTotalDocs),\n start: ((paginationData.page ?? 1) - 1) * previewLimit + 1,\n total: exportTotalDocs,\n }}\n />\n </span>\n <PerPage\n handleChange={handlePerPageChange}\n limit={previewLimit}\n limits={PREVIEW_LIMIT_OPTIONS}\n />\n </div>\n )}\n </div>\n )\n}\n"],"names":["getTranslation","CodeEditorLazy","Pagination","PerPage","Table","Translation","useConfig","useDebouncedEffect","useDocumentInfo","useForm","useFormFields","useTranslation","React","useEffect","useRef","useState","useTransition","DEFAULT_PREVIEW_LIMIT","PREVIEW_LIMIT_OPTIONS","getFormStateSignature","getSubmittedFormValues","useImportExport","baseClass","ExportPreview","isPending","startTransition","collection","config","routes","collectionSlug","draft","fields","format","limit","locale","sort","where","value","getData","formStateSignature","dataToRender","setDataToRender","exportTotalDocs","setExportTotalDocs","maxLimit","setMaxLimit","undefined","columns","setColumns","i18n","t","previewPage","setPreviewPage","previewLimit","setPreviewLimit","paginationData","setPaginationData","prevExportConfigRef","prevConfig","current","configChanged","JSON","stringify","targetCollectionSlug","isCSV","abortController","AbortController","fetchData","res","fetch","api","body","formData","credentials","headers","method","signal","ok","serverColumns","docs","serverExportTotalDocs","hasNextPage","hasPrevPage","responseLimit","serverMaxLimit","page","responsePage","totalPages","json","allKeys","Array","from","Set","flatMap","doc","Object","keys","fieldKeys","length","newColumns","map","key","accessor","active","field","name","Heading","renderedCells","val","String","isArray","join","nextPage","prevPage","error","console","aborted","abort","handlePageChange","handlePerPageChange","newLimit","div","className","h3","i18nKey","span","variables","count","data","language","readOnly","numberOfNeighbors","onChange","end","Math","min","start","total","handleChange","limits"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,cAAc,EACdC,UAAU,EACVC,OAAO,EACPC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,kBAAkB,EAClBC,eAAe,EACfC,OAAO,EACPC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,QAAO;AAQzE,SAASC,qBAAqB,EAAEC,qBAAqB,QAAQ,qBAAoB;AACjF,SACEC,qBAAqB,EACrBC,sBAAsB,QACjB,4CAA2C;AAClD,SAASC,eAAe,QAAQ,mCAAkC;AAClE,OAA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;;YAObpB,aAAa,CAACgB,8BACb,KAACiF;gBAAIC,WAAW,GAAGpG,UAAU,SAAS,CAAC;0BACrC,cAAA,KAACjB;oBAAYuH,SAAQ;oBAAkB1E,GAAGA;;;YAG7CV,gBACEwB,CAAAA,sBACC,KAAC5D;gBAAM2C,SAASA;gBAASiF,MAAMxF;+BAE/B,KAACvC;gBAAegI,UAAS;gBAAOC,QAAQ;gBAAC7F,OAAOwB,KAAKC,SAAS,CAACtB,cAAc,MAAM;cACrF;YACDe,kBAAkBb,kBAAkB,mBACnC,MAAC+E;gBAAIC,WAAW,GAAGpG,UAAU,YAAY,CAAC;;oBACvCiC,eAAegC,UAAU,GAAG,mBAC3B,KAACrF;wBACC+E,aAAa1B,eAAe0B,WAAW;wBACvCC,aAAa3B,eAAe2B,WAAW;wBACvC8B,UAAUzD,eAAeyD,QAAQ,IAAIlE;wBACrCqF,mBAAmB;wBACnBC,UAAUd;wBACVjC,MAAM9B,eAAe8B,IAAI;wBACzB4B,UAAU1D,eAAe0D,QAAQ,IAAInE;wBACrCyC,YAAYhC,eAAegC,UAAU;;kCAGzC,KAACsC;wBAAKH,WAAW,GAAGpG,UAAU,WAAW,CAAC;kCACxC,cAAA,KAACjB;4BACC,mDAAmD;4BACnDuH,SAAQ;4BACR1E,GAAGA;4BACH4E,WAAW;gCACTO,KAAKC,KAAKC,GAAG,CAAC,AAAChF,CAAAA,eAAe8B,IAAI,IAAI,CAAA,IAAKhC,cAAcX;gCACzD8F,OAAO,AAAC,CAAA,AAACjF,CAAAA,eAAe8B,IAAI,IAAI,CAAA,IAAK,CAAA,IAAKhC,eAAe;gCACzDoF,OAAO/F;4BACT;;;kCAGJ,KAACvC;wBACCuI,cAAcnB;wBACdtF,OAAOoB;wBACPsF,QAAQzH;;;;;;AAMpB,EAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SelectFieldClientProps } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const FieldsToExport: React.FC<SelectFieldClientProps>;
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAWrD,OAAO,KAAoB,MAAM,OAAO,CAAA;AAOxC,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA2E3D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/FieldsToExport/index.tsx"],"sourcesContent":["'use client'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/FieldsToExport/index.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientProps } from 'payload'\nimport type { ReactNode } from 'react'\n\nimport {\n FieldLabel,\n ReactSelect,\n useConfig,\n useDocumentInfo,\n useField,\n useListQuery,\n} from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport { reduceFields } from './reduceFields.js'\n\nconst baseClass = 'field-type fields-to-export'\n\nexport const FieldsToExport: React.FC<SelectFieldClientProps> = (props) => {\n const { id } = useDocumentInfo()\n const { setValue, value } = useField<string[]>()\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n const { query } = useListQuery()\n\n const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })\n\n const disabledFields =\n collectionConfig?.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const fieldOptions = reduceFields({\n disabledFields,\n fields: collectionConfig?.fields,\n })\n\n useEffect(() => {\n if (id || !collectionSlug) {\n return\n }\n\n const queryColumns = query?.columns\n\n if (Array.isArray(queryColumns)) {\n const cleanColumns = queryColumns.filter(\n (col): col is string => typeof col === 'string' && !col.startsWith('-'),\n )\n // If columns are specified in the query, use them\n setValue(cleanColumns)\n } else {\n // Fallback if no columns in query\n setValue(collectionConfig?.admin?.defaultColumns ?? [])\n }\n }, [id, collectionSlug, query?.columns, collectionConfig?.admin?.defaultColumns, setValue])\n\n const onChange = (options: { id: string; label: ReactNode; value: string }[]) => {\n if (!options) {\n setValue([])\n return\n }\n\n const updatedValue = options.map((option) =>\n typeof option === 'object' ? option.value : option,\n )\n\n setValue(updatedValue)\n }\n\n return (\n <div className={baseClass}>\n <FieldLabel label={props.field.label} path={props.path} />\n <ReactSelect\n className={baseClass}\n disabled={props.readOnly}\n getOptionValue={(option) => String(option.value)}\n inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={true}\n isMulti={true}\n isSortable={true}\n // @ts-expect-error react select option\n onChange={onChange}\n options={fieldOptions}\n value={\n Array.isArray(value)\n ? value.map((val) => {\n const match = fieldOptions.find((opt) => opt.value === val)\n return match ? { ...match, id: val } : { id: val, label: val, value: val }\n })\n : []\n }\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useConfig","useDocumentInfo","useField","useListQuery","React","useEffect","useImportExport","reduceFields","baseClass","FieldsToExport","props","id","setValue","value","collectionSlug","path","getEntityConfig","collection","query","collectionConfig","disabledFields","admin","custom","fieldOptions","fields","queryColumns","columns","Array","isArray","cleanColumns","filter","col","startsWith","defaultColumns","onChange","options","updatedValue","map","option","div","className","label","field","disabled","readOnly","getOptionValue","String","inputId","replace","isClearable","isMulti","isSortable","val","match","find","opt"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,YAAY,QACP,iBAAgB;AACvB,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAExC,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qBACE,MAACG;QAAIC,WAAWhC;;0BACd,KAACV;gBAAW2C,OAAO/B,MAAMgC,KAAK,CAACD,KAAK;gBAAE1B,MAAML,MAAMK,IAAI;;0BACtD,KAAChB;gBACCyC,WAAWhC;gBACXmC,UAAUjC,MAAMkC,QAAQ;gBACxBC,gBAAgB,CAACP,SAAWQ,OAAOR,OAAOzB,KAAK;gBAC/CkC,SAAS,CAAC,MAAM,EAAErC,MAAMK,IAAI,CAACiC,OAAO,CAAC,OAAO,OAAO;gBACnDC,aAAa;gBACbC,SAAS;gBACTC,YAAY;gBACZ,uCAAuC;gBACvCjB,UAAUA;gBACVC,SAASZ;gBACTV,OACEc,MAAMC,OAAO,CAACf,SACVA,MAAMwB,GAAG,CAAC,CAACe;oBACT,MAAMC,QAAQ9B,aAAa+B,IAAI,CAAC,CAACC,MAAQA,IAAI1C,KAAK,KAAKuC;oBACvD,OAAOC,QAAQ;wBAAE,GAAGA,KAAK;wBAAE1C,IAAIyC;oBAAI,IAAI;wBAAEzC,IAAIyC;wBAAKX,OAAOW;wBAAKvC,OAAOuC;oBAAI;gBAC3E,KACA,EAAE;;;;AAKhB,EAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SelectFieldClientProps } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const FormatField: React.FC<SelectFieldClientProps>;
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormatField/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormatField/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAGrD,OAAO,KAA0C,MAAM,OAAO,CAAA;AAW9D,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAiExD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/FormatField/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ReactSelectOption } from '@payloadcms/ui'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/FormatField/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ReactSelectOption } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\n\nimport { FieldLabel, ReactSelect, useConfig, useField } from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useMemo } from 'react'\n\nconst baseClass = 'field-type select'\n\ntype Format = 'csv' | 'json'\n\nconst allOptions: ReactSelectOption[] = [\n { label: 'CSV', value: 'csv' },\n { label: 'JSON', value: 'json' },\n]\n\nexport const FormatField: React.FC<SelectFieldClientProps> = (props) => {\n const { getEntityConfig } = useConfig()\n const width = props.field.admin?.width\n\n const styles = useMemo<React.CSSProperties>(\n () => ({ '--field-width': width }) as React.CSSProperties,\n [width],\n )\n\n const { setValue, value: formatValue } = useField<Format>()\n const { value: targetCollectionSlug } = useField<string>({ path: 'collectionSlug' })\n\n const targetCollectionConfig = getEntityConfig({ collectionSlug: targetCollectionSlug })\n const forcedFormat = targetCollectionConfig?.admin?.custom?.['plugin-import-export']\n ?.exportFormat as Format | undefined\n\n const options = useMemo<ReactSelectOption[]>(() => {\n if (forcedFormat) {\n return [{ label: forcedFormat.toUpperCase(), value: forcedFormat }]\n }\n return allOptions\n }, [forcedFormat])\n\n const selectedOption = useMemo<ReactSelectOption | undefined>(() => {\n const effectiveValue = forcedFormat || formatValue || 'csv'\n return options.find((o) => o.value === effectiveValue) ?? options[0]\n }, [forcedFormat, formatValue, options])\n\n useEffect(() => {\n if (forcedFormat && formatValue !== forcedFormat) {\n setValue(forcedFormat)\n }\n }, [forcedFormat, formatValue, setValue])\n\n const handleChange = useCallback(\n (selected: ReactSelectOption | ReactSelectOption[]) => {\n if (forcedFormat) {\n return\n }\n if (Array.isArray(selected)) {\n setValue((selected[0]?.value as Format) ?? 'csv')\n } else {\n setValue((selected?.value as Format) ?? 'csv')\n }\n },\n [forcedFormat, setValue],\n )\n\n const isReadOnly = Boolean(forcedFormat) || props.readOnly\n\n return (\n <div className={baseClass} style={styles}>\n <FieldLabel label={props.field.label} path={props.path} />\n <ReactSelect\n className={'format-field'}\n disabled={isReadOnly}\n inputId={`field-${props.path.replace(/\\./g, '__')}`}\n isClearable={false}\n isSearchable={false}\n onChange={handleChange}\n options={options}\n value={selectedOption}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useConfig","useField","React","useCallback","useEffect","useMemo","baseClass","allOptions","label","value","FormatField","props","getEntityConfig","width","field","admin","styles","setValue","formatValue","targetCollectionSlug","path","targetCollectionConfig","collectionSlug","forcedFormat","custom","exportFormat","options","toUpperCase","selectedOption","effectiveValue","find","o","handleChange","selected","Array","isArray","isReadOnly","Boolean","readOnly","div","className","style","disabled","inputId","replace","isClearable","isSearchable","onChange"],"mappings":"AAAA;;AAKA,SAASA,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AAC7E,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,QAAO;AAE9D,MAAMC,YAAY;AAIlB,MAAMC,aAAkC;IACtC;QAAEC,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAQC,OAAO;IAAO;CAChC;AAED,OAAO,MAAMC,cAAgD,CAACC;IAC5D,MAAM,EAAEC,eAAe,EAAE,GAAGZ;IAC5B,MAAMa,QAAQF,MAAMG,KAAK,CAACC,KAAK,EAAEF;IAEjC,MAAMG,SAASX,QACb,IAAO,CAAA;YAAE,iBAAiBQ;QAAM,CAAA,GAChC;QAACA;KAAM;IAGT,MAAM,EAAEI,QAAQ,EAAER,OAAOS,WAAW,EAAE,GAAGjB;IACzC,MAAM,EAAE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OAAO;gBACnDC,aAAa;gBACbC,cAAc;gBACdC,UAAUf;gBACVN,SAASA;gBACTjB,OAAOmB;;;;AAIf,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImportListMenuItem/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImportListMenuItem/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoB,MAAM,OAAO,CAAA;AAWxC,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;IACxC,cAAc,EAAE,MAAM,CAAA;IACtB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAqCA,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
-
import {
|
|
4
|
+
import { useConfig, useDocumentDrawer, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import React, { useEffect } from 'react';
|
|
6
6
|
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
7
7
|
const baseClass = 'import-list-menu-item';
|
|
@@ -11,6 +11,10 @@ export const ImportListMenuItem = ({ collectionSlug, importCollectionSlug })=>{
|
|
|
11
11
|
const currentCollectionConfig = getEntityConfig({
|
|
12
12
|
collectionSlug
|
|
13
13
|
});
|
|
14
|
+
const collectionLabel = getTranslation(currentCollectionConfig.labels.plural, i18n);
|
|
15
|
+
const actionLabel = t('plugin-import-export:importDocumentLabel', {
|
|
16
|
+
label: collectionLabel
|
|
17
|
+
});
|
|
14
18
|
const [DocumentDrawer, DocumentDrawerToggler] = useDocumentDrawer({
|
|
15
19
|
collectionSlug: importCollectionSlug
|
|
16
20
|
});
|
|
@@ -22,18 +26,16 @@ export const ImportListMenuItem = ({ collectionSlug, importCollectionSlug })=>{
|
|
|
22
26
|
currentCollectionConfig,
|
|
23
27
|
setCollection
|
|
24
28
|
]);
|
|
25
|
-
return /*#__PURE__*/ _jsxs(
|
|
26
|
-
className: baseClass,
|
|
29
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
27
30
|
children: [
|
|
28
31
|
/*#__PURE__*/ _jsx(DocumentDrawerToggler, {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
32
|
+
"aria-label": actionLabel,
|
|
33
|
+
className: `popup-button-list__button ${baseClass}`,
|
|
34
|
+
role: "menuitem",
|
|
35
|
+
tabIndex: -1,
|
|
36
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
37
|
+
className: "popup-button-list__label",
|
|
38
|
+
children: actionLabel
|
|
37
39
|
})
|
|
38
40
|
}),
|
|
39
41
|
/*#__PURE__*/ _jsx(DocumentDrawer, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/ImportListMenuItem/index.tsx"],"sourcesContent":["'use client'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/ImportListMenuItem/index.tsx"],"sourcesContent":["'use client'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { useConfig, useDocumentDrawer, useTranslation } from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\n\nconst baseClass = 'import-list-menu-item'\n\nexport const ImportListMenuItem: React.FC<{\n collectionSlug: string\n importCollectionSlug: string\n}> = ({ collectionSlug, importCollectionSlug }) => {\n const { getEntityConfig } = useConfig()\n\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const currentCollectionConfig = getEntityConfig({ collectionSlug })\n const collectionLabel = getTranslation(currentCollectionConfig.labels.plural, i18n)\n const actionLabel = t('plugin-import-export:importDocumentLabel', {\n label: collectionLabel,\n })\n\n const [DocumentDrawer, DocumentDrawerToggler] = useDocumentDrawer({\n collectionSlug: importCollectionSlug,\n })\n const { setCollection } = useImportExport()\n\n // Set collection and selected items on mount or when selection changes\n useEffect(() => {\n setCollection(currentCollectionConfig.slug ?? '')\n }, [currentCollectionConfig, setCollection])\n\n return (\n <>\n <DocumentDrawerToggler\n aria-label={actionLabel}\n className={`popup-button-list__button ${baseClass}`}\n role=\"menuitem\"\n tabIndex={-1}\n >\n <span className=\"popup-button-list__label\">{actionLabel}</span>\n </DocumentDrawerToggler>\n <DocumentDrawer initialData={{ collectionSlug }} />\n </>\n )\n}\n"],"names":["getTranslation","useConfig","useDocumentDrawer","useTranslation","React","useEffect","useImportExport","baseClass","ImportListMenuItem","collectionSlug","importCollectionSlug","getEntityConfig","i18n","t","currentCollectionConfig","collectionLabel","labels","plural","actionLabel","label","DocumentDrawer","DocumentDrawerToggler","setCollection","slug","aria-label","className","role","tabIndex","span","initialData"],"mappings":"AAAA;;AAEA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,iBAAgB;AAC7E,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAOxC,SAASC,eAAe,QAAQ,mCAAkC;AAElE,MAAMC,YAAY;AAElB,OAAO,MAAMC,qBAGR,CAAC,EAAEC,cAAc,EAAEC,oBAAoB,EAAE;IAC5C,MAAM,EAAEC,eAAe,EAAE,GAAGV;IAE5B,MAAM,EAAEW,IAAI,EAAEC,CAAC,EAAE,GAAGV;IAKpB,MAAMW,0BAA0BH,gBAAgB;QAAEF;IAAe;IACjE,MAAMM,kBAAkBf,eAAec,wBAAwBE,MAAM,CAACC,MAAM,EAAEL;IAC9E,MAAMM,cAAcL,EAAE,4CAA4C;QAChEM,OAAOJ;IACT;IAEA,MAAM,CAACK,gBAAgBC,sBAAsB,GAAGnB,kBAAkB;QAChEO,gBAAgBC;IAClB;IACA,MAAM,EAAEY,aAAa,EAAE,GAAGhB;IAE1B,uEAAuE;IACvED,UAAU;QACRiB,cAAcR,wBAAwBS,IAAI,IAAI;IAChD,GAAG;QAACT;QAAyBQ;KAAc;IAE3C,qBACE;;0BACE,KAACD;gBACCG,cAAYN;gBACZO,WAAW,CAAC,0BAA0B,EAAElB,WAAW;gBACnDmB,MAAK;gBACLC,UAAU,CAAC;0BAEX,cAAA,KAACC;oBAAKH,WAAU;8BAA4BP;;;0BAE9C,KAACE;gBAAeS,aAAa;oBAAEpB;gBAAe;;;;AAGpD,EAAC"}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
.import-preview__info {
|
|
10
10
|
color: var(--color-text-secondary);
|
|
11
|
-
font-family: var(--text-body-medium-font-family);
|
|
12
11
|
font-size: var(--text-body-medium-font-size);
|
|
13
12
|
font-weight: var(--text-body-medium-font-weight);
|
|
14
13
|
line-height: var(--text-body-medium-line-height);
|
|
@@ -16,7 +15,6 @@
|
|
|
16
15
|
|
|
17
16
|
.import-preview__import-count {
|
|
18
17
|
color: var(--color-text-secondary);
|
|
19
|
-
font-family: var(--text-body-medium-font-family);
|
|
20
18
|
font-size: var(--text-body-medium-font-size);
|
|
21
19
|
font-weight: var(--text-body-medium-font-weight);
|
|
22
20
|
line-height: var(--text-body-medium-line-height);
|
|
@@ -39,7 +37,6 @@
|
|
|
39
37
|
|
|
40
38
|
.import-preview__page-info {
|
|
41
39
|
color: var(--color-text-secondary);
|
|
42
|
-
font-family: var(--text-body-medium-font-family);
|
|
43
40
|
font-size: var(--text-body-medium-font-size);
|
|
44
41
|
font-weight: var(--text-body-medium-font-weight);
|
|
45
42
|
line-height: var(--text-body-medium-line-height);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImportPreview/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImportPreview/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAkC,MAAM,OAAO,CAAA;AActD,OAAO,aAAa,CAAA;AAuBpB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EA+nBjC,CAAA"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
-
import { Pagination, PerPage, Table, Translation, useConfig, useDebouncedEffect, useDocumentInfo, useField, useFormFields, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import { Pagination, PerPage, Table, Translation, useConfig, useDebouncedEffect, useDocumentInfo, useField, useForm, useFormFields, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import { formatDocTitle } from '@payloadcms/ui/shared';
|
|
6
6
|
import { fieldAffectsData, getObjectDotNotation } from 'payload/shared';
|
|
7
7
|
import React, { useState, useTransition } from 'react';
|
|
8
8
|
import { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js';
|
|
9
|
+
import { getFormStateSignature, getSubmittedFormValues } from '../../utilities/getSubmittedFormValues.js';
|
|
10
|
+
import { RelationshipCell } from '../RelationshipCell/index.js';
|
|
9
11
|
import './index.css';
|
|
10
12
|
const baseClass = 'import-preview';
|
|
13
|
+
// The file contents are sent separately as `fileData`.
|
|
14
|
+
const nonSerializableFormKeys = [
|
|
15
|
+
'file'
|
|
16
|
+
];
|
|
11
17
|
/**
|
|
12
18
|
* Browser-native ArrayBuffer → base64. Avoids Node's `Buffer`, which is not
|
|
13
19
|
* available in the browser under bundlers that don't polyfill it (e.g. Vite),
|
|
@@ -53,6 +59,11 @@ export const ImportPreview = ()=>{
|
|
|
53
59
|
});
|
|
54
60
|
// Access the file field directly from form fields
|
|
55
61
|
const fileField = useFormFields(([fields])=>fields?.file || null);
|
|
62
|
+
const { getData } = useForm();
|
|
63
|
+
const formStateSignature = useFormFields(([fields])=>getFormStateSignature({
|
|
64
|
+
fields,
|
|
65
|
+
omit: nonSerializableFormKeys
|
|
66
|
+
}));
|
|
56
67
|
const [dataToRender, setDataToRender] = useState([]);
|
|
57
68
|
const [columns, setColumns] = useState([]);
|
|
58
69
|
const [totalDocs, setTotalDocs] = useState(0);
|
|
@@ -127,6 +138,10 @@ export const ImportPreview = ()=>{
|
|
|
127
138
|
collectionSlug: targetCollectionSlug,
|
|
128
139
|
fileData,
|
|
129
140
|
format,
|
|
141
|
+
formData: getSubmittedFormValues({
|
|
142
|
+
formData: getData(),
|
|
143
|
+
omit: nonSerializableFormKeys
|
|
144
|
+
}),
|
|
130
145
|
previewLimit,
|
|
131
146
|
previewPage
|
|
132
147
|
}),
|
|
@@ -187,16 +202,21 @@ export const ImportPreview = ()=>{
|
|
|
187
202
|
active: true,
|
|
188
203
|
field,
|
|
189
204
|
Heading: label,
|
|
190
|
-
renderedCells: docs.map((doc)=>{
|
|
205
|
+
renderedCells: docs.map((doc, rowIndex)=>{
|
|
191
206
|
const value = getObjectDotNotation(doc, fieldPath);
|
|
192
207
|
if (value === undefined || value === null) {
|
|
193
208
|
return null;
|
|
194
209
|
}
|
|
195
210
|
// Format based on field type
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
const shouldRenderGroupedRelationship = format === 'json' && field.type === 'relationship' && Array.isArray(field.relationTo);
|
|
212
|
+
if (shouldRenderGroupedRelationship) {
|
|
213
|
+
return /*#__PURE__*/ _jsx(RelationshipCell, {
|
|
214
|
+
fieldPath: fieldPath,
|
|
215
|
+
relationTo: field.relationTo,
|
|
216
|
+
value: value
|
|
217
|
+
}, `${fieldPath}-${rowIndex}`);
|
|
218
|
+
} else if (field.type === 'relationship' || field.type === 'upload') {
|
|
198
219
|
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
199
|
-
// Single relationship
|
|
200
220
|
const relationTo = Array.isArray(field.relationTo) ? value.relationTo : field.relationTo;
|
|
201
221
|
const relatedConfig = config.collections.find((c)=>c.slug === relationTo);
|
|
202
222
|
if (relatedConfig && relatedConfig.admin?.useAsTitle) {
|
|
@@ -210,11 +230,9 @@ export const ImportPreview = ()=>{
|
|
|
210
230
|
});
|
|
211
231
|
}
|
|
212
232
|
}
|
|
213
|
-
// Fallback to ID
|
|
214
233
|
const id = value.id || value;
|
|
215
234
|
return `${getTranslation(relatedConfig?.labels?.singular || relationTo, i18n)}: ${id}`;
|
|
216
235
|
} else if (Array.isArray(value)) {
|
|
217
|
-
// Multiple relationships
|
|
218
236
|
return value.map((item)=>{
|
|
219
237
|
if (typeof item === 'object') {
|
|
220
238
|
const relationTo = Array.isArray(field.relationTo) ? item.relationTo : field.relationTo;
|
|
@@ -235,7 +253,6 @@ export const ImportPreview = ()=>{
|
|
|
235
253
|
return item;
|
|
236
254
|
}).join(', ');
|
|
237
255
|
}
|
|
238
|
-
// Just an ID
|
|
239
256
|
return String(value);
|
|
240
257
|
} else if (field.type === 'date') {
|
|
241
258
|
// Display date as string to avoid wrong locale/timezone conversion
|
|
@@ -381,6 +398,8 @@ export const ImportPreview = ()=>{
|
|
|
381
398
|
filename,
|
|
382
399
|
mimeType,
|
|
383
400
|
fileField?.value,
|
|
401
|
+
formStateSignature,
|
|
402
|
+
getData,
|
|
384
403
|
collectionConfig,
|
|
385
404
|
config,
|
|
386
405
|
i18n,
|