@payloadcms/plugin-import-export 0.0.1-beta.0
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/README.md +17 -0
- package/dist/components/CollectionField/index.d.ts +3 -0
- package/dist/components/CollectionField/index.d.ts.map +1 -0
- package/dist/components/CollectionField/index.js +24 -0
- package/dist/components/CollectionField/index.js.map +1 -0
- package/dist/components/ExportListMenuItem/index.d.ts +7 -0
- package/dist/components/ExportListMenuItem/index.d.ts.map +1 -0
- package/dist/components/ExportListMenuItem/index.js +40 -0
- package/dist/components/ExportListMenuItem/index.js.map +1 -0
- package/dist/components/ExportListMenuItem/index.scss +52 -0
- package/dist/components/ExportSaveButton/index.d.ts +3 -0
- package/dist/components/ExportSaveButton/index.d.ts.map +1 -0
- package/dist/components/ExportSaveButton/index.js +27 -0
- package/dist/components/ExportSaveButton/index.js.map +1 -0
- package/dist/components/FieldsToExport/index.d.ts +3 -0
- package/dist/components/FieldsToExport/index.d.ts.map +1 -0
- package/dist/components/FieldsToExport/index.js +99 -0
- package/dist/components/FieldsToExport/index.js.map +1 -0
- package/dist/components/FieldsToExport/index.scss +0 -0
- package/dist/components/FieldsToExport/reduceFields.d.ts +12 -0
- package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -0
- package/dist/components/FieldsToExport/reduceFields.js +96 -0
- package/dist/components/FieldsToExport/reduceFields.js.map +1 -0
- package/dist/components/ImportExportProvider/index.d.ts +12 -0
- package/dist/components/ImportExportProvider/index.d.ts.map +1 -0
- package/dist/components/ImportExportProvider/index.js +20 -0
- package/dist/components/ImportExportProvider/index.js.map +1 -0
- package/dist/components/Preview/index.d.ts +4 -0
- package/dist/components/Preview/index.d.ts.map +1 -0
- package/dist/components/Preview/index.js +123 -0
- package/dist/components/Preview/index.js.map +1 -0
- package/dist/components/Preview/index.scss +8 -0
- package/dist/components/SortBy/index.d.ts +3 -0
- package/dist/components/SortBy/index.d.ts.map +1 -0
- package/dist/components/SortBy/index.js +91 -0
- package/dist/components/SortBy/index.js.map +1 -0
- package/dist/components/SortBy/index.scss +4 -0
- package/dist/components/WhereField/index.d.ts +4 -0
- package/dist/components/WhereField/index.d.ts.map +1 -0
- package/dist/components/WhereField/index.js +72 -0
- package/dist/components/WhereField/index.js.map +1 -0
- package/dist/components/WhereField/index.scss +0 -0
- package/dist/export/createExport.d.ts +24 -0
- package/dist/export/createExport.d.ts.map +1 -0
- package/dist/export/createExport.js +72 -0
- package/dist/export/createExport.js.map +1 -0
- package/dist/export/flattenObject.d.ts +2 -0
- package/dist/export/flattenObject.d.ts.map +1 -0
- package/dist/export/flattenObject.js +22 -0
- package/dist/export/flattenObject.js.map +1 -0
- package/dist/export/getCreateExportCollectionTask.d.ts +3 -0
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -0
- package/dist/export/getCreateExportCollectionTask.js +47 -0
- package/dist/export/getCreateExportCollectionTask.js.map +1 -0
- package/dist/export/getFields.d.ts +3 -0
- package/dist/export/getFields.d.ts.map +1 -0
- package/dist/export/getFields.js +175 -0
- package/dist/export/getFields.js.map +1 -0
- package/dist/export/getFilename.d.ts +2 -0
- package/dist/export/getFilename.d.ts.map +1 -0
- package/dist/export/getFilename.js +10 -0
- package/dist/export/getFilename.js.map +1 -0
- package/dist/export/getSelect.d.ts +7 -0
- package/dist/export/getSelect.d.ts.map +1 -0
- package/dist/export/getSelect.js +27 -0
- package/dist/export/getSelect.js.map +1 -0
- package/dist/exports/rsc.d.ts +9 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +10 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/types.d.ts +2 -0
- package/dist/exports/types.d.ts.map +1 -0
- package/dist/exports/types.js +3 -0
- package/dist/exports/types.js.map +1 -0
- package/dist/getExportCollection.d.ts +7 -0
- package/dist/getExportCollection.d.ts.map +1 -0
- package/dist/getExportCollection.js +65 -0
- package/dist/getExportCollection.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/en.d.ts +3 -0
- package/dist/translations/en.d.ts.map +1 -0
- package/dist/translations/en.js +9 -0
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +7 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +6 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/translation-schema.json +24 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/license.md +22 -0
- package/package.json +79 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Preview/index.tsx"],"sourcesContent":["'use client'\nimport type { Column } from '@payloadcms/ui'\nimport type { ClientField, FieldAffectingDataClient } from 'payload'\n\nimport { Table, useConfig, useField } from '@payloadcms/ui'\nimport { fieldAffectsData } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport React from 'react'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport './index.scss'\n\nconst baseClass = 'preview'\n\nexport const Preview = () => {\n const { collection } = useImportExport()\n const { config } = useConfig()\n const { value: where } = useField({ path: 'where' })\n const { value: limit } = useField<number>({ path: 'limit' })\n const { value: fields } = useField<string[]>({ path: 'fields' })\n const { value: sort } = useField({ path: 'sort' })\n const { value: draft } = useField({ path: 'draft' })\n const [dataToRender, setDataToRender] = React.useState<any[]>([])\n const [resultCount, setResultCount] = React.useState<any>('')\n const [columns, setColumns] = React.useState<Column[]>([])\n\n const collectionSlug = typeof collection === 'string' && collection\n const collectionConfig = config.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n\n React.useEffect(() => {\n const fetchData = async () => {\n if (!collectionSlug) {\n return\n }\n\n try {\n const whereQuery = qs.stringify(\n {\n depth: 0,\n draft,\n limit: limit > 10 ? 10 : limit,\n sort,\n where,\n },\n {\n addQueryPrefix: true,\n },\n )\n const response = await fetch(`/api/${collectionSlug}${whereQuery}`, {\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'GET',\n })\n\n if (response.ok) {\n const data = await response.json()\n setResultCount(limit && limit < data.totalDocs ? limit : data.totalDocs)\n // TODO: check if this data is in the correct format for the table\n\n const filteredFields = (collectionConfig?.fields?.filter((field) => {\n if (!fieldAffectsData(field)) {\n return false\n }\n if (fields?.length > 0) {\n return fields.includes(field.name)\n }\n return true\n }) ?? []) as FieldAffectingDataClient[]\n\n setColumns(\n filteredFields.map((field) => ({\n accessor: field.name || '',\n active: true,\n field: field as ClientField,\n Heading: field?.label || field.name,\n renderedCells: data.docs.map((doc: Record<string, unknown>) => {\n if (!field.name || !doc[field.name]) {\n return null\n }\n if (typeof doc[field.name] === 'object') {\n return JSON.stringify(doc[field.name])\n }\n return String(doc[field.name])\n }),\n })) as Column[],\n )\n setDataToRender(data.docs)\n }\n } catch (error) {\n console.error('Error fetching data:', error)\n }\n }\n\n void fetchData()\n }, [collectionConfig?.fields, collectionSlug, draft, fields, limit, sort, where])\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>Preview</h3>\n {resultCount && <span>{resultCount} total documents</span>}\n </div>\n {dataToRender && <Table columns={columns} data={dataToRender} />}\n </div>\n )\n}\n"],"names":["Table","useConfig","useField","fieldAffectsData","qs","React","useImportExport","baseClass","Preview","collection","config","value","where","path","limit","fields","sort","draft","dataToRender","setDataToRender","useState","resultCount","setResultCount","columns","setColumns","collectionSlug","collectionConfig","collections","find","slug","useEffect","fetchData","whereQuery","stringify","depth","addQueryPrefix","response","fetch","headers","method","ok","data","json","totalDocs","filteredFields","filter","field","length","includes","name","map","accessor","active","Heading","label","renderedCells","docs","doc","JSON","String","error","console","div","className","h3","span"],"mappings":"AAAA;;AAIA,SAASA,KAAK,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AAC3D,SAASC,gBAAgB,QAAQ,iBAAgB;AACjD,YAAYC,QAAQ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0BACd,MAACuD;gBAAIC,WAAW,GAAGxD,UAAU,QAAQ,CAAC;;kCACpC,KAACyD;kCAAG;;oBACH3C,6BAAe,MAAC4C;;4BAAM5C;4BAAY;;;;;YAEpCH,8BAAgB,KAAClB;gBAAMuB,SAASA;gBAASkB,MAAMvB;;;;AAGtD,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SortBy/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAkBzD,eAAO,MAAM,MAAM,EAAE,0BAqEpB,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldLabel, ReactSelect, useConfig, useDocumentInfo, useField, useListQuery } from '@payloadcms/ui';
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { reduceFields } from '../FieldsToExport/reduceFields.js';
|
|
6
|
+
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
7
|
+
const baseClass = 'sort-by-fields';
|
|
8
|
+
export const SortBy = (props)=>{
|
|
9
|
+
const { id } = useDocumentInfo();
|
|
10
|
+
const { path } = props;
|
|
11
|
+
const { setValue, value } = useField({
|
|
12
|
+
path
|
|
13
|
+
});
|
|
14
|
+
const { value: collectionSlug } = useField({
|
|
15
|
+
path: 'collectionSlug'
|
|
16
|
+
});
|
|
17
|
+
const { query } = useListQuery();
|
|
18
|
+
const { getEntityConfig } = useConfig();
|
|
19
|
+
const { collection } = useImportExport();
|
|
20
|
+
const [displayedValue, setDisplayedValue] = useState(null);
|
|
21
|
+
const collectionConfig = getEntityConfig({
|
|
22
|
+
collectionSlug: collectionSlug ?? collection
|
|
23
|
+
});
|
|
24
|
+
const fieldOptions = reduceFields({
|
|
25
|
+
fields: collectionConfig?.fields
|
|
26
|
+
});
|
|
27
|
+
// Sync displayedValue with value from useField
|
|
28
|
+
useEffect(()=>{
|
|
29
|
+
if (!value) {
|
|
30
|
+
setDisplayedValue(null);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const option = fieldOptions.find((field)=>field.value === value);
|
|
34
|
+
if (option && (!displayedValue || displayedValue.value !== value)) {
|
|
35
|
+
setDisplayedValue(option);
|
|
36
|
+
}
|
|
37
|
+
}, [
|
|
38
|
+
value,
|
|
39
|
+
fieldOptions
|
|
40
|
+
]);
|
|
41
|
+
useEffect(()=>{
|
|
42
|
+
if (id || !query?.sort || value) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const option = fieldOptions.find((field)=>field.value === query.sort);
|
|
46
|
+
if (option) {
|
|
47
|
+
setValue(option.value);
|
|
48
|
+
setDisplayedValue(option);
|
|
49
|
+
}
|
|
50
|
+
}, [
|
|
51
|
+
fieldOptions,
|
|
52
|
+
id,
|
|
53
|
+
query?.sort,
|
|
54
|
+
value,
|
|
55
|
+
setValue
|
|
56
|
+
]);
|
|
57
|
+
const onChange = (option)=>{
|
|
58
|
+
if (!option) {
|
|
59
|
+
setValue('');
|
|
60
|
+
setDisplayedValue(null);
|
|
61
|
+
} else {
|
|
62
|
+
setValue(option.value);
|
|
63
|
+
setDisplayedValue(option);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
67
|
+
className: baseClass,
|
|
68
|
+
style: {
|
|
69
|
+
'--field-width': '33%'
|
|
70
|
+
},
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
73
|
+
label: "Sort By"
|
|
74
|
+
}),
|
|
75
|
+
/*#__PURE__*/ _jsx(ReactSelect, {
|
|
76
|
+
className: baseClass,
|
|
77
|
+
disabled: props.readOnly,
|
|
78
|
+
getOptionValue: (option)=>String(option.value),
|
|
79
|
+
isClearable: true,
|
|
80
|
+
isSortable: true,
|
|
81
|
+
// @ts-expect-error react select option
|
|
82
|
+
onChange: onChange,
|
|
83
|
+
options: fieldOptions,
|
|
84
|
+
// @ts-expect-error react select
|
|
85
|
+
value: displayedValue
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SortBy/index.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientComponent } 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, useState } from 'react'\n\nimport { reduceFields } from '../FieldsToExport/reduceFields.js'\nimport { useImportExport } from '../ImportExportProvider/index.js'\n\nconst baseClass = 'sort-by-fields'\n\nexport const SortBy: SelectFieldClientComponent = (props) => {\n const { id } = useDocumentInfo()\n const { path } = props\n const { setValue, value } = useField<string>({ path })\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { query } = useListQuery()\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n const [displayedValue, setDisplayedValue] = useState<{\n id: string\n label: ReactNode\n value: string\n } | null>(null)\n\n const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })\n const fieldOptions = reduceFields({ fields: collectionConfig?.fields })\n\n // Sync displayedValue with value from useField\n useEffect(() => {\n if (!value) {\n setDisplayedValue(null)\n return\n }\n\n const option = fieldOptions.find((field) => field.value === value)\n if (option && (!displayedValue || displayedValue.value !== value)) {\n setDisplayedValue(option)\n }\n }, [value, fieldOptions])\n\n useEffect(() => {\n if (id || !query?.sort || value) {\n return\n }\n\n const option = fieldOptions.find((field) => field.value === query.sort)\n if (option) {\n setValue(option.value)\n setDisplayedValue(option)\n }\n }, [fieldOptions, id, query?.sort, value, setValue])\n\n const onChange = (option: { id: string; label: ReactNode; value: string } | null) => {\n if (!option) {\n setValue('')\n setDisplayedValue(null)\n } else {\n setValue(option.value)\n setDisplayedValue(option)\n }\n }\n\n return (\n <div className={baseClass} style={{ '--field-width': '33%' } as React.CSSProperties}>\n <FieldLabel label=\"Sort By\" />\n <ReactSelect\n className={baseClass}\n disabled={props.readOnly}\n getOptionValue={(option) => String(option.value)}\n isClearable={true}\n isSortable={true}\n // @ts-expect-error react select option\n onChange={onChange}\n options={fieldOptions}\n // @ts-expect-error react select\n value={displayedValue}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useConfig","useDocumentInfo","useField","useListQuery","React","useEffect","useState","reduceFields","useImportExport","baseClass","SortBy","props","id","path","setValue","value","collectionSlug","query","getEntityConfig","collection","displayedValue","setDisplayedValue","collectionConfig","fieldOptions","fields","option","find","field","sort","onChange","div","className","style","label","disabled","readOnly","getOptionValue","String","isClearable","isSortable","options"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,YAAY,QACP,iBAAgB;AACvB,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAElD,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,eAAe,QAAQ,mCAAkC;AAElE,MAAMC,YAAY;AAElB,OAAO,MAAMC,SAAqC,CAACC;IACjD,MAAM,EAAEC,EAAE,EAAE,GAAGX;IACf,MAAM,EAAEY,IAAI,EAAE,GAAGF;IACjB,MAAM,EAAEG,QAAQ,EAAEC,KAAK,EAAE,GAAGb,SAAiB;QAAEW;IAAK;IACpD,MAAM,EAAEE,OAAOC,cAAc,EAAE,GAAGd,SAAiB;QAAEW,MAAM;IAAiB;IAC5E,MAAM,EAAEI,KAAK,EAAE,GAAGd;IAClB,MAAM,EAAEe,eAAe,EAAE,GAAGlB;IAC5B,MAAM,EAAEmB,UAAU,EAAE,GAAGX;IACvB,MAAM,CAACY,gBAAgBC,kBAAkB,GA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":"index.d.ts","sourceRoot":"","sources":["../../../src/components/WhereField/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EA6D9B,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useDocumentInfo, useField, useListQuery, useSelection } from '@payloadcms/ui';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import './index.scss';
|
|
5
|
+
export const WhereField = ()=>{
|
|
6
|
+
const { setValue: setSelectionToUseValue, value: selectionToUseValue } = useField({
|
|
7
|
+
path: 'selectionToUse'
|
|
8
|
+
});
|
|
9
|
+
const { setValue } = useField({
|
|
10
|
+
path: 'where'
|
|
11
|
+
});
|
|
12
|
+
const { selectAll, selected } = useSelection();
|
|
13
|
+
const { query } = useListQuery();
|
|
14
|
+
const { id } = useDocumentInfo();
|
|
15
|
+
// setValue based on selectionToUseValue
|
|
16
|
+
useEffect(()=>{
|
|
17
|
+
if (id) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (selectionToUseValue === 'currentFilters' && query && query?.where) {
|
|
21
|
+
setValue(query.where);
|
|
22
|
+
}
|
|
23
|
+
if (selectionToUseValue === 'currentSelection' && selected) {
|
|
24
|
+
const ids = [];
|
|
25
|
+
for (const [key, value] of selected){
|
|
26
|
+
if (value) {
|
|
27
|
+
ids.push(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
setValue({
|
|
31
|
+
id: {
|
|
32
|
+
in: ids
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (selectionToUseValue === 'all' && selected) {
|
|
37
|
+
setValue({});
|
|
38
|
+
}
|
|
39
|
+
// Selected set a where query with IDs
|
|
40
|
+
}, [
|
|
41
|
+
id,
|
|
42
|
+
selectionToUseValue,
|
|
43
|
+
query,
|
|
44
|
+
selected,
|
|
45
|
+
setValue
|
|
46
|
+
]);
|
|
47
|
+
// handles default value of selectionToUse
|
|
48
|
+
useEffect(()=>{
|
|
49
|
+
if (id) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let defaultSelection = 'all';
|
|
53
|
+
if ([
|
|
54
|
+
'allInPage',
|
|
55
|
+
'some'
|
|
56
|
+
].includes(selectAll)) {
|
|
57
|
+
defaultSelection = 'currentSelection';
|
|
58
|
+
}
|
|
59
|
+
if (defaultSelection === 'all' && query?.where) {
|
|
60
|
+
defaultSelection = 'currentFilters';
|
|
61
|
+
}
|
|
62
|
+
setSelectionToUseValue(defaultSelection);
|
|
63
|
+
}, [
|
|
64
|
+
id,
|
|
65
|
+
query,
|
|
66
|
+
selectAll,
|
|
67
|
+
setSelectionToUseValue
|
|
68
|
+
]);
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/WhereField/index.tsx"],"sourcesContent":["'use client'\n\nimport type React from 'react'\n\nimport { useDocumentInfo, useField, useListQuery, useSelection } from '@payloadcms/ui'\nimport { useEffect } from 'react'\n\nimport './index.scss'\n\nexport const WhereField: React.FC = () => {\n const { setValue: setSelectionToUseValue, value: selectionToUseValue } = useField({\n path: 'selectionToUse',\n })\n const { setValue } = useField({ path: 'where' })\n const { selectAll, selected } = useSelection()\n const { query } = useListQuery()\n const { id } = useDocumentInfo()\n\n // setValue based on selectionToUseValue\n useEffect(() => {\n if (id) {\n return\n }\n\n if (selectionToUseValue === 'currentFilters' && query && query?.where) {\n setValue(query.where)\n }\n\n if (selectionToUseValue === 'currentSelection' && selected) {\n const ids = []\n\n for (const [key, value] of selected) {\n if (value) {\n ids.push(key)\n }\n }\n\n setValue({\n id: {\n in: ids,\n },\n })\n }\n\n if (selectionToUseValue === 'all' && selected) {\n setValue({})\n }\n\n // Selected set a where query with IDs\n }, [id, selectionToUseValue, query, selected, setValue])\n\n // handles default value of selectionToUse\n useEffect(() => {\n if (id) {\n return\n }\n let defaultSelection: 'all' | 'currentFilters' | 'currentSelection' = 'all'\n\n if (['allInPage', 'some'].includes(selectAll)) {\n defaultSelection = 'currentSelection'\n }\n\n if (defaultSelection === 'all' && query?.where) {\n defaultSelection = 'currentFilters'\n }\n\n setSelectionToUseValue(defaultSelection)\n }, [id, query, selectAll, setSelectionToUseValue])\n\n return null\n}\n"],"names":["useDocumentInfo","useField","useListQuery","useSelection","useEffect","WhereField","setValue","setSelectionToUseValue","value","selectionToUseValue","path","selectAll","selected","query","id","where","ids","key","push","in","defaultSelection","includes"],"mappings":"AAAA;AAIA,SAASA,eAAe,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,QAAQ,iBAAgB;AACtF,SAASC,SAAS,QAAQ,QAAO;AAEjC,OAAO,eAAc;AAErB,OAAO,MAAMC,aAAuB;IAClC,MAAM,EAAEC,UAAUC,sBAAsB,EAAEC,OAAOC,mBAAmB,EAAE,GAAGR,SAAS;QAChFS,MAAM;IACR;IACA,MAAM,EAAEJ,QAAQ,EAAE,GAAGL,SAAS;QAAES,MAAM;IAAQ;IAC9C,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAE,GAAGT;IAChC,MAAM,EAAEU,KAAK,EAAE,GAAGX;IAClB,MAAM,EAAEY,EAAE,EAAE,GAAGd;IAEf,wCAAwC;IACxCI,UAAU;QACR,IAAIU,IAAI;YACN;QACF;QAEA,IAAIL,wBAAwB,oBAAoBI,SAASA,OAAOE,OAAO;YACrET,SAASO,MAAME,KAAK;QACtB;QAEA,IAAIN,wBAAwB,sBAAsBG,UAAU;YAC1D,MAAMI,MAAM,EAAE;YAEd,KAAK,MAAM,CAACC,KAAKT,MAAM,IAAII,SAAU;gBACnC,IAAIJ,OAAO;oBACTQ,IAAIE,IAAI,CAACD;gBACX;YACF;YAEAX,SAAS;gBACPQ,IAAI;oBACFK,IAAIH;gBACN;YACF;QACF;QAEA,IAAIP,wBAAwB,SAASG,UAAU;YAC7CN,SAAS,CAAC;QACZ;IAEA,sCAAsC;IACxC,GAAG;QAACQ;QAAIL;QAAqBI;QAAOD;QAAUN;KAAS;IAEvD,0CAA0C;IAC1CF,UAAU;QACR,IAAIU,IAAI;YACN;QACF;QACA,IAAIM,mBAAkE;QAEtE,IAAI;YAAC;YAAa;SAAO,CAACC,QAAQ,CAACV,YAAY;YAC7CS,mBAAmB;QACrB;QAEA,IAAIA,qBAAqB,SAASP,OAAOE,OAAO;YAC9CK,mBAAmB;QACrB;QAEAb,uBAAuBa;IACzB,GAAG;QAACN;QAAID;QAAOF;QAAWJ;KAAuB;IAEjD,OAAO;AACT,EAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PayloadRequest, Sort, User, Where } from 'payload';
|
|
2
|
+
type Export = {
|
|
3
|
+
collectionSlug: string;
|
|
4
|
+
exportsCollection: string;
|
|
5
|
+
fields?: string[];
|
|
6
|
+
format: 'csv' | 'json';
|
|
7
|
+
globals?: string[];
|
|
8
|
+
id: number | string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
slug: string;
|
|
12
|
+
sort: Sort;
|
|
13
|
+
user: string;
|
|
14
|
+
userCollection: string;
|
|
15
|
+
where?: Where;
|
|
16
|
+
};
|
|
17
|
+
export type CreateExportArgs = {
|
|
18
|
+
input: Export;
|
|
19
|
+
req: PayloadRequest;
|
|
20
|
+
user?: User;
|
|
21
|
+
};
|
|
22
|
+
export declare const createExport: (args: CreateExportArgs) => Promise<void>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=createExport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAU/E,KAAK,MAAM,GAAG;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAA;AAED,eAAO,MAAM,YAAY,SAAgB,gBAAgB,kBAwFxD,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { stringify } from 'csv-stringify/sync';
|
|
3
|
+
import { APIError } from 'payload';
|
|
4
|
+
import { flattenObject } from './flattenObject.js';
|
|
5
|
+
import { getFilename } from './getFilename.js';
|
|
6
|
+
import { getSelect } from './getSelect.js';
|
|
7
|
+
export const createExport = async (args)=>{
|
|
8
|
+
const { input: { id, name: nameArg, collectionSlug, exportsCollection, fields, format, locale: localeInput, sort, user, where }, req: { locale: localeArg, payload }, req } = args;
|
|
9
|
+
const locale = localeInput ?? localeArg;
|
|
10
|
+
const collectionConfig = payload.config.collections.find(({ slug })=>slug === collectionSlug);
|
|
11
|
+
if (!collectionConfig) {
|
|
12
|
+
throw new APIError(`Collection with slug ${collectionSlug} not found`);
|
|
13
|
+
}
|
|
14
|
+
const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`;
|
|
15
|
+
const findArgs = {
|
|
16
|
+
collection: collectionSlug,
|
|
17
|
+
depth: 0,
|
|
18
|
+
limit: 100,
|
|
19
|
+
locale,
|
|
20
|
+
overrideAccess: false,
|
|
21
|
+
page: 0,
|
|
22
|
+
select: fields ? getSelect(fields) : undefined,
|
|
23
|
+
sort,
|
|
24
|
+
user,
|
|
25
|
+
where
|
|
26
|
+
};
|
|
27
|
+
let result = {
|
|
28
|
+
hasNextPage: true
|
|
29
|
+
};
|
|
30
|
+
const outputData = [];
|
|
31
|
+
let isFirstBatch = true;
|
|
32
|
+
while(result.hasNextPage){
|
|
33
|
+
findArgs.page = findArgs.page + 1;
|
|
34
|
+
result = await payload.find(findArgs);
|
|
35
|
+
if (format === 'csv') {
|
|
36
|
+
const csvInput = result.docs.map((doc)=>flattenObject(doc));
|
|
37
|
+
const csvString = stringify(csvInput, {
|
|
38
|
+
header: isFirstBatch
|
|
39
|
+
});
|
|
40
|
+
outputData.push(csvString);
|
|
41
|
+
isFirstBatch = false;
|
|
42
|
+
}
|
|
43
|
+
if (format === 'json') {
|
|
44
|
+
const jsonInput = result.docs.map((doc)=>JSON.stringify(doc));
|
|
45
|
+
outputData.push(jsonInput.join(',\n'));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''));
|
|
49
|
+
// when `disableJobsQueue` is true, the export is created synchronously in a beforeOperation hook
|
|
50
|
+
if (!id) {
|
|
51
|
+
req.file = {
|
|
52
|
+
name,
|
|
53
|
+
data: buffer,
|
|
54
|
+
mimetype: format === 'json' ? 'application/json' : `text/${format}`,
|
|
55
|
+
size: buffer.length
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
await req.payload.update({
|
|
59
|
+
id,
|
|
60
|
+
collection: exportsCollection,
|
|
61
|
+
data: {},
|
|
62
|
+
file: {
|
|
63
|
+
name,
|
|
64
|
+
data: buffer,
|
|
65
|
+
mimetype: format === 'json' ? 'application/json' : `text/${format}`,
|
|
66
|
+
size: buffer.length
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=createExport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["import type { PaginatedDocs, PayloadRequest, Sort, User, Where } from 'payload'\n\nimport { Buffer } from 'buffer'\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\ntype Export = {\n collectionSlug: string\n exportsCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n locale?: string\n name: string\n slug: string\n sort: Sort\n user: string\n userCollection: string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n input: Export\n req: PayloadRequest\n user?: User\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n input: {\n id,\n name: nameArg,\n collectionSlug,\n exportsCollection,\n fields,\n format,\n locale: localeInput,\n sort,\n user,\n where,\n },\n req: { locale: localeArg, payload },\n req,\n } = args\n\n const locale = localeInput ?? localeArg\n\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found`)\n }\n const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`\n\n const findArgs = {\n collection: collectionSlug,\n depth: 0,\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select: fields ? getSelect(fields) : undefined,\n sort,\n user,\n where,\n }\n\n let result: PaginatedDocs = { hasNextPage: true } as PaginatedDocs\n const outputData: string[] = []\n\n let isFirstBatch = true\n\n while (result.hasNextPage) {\n findArgs.page = findArgs.page + 1\n result = await payload.find(findArgs)\n\n if (format === 'csv') {\n const csvInput = result.docs.map((doc) => flattenObject(doc))\n\n const csvString = stringify(csvInput, {\n header: isFirstBatch, // Only include header in the first batch\n })\n\n outputData.push(csvString)\n isFirstBatch = false\n }\n\n if (format === 'json') {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n\n // when `disableJobsQueue` is true, the export is created synchronously in a beforeOperation hook\n if (!id) {\n req.file = {\n name,\n data: buffer,\n mimetype: format === 'json' ? 'application/json' : `text/${format}`,\n size: buffer.length,\n }\n } else {\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: format === 'json' ? 'application/json' : `text/${format}`,\n size: buffer.length,\n },\n })\n }\n}\n"],"names":["Buffer","stringify","APIError","flattenObject","getFilename","getSelect","createExport","args","input","id","name","nameArg","collectionSlug","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","collectionConfig","config","collections","find","slug","findArgs","collection","depth","limit","overrideAccess","page","select","undefined","result","hasNextPage","outputData","isFirstBatch","csvInput","docs","map","doc","csvString","header","push","jsonInput","JSON","join","buffer","from","file","data","mimetype","size","length","update"],"mappings":"AAEA,SAASA,MAAM,QAAQ,SAAQ;AAC/B,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAElC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,SAAS,QAAQ,iBAAgB;AAwB1C,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,OAAO,EACLC,EAAE,EACFC,MAAMC,OAAO,EACbC,cAAc,EACdC,iBAAiB,EACjBC,MAAM,EACNC,MAAM,EACNC,QAAQC,WAAW,EACnBC,IAAI,EACJC,IAAI,EACJC,KAAK,EACN,EACDC,KAAK,EA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CAAC,CAAC,GAAGX,WAAWW,IAAI,CAAC;IAE7F,iGAAiG;IACjG,IAAI,CAACzC,IAAI;QACPY,IAAIgC,IAAI,GAAG;YACT3C;YACA4C,MAAMH;YACNI,UAAUxC,WAAW,SAAS,qBAAqB,CAAC,KAAK,EAAEA,QAAQ;YACnEyC,MAAML,OAAOM,MAAM;QACrB;IACF,OAAO;QACL,MAAMpC,IAAIE,OAAO,CAACmC,MAAM,CAAC;YACvBjD;YACAqB,YAAYjB;YACZyC,MAAM,CAAC;YACPD,MAAM;gBACJ3C;gBACA4C,MAAMH;gBACNI,UAAUxC,WAAW,SAAS,qBAAqB,CAAC,KAAK,EAAEA,QAAQ;gBACnEyC,MAAML,OAAOM,MAAM;YACrB;QACF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAAS,GAAG,WAAU,MAAM,KAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAsBnF,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const flattenObject = (obj, prefix = '')=>{
|
|
2
|
+
const result = {};
|
|
3
|
+
Object.entries(obj).forEach(([key, value])=>{
|
|
4
|
+
const newKey = prefix ? `${prefix}_${key}` : key;
|
|
5
|
+
if (Array.isArray(value)) {
|
|
6
|
+
value.forEach((item, index)=>{
|
|
7
|
+
if (typeof item === 'object' && item !== null) {
|
|
8
|
+
Object.assign(result, flattenObject(item, `${newKey}_${index}`));
|
|
9
|
+
} else {
|
|
10
|
+
result[`${newKey}_${index}`] = item;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
14
|
+
Object.assign(result, flattenObject(value, newKey));
|
|
15
|
+
} else {
|
|
16
|
+
result[newKey] = value;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=flattenObject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["export const flattenObject = (obj: any, prefix: string = ''): Record<string, unknown> => {\n const result: Record<string, unknown> = {}\n\n Object.entries(obj).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n Object.assign(result, flattenObject(item, `${newKey}_${index}`))\n } else {\n result[`${newKey}_${index}`] = item\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n Object.assign(result, flattenObject(value, newKey))\n } else {\n result[newKey] = value\n }\n })\n\n return result\n}\n"],"names":["flattenObject","obj","prefix","result","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","assign"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,CAACC,KAAUC,SAAiB,EAAE;IACzD,MAAMC,SAAkC,CAAC;IAEzCC,OAAOC,OAAO,CAACJ,KAAKK,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;QACvC,MAAMC,SAASP,SAAS,GAAGA,OAAO,CAAC,EAAEK,KAAK,GAAGA;QAE7C,IAAIG,MAAMC,OAAO,CAACH,QAAQ;YACxBA,MAAMF,OAAO,CAAC,CAACM,MAAMC;gBACnB,IAAI,OAAOD,SAAS,YAAYA,SAAS,MAAM;oBAC7CR,OAAOU,MAAM,CAACX,QAAQH,cAAcY,MAAM,GAAGH,OAAO,CAAC,EAAEI,OAAO;gBAChE,OAAO;oBACLV,MAAM,CAAC,GAAGM,OAAO,CAAC,EAAEI,OAAO,CAAC,GAAGD;gBACjC;YACF;QACF,OAAO,IAAI,OAAOJ,UAAU,YAAYA,UAAU,MAAM;YACtDJ,OAAOU,MAAM,CAACX,QAAQH,cAAcQ,OAAOC;QAC7C,OAAO;YACLN,MAAM,CAACM,OAAO,GAAGD;QACnB;IACF;IAEA,OAAOL;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAQ,MAAM,SAAS,CAAA;AAOxD,eAAO,MAAM,6BAA6B,WAAY,MAAM,KAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CA+CrF,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createExport } from './createExport.js';
|
|
2
|
+
import { getFields } from './getFields.js';
|
|
3
|
+
export const getCreateCollectionExportTask = (config)=>{
|
|
4
|
+
const inputSchema = getFields(config).concat({
|
|
5
|
+
name: 'user',
|
|
6
|
+
type: 'text'
|
|
7
|
+
}, {
|
|
8
|
+
name: 'userCollection',
|
|
9
|
+
type: 'text'
|
|
10
|
+
}, {
|
|
11
|
+
name: 'exportsCollection',
|
|
12
|
+
type: 'text'
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
// @ts-expect-error plugin tasks cannot have predefined type slug
|
|
16
|
+
slug: 'createCollectionExport',
|
|
17
|
+
handler: async ({ input, req })=>{
|
|
18
|
+
let user;
|
|
19
|
+
if (input.userCollection && input.user) {
|
|
20
|
+
user = await req.payload.findByID({
|
|
21
|
+
id: input.user,
|
|
22
|
+
collection: input.userCollection
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (!user) {
|
|
26
|
+
throw new Error('User not found');
|
|
27
|
+
}
|
|
28
|
+
await createExport({
|
|
29
|
+
input,
|
|
30
|
+
req,
|
|
31
|
+
user
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
success: true
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
inputSchema,
|
|
38
|
+
outputSchema: [
|
|
39
|
+
{
|
|
40
|
+
name: 'success',
|
|
41
|
+
type: 'checkbox'
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=getCreateExportCollectionTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, TaskHandler, User } from 'payload'\n\nimport type { CreateExportArgs } from './createExport.js'\n\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\n\nexport const getCreateCollectionExportTask = (config: Config): TaskHandler<any, string> => {\n const inputSchema = getFields(config).concat(\n {\n name: 'user',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'exportsCollection',\n type: 'text',\n },\n )\n\n return {\n // @ts-expect-error plugin tasks cannot have predefined type slug\n slug: 'createCollectionExport',\n handler: async ({ input, req }: CreateExportArgs) => {\n let user: undefined | User\n\n if (input.userCollection && input.user) {\n user = (await req.payload.findByID({\n id: input.user,\n collection: input.userCollection,\n })) as User\n }\n\n if (!user) {\n throw new Error('User not found')\n }\n\n await createExport({ input, req, user })\n\n return {\n success: true,\n }\n },\n inputSchema,\n outputSchema: [\n {\n name: 'success',\n type: 'checkbox',\n },\n ],\n }\n}\n"],"names":["createExport","getFields","getCreateCollectionExportTask","config","inputSchema","concat","name","type","slug","handler","input","req","user","userCollection","payload","findByID","id","collection","Error","success","outputSchema"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,OAAO,MAAMC,gCAAgC,CAACC;IAC5C,MAAMC,cAAcH,UAAUE,QAAQE,MAAM,CAC1C;QACEC,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR,GACA;QACED,MAAM;QACNC,MAAM;IACR;IAGF,OAAO;QACL,iEAAiE;QACjEC,MAAM;QACNC,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAoB;YAC9C,IAAIC;YAEJ,IAAIF,MAAMG,cAAc,IAAIH,MAAME,IAAI,EAAE;gBACtCA,OAAQ,MAAMD,IAAIG,OAAO,CAACC,QAAQ,CAAC;oBACjCC,IAAIN,MAAME,IAAI;oBACdK,YAAYP,MAAMG,cAAc;gBAClC;YACF;YAEA,IAAI,CAACD,MAAM;gBACT,MAAM,IAAIM,MAAM;YAClB;YAEA,MAAMlB,aAAa;gBAAEU;gBAAOC;gBAAKC;YAAK;YAEtC,OAAO;gBACLO,SAAS;YACX;QACF;QACAf;QACAgB,cAAc;YACZ;gBACEd,MAAM;gBACNC,MAAM;YACR;SACD;IACH;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAe,MAAM,SAAS,CAAA;AAIzD,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,KAAK,EAwL/C,CAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { getFilename } from './getFilename.js';
|
|
2
|
+
export const getFields = (config)=>{
|
|
3
|
+
let localeField;
|
|
4
|
+
if (config.localization) {
|
|
5
|
+
localeField = {
|
|
6
|
+
name: 'locale',
|
|
7
|
+
type: 'select',
|
|
8
|
+
admin: {
|
|
9
|
+
width: '33%'
|
|
10
|
+
},
|
|
11
|
+
defaultValue: 'all',
|
|
12
|
+
label: 'Locale',
|
|
13
|
+
options: [
|
|
14
|
+
{
|
|
15
|
+
label: 'All Locales',
|
|
16
|
+
value: 'all'
|
|
17
|
+
},
|
|
18
|
+
...config.localization.locales.map((locale)=>({
|
|
19
|
+
label: typeof locale === 'string' ? locale : locale.label,
|
|
20
|
+
value: typeof locale === 'string' ? locale : locale.code
|
|
21
|
+
}))
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
type: 'collapsible',
|
|
28
|
+
fields: [
|
|
29
|
+
{
|
|
30
|
+
name: 'name',
|
|
31
|
+
type: 'text',
|
|
32
|
+
defaultValue: ()=>getFilename(),
|
|
33
|
+
label: 'File Name'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'row',
|
|
37
|
+
fields: [
|
|
38
|
+
{
|
|
39
|
+
name: 'format',
|
|
40
|
+
type: 'select',
|
|
41
|
+
admin: {
|
|
42
|
+
width: '33%'
|
|
43
|
+
},
|
|
44
|
+
defaultValue: 'csv',
|
|
45
|
+
label: 'Export Format',
|
|
46
|
+
options: [
|
|
47
|
+
{
|
|
48
|
+
label: 'CSV',
|
|
49
|
+
value: 'csv'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: 'JSON',
|
|
53
|
+
value: 'json'
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
required: true
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'limit',
|
|
60
|
+
type: 'number',
|
|
61
|
+
admin: {
|
|
62
|
+
placeholder: 'No limit',
|
|
63
|
+
width: '33%'
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'sort',
|
|
68
|
+
type: 'text',
|
|
69
|
+
admin: {
|
|
70
|
+
components: {
|
|
71
|
+
Field: '@payloadcms/plugin-import-export/rsc#SortBy'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'row',
|
|
79
|
+
fields: [
|
|
80
|
+
...localeField ? [
|
|
81
|
+
localeField
|
|
82
|
+
] : [],
|
|
83
|
+
{
|
|
84
|
+
name: 'drafts',
|
|
85
|
+
type: 'select',
|
|
86
|
+
admin: {
|
|
87
|
+
condition: (data)=>{
|
|
88
|
+
const collectionConfig = (config.collections ?? []).find((collection)=>collection.slug === data.collectionSlug);
|
|
89
|
+
return Boolean(typeof collectionConfig?.versions === 'object' && collectionConfig?.versions?.drafts);
|
|
90
|
+
},
|
|
91
|
+
width: '33%'
|
|
92
|
+
},
|
|
93
|
+
defaultValue: 'true',
|
|
94
|
+
label: 'Drafts',
|
|
95
|
+
options: [
|
|
96
|
+
{
|
|
97
|
+
label: 'True',
|
|
98
|
+
value: 'true'
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
label: 'False',
|
|
102
|
+
value: 'false'
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
// virtual field for the UI component to modify the hidden `where` field
|
|
110
|
+
name: 'selectionToUse',
|
|
111
|
+
type: 'radio',
|
|
112
|
+
defaultValue: 'all',
|
|
113
|
+
options: [
|
|
114
|
+
{
|
|
115
|
+
label: 'Use current selection',
|
|
116
|
+
value: 'currentSelection'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
label: 'Use current filters',
|
|
120
|
+
value: 'currentFilters'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
label: 'Use all documents',
|
|
124
|
+
value: 'all'
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
virtual: true
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'fields',
|
|
131
|
+
type: 'text',
|
|
132
|
+
admin: {
|
|
133
|
+
components: {
|
|
134
|
+
Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport'
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
hasMany: true
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'collectionSlug',
|
|
141
|
+
type: 'text',
|
|
142
|
+
admin: {
|
|
143
|
+
components: {
|
|
144
|
+
Field: '@payloadcms/plugin-import-export/rsc#CollectionField'
|
|
145
|
+
},
|
|
146
|
+
hidden: true
|
|
147
|
+
},
|
|
148
|
+
required: true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: 'where',
|
|
152
|
+
type: 'json',
|
|
153
|
+
admin: {
|
|
154
|
+
components: {
|
|
155
|
+
Field: '@payloadcms/plugin-import-export/rsc#WhereField'
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
defaultValue: {}
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
label: 'Export Options'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'preview',
|
|
165
|
+
type: 'ui',
|
|
166
|
+
admin: {
|
|
167
|
+
components: {
|
|
168
|
+
Field: '@payloadcms/plugin-import-export/rsc#Preview'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=getFields.js.map
|