@payloadcms/plugin-import-export 3.47.0-canary.1 → 3.47.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/FieldsToExport/index.d.ts.map +1 -1
- package/dist/components/FieldsToExport/index.js +13 -28
- package/dist/components/FieldsToExport/index.js.map +1 -1
- package/dist/components/SelectionToUseField/index.d.ts +3 -0
- package/dist/components/SelectionToUseField/index.d.ts.map +1 -0
- package/dist/components/SelectionToUseField/index.js +128 -0
- package/dist/components/SelectionToUseField/index.js.map +1 -0
- package/dist/components/SortBy/index.js +3 -2
- package/dist/components/SortBy/index.js.map +1 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +1 -2
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/flattenObject.d.ts.map +1 -1
- package/dist/export/flattenObject.js +48 -30
- package/dist/export/flattenObject.js.map +1 -1
- package/dist/export/getCustomFieldFunctions.d.ts +2 -3
- package/dist/export/getCustomFieldFunctions.d.ts.map +1 -1
- package/dist/export/getCustomFieldFunctions.js +3 -5
- package/dist/export/getCustomFieldFunctions.js.map +1 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +15 -10
- package/dist/export/getFields.js.map +1 -1
- package/dist/exports/rsc.d.ts +1 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +1 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.js +16 -5
- package/dist/utilities/getFlattenedFieldKeys.js.map +1 -1
- package/package.json +7 -7
- package/dist/components/WhereField/index.d.ts +0 -4
- package/dist/components/WhereField/index.d.ts.map +0 -1
- package/dist/components/WhereField/index.js +0 -72
- package/dist/components/WhereField/index.js.map +0 -1
- package/dist/components/WhereField/index.scss +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyB,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAkBhF,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FieldsToExport/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyB,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAkBhF,eAAO,MAAM,cAAc,EAAE,0BAyE5B,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { FieldLabel, ReactSelect, useConfig, useDocumentInfo, useField, usePreferences } from '@payloadcms/ui';
|
|
4
|
-
import React, { useEffect
|
|
4
|
+
import React, { useEffect } from 'react';
|
|
5
5
|
import { useImportExport } from '../ImportExportProvider/index.js';
|
|
6
6
|
import { reduceFields } from './reduceFields.js';
|
|
7
7
|
const baseClass = 'fields-to-export';
|
|
@@ -14,36 +14,12 @@ export const FieldsToExport = (props)=>{
|
|
|
14
14
|
const { getEntityConfig } = useConfig();
|
|
15
15
|
const { collection } = useImportExport();
|
|
16
16
|
const { getPreference } = usePreferences();
|
|
17
|
-
const [displayedValue, setDisplayedValue] = useState([]);
|
|
18
17
|
const collectionConfig = getEntityConfig({
|
|
19
18
|
collectionSlug: collectionSlug ?? collection
|
|
20
19
|
});
|
|
21
20
|
const fieldOptions = reduceFields({
|
|
22
21
|
fields: collectionConfig?.fields
|
|
23
22
|
});
|
|
24
|
-
useEffect(()=>{
|
|
25
|
-
if (value && value.length > 0) {
|
|
26
|
-
setDisplayedValue((prevDisplayedValue)=>{
|
|
27
|
-
if (prevDisplayedValue.length > 0) {
|
|
28
|
-
return prevDisplayedValue;
|
|
29
|
-
} // Prevent unnecessary updates
|
|
30
|
-
return value.map((field)=>{
|
|
31
|
-
const match = fieldOptions.find((option)=>option.value === field);
|
|
32
|
-
return match ? {
|
|
33
|
-
...match,
|
|
34
|
-
id: field
|
|
35
|
-
} : {
|
|
36
|
-
id: field,
|
|
37
|
-
label: field,
|
|
38
|
-
value: field
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}, [
|
|
44
|
-
value,
|
|
45
|
-
fieldOptions
|
|
46
|
-
]);
|
|
47
23
|
useEffect(()=>{
|
|
48
24
|
if (id || !collectionSlug) {
|
|
49
25
|
return;
|
|
@@ -67,9 +43,8 @@ export const FieldsToExport = (props)=>{
|
|
|
67
43
|
setValue([]);
|
|
68
44
|
return;
|
|
69
45
|
}
|
|
70
|
-
const updatedValue = options
|
|
46
|
+
const updatedValue = options.map((option)=>typeof option === 'object' ? option.value : option);
|
|
71
47
|
setValue(updatedValue);
|
|
72
|
-
setDisplayedValue(options);
|
|
73
48
|
};
|
|
74
49
|
return /*#__PURE__*/ _jsxs("div", {
|
|
75
50
|
className: baseClass,
|
|
@@ -89,7 +64,17 @@ export const FieldsToExport = (props)=>{
|
|
|
89
64
|
// @ts-expect-error react select option
|
|
90
65
|
onChange: onChange,
|
|
91
66
|
options: fieldOptions,
|
|
92
|
-
value:
|
|
67
|
+
value: Array.isArray(value) ? value.map((val)=>{
|
|
68
|
+
const match = fieldOptions.find((opt)=>opt.value === val);
|
|
69
|
+
return match ? {
|
|
70
|
+
...match,
|
|
71
|
+
id: val
|
|
72
|
+
} : {
|
|
73
|
+
id: val,
|
|
74
|
+
label: val,
|
|
75
|
+
value: val
|
|
76
|
+
};
|
|
77
|
+
}) : []
|
|
93
78
|
})
|
|
94
79
|
]
|
|
95
80
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/FieldsToExport/index.tsx"],"sourcesContent":["'use client'\n\nimport type { CollectionPreferences, SelectFieldClientComponent } from 'payload'\nimport type { ReactNode } from 'react'\n\nimport {\n FieldLabel,\n ReactSelect,\n useConfig,\n useDocumentInfo,\n useField,\n usePreferences,\n} from '@payloadcms/ui'\nimport React, { useEffect
|
|
1
|
+
{"version":3,"sources":["../../../src/components/FieldsToExport/index.tsx"],"sourcesContent":["'use client'\n\nimport type { CollectionPreferences, SelectFieldClientComponent } from 'payload'\nimport type { ReactNode } from 'react'\n\nimport {\n FieldLabel,\n ReactSelect,\n useConfig,\n useDocumentInfo,\n useField,\n usePreferences,\n} from '@payloadcms/ui'\nimport React, { useEffect } from 'react'\n\nimport { useImportExport } from '../ImportExportProvider/index.js'\nimport { reduceFields } from './reduceFields.js'\n\nconst baseClass = 'fields-to-export'\n\nexport const FieldsToExport: SelectFieldClientComponent = (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 { getPreference } = usePreferences()\n\n const collectionConfig = getEntityConfig({ collectionSlug: collectionSlug ?? collection })\n const fieldOptions = reduceFields({ fields: collectionConfig?.fields })\n\n useEffect(() => {\n if (id || !collectionSlug) {\n return\n }\n\n const doAsync = async () => {\n const currentPreferences = await getPreference<{\n columns: CollectionPreferences['columns']\n }>(`collection-${collectionSlug}`)\n\n const columns = currentPreferences?.columns?.filter((a) => a.active).map((b) => b.accessor)\n setValue(columns ?? collectionConfig?.admin?.defaultColumns ?? [])\n }\n\n void doAsync()\n }, [\n getPreference,\n collection,\n setValue,\n collectionSlug,\n id,\n collectionConfig?.admin?.defaultColumns,\n ])\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","usePreferences","React","useEffect","useImportExport","reduceFields","baseClass","FieldsToExport","props","id","setValue","value","collectionSlug","path","getEntityConfig","collection","getPreference","collectionConfig","fieldOptions","fields","doAsync","currentPreferences","columns","filter","a","active","map","b","accessor","admin","defaultColumns","onChange","options","updatedValue","option","div","className","label","field","disabled","readOnly","getOptionValue","String","inputId","replace","isClearable","isMulti","isSortable","Array","isArray","val","match","find","opt"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAExC,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,MAAMC,YAAY;AAElB,OAAO,MAAMC,iBAA6C,CAACC;IACzD,MAAM,EAAEC,EAAE,EAAE,GAAGV;IACf,MAAM,EAAEW,QAAQ,EAAEC,KAAK,EAAE,GAAGX;IAC5B,MAAM,EAAEW,OAAOC,cAAc,EAAE,GAAGZ,SAAiB;QAAEa,MAAM;IAAiB;IAC5E,MAAM,EAAEC,eAAe,EAAE,GAAGhB;IAC5B,MAAM,EAAEiB,UAAU,EAAE,GAAGX;IACvB,MAAM,EAAEY,aAAa,EAAE,GAAGf;IAE1B,MAAMgB,mBAAmBH,gBAAgB;QAAEF,gBAAgBA,kBAAkBG;IAAW;IACxF,MAAMG,eAAeb,aAAa;QAAEc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AI,IAAI;wBAAEzC,IAAIyC;wBAAKb,OAAOa;wBAAKvC,OAAOuC;oBAAI;gBAC3E,KACA,EAAE;;;;AAKhB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionToUseField/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAkBjD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAmGvC,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { RadioGroupField, useDocumentInfo, useField, useListQuery, useSelection, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import React, { useEffect, useMemo } from 'react';
|
|
5
|
+
const isWhereEmpty = (where)=>{
|
|
6
|
+
if (!where || typeof where !== 'object') {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
// Flatten one level of OR/AND wrappers
|
|
10
|
+
if (Array.isArray(where.and)) {
|
|
11
|
+
return where.and.length === 0;
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(where.or)) {
|
|
14
|
+
return where.or.length === 0;
|
|
15
|
+
}
|
|
16
|
+
return Object.keys(where).length === 0;
|
|
17
|
+
};
|
|
18
|
+
export const SelectionToUseField = ()=>{
|
|
19
|
+
const { id } = useDocumentInfo();
|
|
20
|
+
const { query } = useListQuery();
|
|
21
|
+
const { selectAll, selected } = useSelection();
|
|
22
|
+
const { t } = useTranslation();
|
|
23
|
+
const { setValue: setSelectionToUseValue, value: selectionToUseValue } = useField({
|
|
24
|
+
path: 'selectionToUse'
|
|
25
|
+
});
|
|
26
|
+
const { setValue: setWhere } = useField({
|
|
27
|
+
path: 'where'
|
|
28
|
+
});
|
|
29
|
+
const hasMeaningfulFilters = query?.where && !isWhereEmpty(query.where);
|
|
30
|
+
const availableOptions = useMemo(()=>{
|
|
31
|
+
const options = [
|
|
32
|
+
{
|
|
33
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
34
|
+
label: t('plugin-import-export:selectionToUse-allDocuments'),
|
|
35
|
+
value: 'all'
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
if (hasMeaningfulFilters) {
|
|
39
|
+
options.unshift({
|
|
40
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
41
|
+
label: t('plugin-import-export:selectionToUse-currentFilters'),
|
|
42
|
+
value: 'currentFilters'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if ([
|
|
46
|
+
'allInPage',
|
|
47
|
+
'some'
|
|
48
|
+
].includes(selectAll)) {
|
|
49
|
+
options.unshift({
|
|
50
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
51
|
+
label: t('plugin-import-export:selectionToUse-currentSelection'),
|
|
52
|
+
value: 'currentSelection'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return options;
|
|
56
|
+
}, [
|
|
57
|
+
hasMeaningfulFilters,
|
|
58
|
+
selectAll,
|
|
59
|
+
t
|
|
60
|
+
]);
|
|
61
|
+
// Auto-set default
|
|
62
|
+
useEffect(()=>{
|
|
63
|
+
if (id) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let defaultSelection = 'all';
|
|
67
|
+
if ([
|
|
68
|
+
'allInPage',
|
|
69
|
+
'some'
|
|
70
|
+
].includes(selectAll)) {
|
|
71
|
+
defaultSelection = 'currentSelection';
|
|
72
|
+
} else if (query?.where) {
|
|
73
|
+
defaultSelection = 'currentFilters';
|
|
74
|
+
}
|
|
75
|
+
setSelectionToUseValue(defaultSelection);
|
|
76
|
+
}, [
|
|
77
|
+
id,
|
|
78
|
+
selectAll,
|
|
79
|
+
query?.where,
|
|
80
|
+
setSelectionToUseValue
|
|
81
|
+
]);
|
|
82
|
+
// Sync where clause with selected option
|
|
83
|
+
useEffect(()=>{
|
|
84
|
+
if (id) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (selectionToUseValue === 'currentFilters' && query?.where) {
|
|
88
|
+
setWhere(query.where);
|
|
89
|
+
} else if (selectionToUseValue === 'currentSelection' && selected) {
|
|
90
|
+
const ids = [
|
|
91
|
+
...selected.entries()
|
|
92
|
+
].filter(([_, isSelected])=>isSelected).map(([id])=>id);
|
|
93
|
+
setWhere({
|
|
94
|
+
id: {
|
|
95
|
+
in: ids
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
} else if (selectionToUseValue === 'all') {
|
|
99
|
+
setWhere({});
|
|
100
|
+
}
|
|
101
|
+
}, [
|
|
102
|
+
id,
|
|
103
|
+
selectionToUseValue,
|
|
104
|
+
query?.where,
|
|
105
|
+
selected,
|
|
106
|
+
setWhere
|
|
107
|
+
]);
|
|
108
|
+
// Hide component if no other options besides "all" are available
|
|
109
|
+
if (availableOptions.length <= 1) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return /*#__PURE__*/ _jsx(RadioGroupField, {
|
|
113
|
+
field: {
|
|
114
|
+
name: 'selectionToUse',
|
|
115
|
+
type: 'radio',
|
|
116
|
+
admin: {},
|
|
117
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
118
|
+
label: t('plugin-import-export:field-selectionToUse-label'),
|
|
119
|
+
options: availableOptions
|
|
120
|
+
},
|
|
121
|
+
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
122
|
+
label: t('plugin-import-export:field-selectionToUse-label'),
|
|
123
|
+
options: availableOptions,
|
|
124
|
+
path: "selectionToUse"
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SelectionToUseField/index.tsx"],"sourcesContent":["'use client'\n\nimport type { Where } from 'payload'\n\nimport {\n RadioGroupField,\n useDocumentInfo,\n useField,\n useListQuery,\n useSelection,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useEffect, useMemo } from 'react'\n\nconst isWhereEmpty = (where: Where): boolean => {\n if (!where || typeof where !== 'object') {\n return true\n }\n\n // Flatten one level of OR/AND wrappers\n if (Array.isArray(where.and)) {\n return where.and.length === 0\n }\n if (Array.isArray(where.or)) {\n return where.or.length === 0\n }\n\n return Object.keys(where).length === 0\n}\n\nexport const SelectionToUseField: React.FC = () => {\n const { id } = useDocumentInfo()\n const { query } = useListQuery()\n const { selectAll, selected } = useSelection()\n const { t } = useTranslation()\n\n const { setValue: setSelectionToUseValue, value: selectionToUseValue } = useField({\n path: 'selectionToUse',\n })\n\n const { setValue: setWhere } = useField({\n path: 'where',\n })\n\n const hasMeaningfulFilters = query?.where && !isWhereEmpty(query.where)\n\n const availableOptions = useMemo(() => {\n const options = [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ]\n\n if (hasMeaningfulFilters) {\n options.unshift({\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n })\n }\n\n if (['allInPage', 'some'].includes(selectAll)) {\n options.unshift({\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n })\n }\n\n return options\n }, [hasMeaningfulFilters, selectAll, t])\n\n // Auto-set default\n useEffect(() => {\n if (id) {\n return\n }\n\n let defaultSelection: 'all' | 'currentFilters' | 'currentSelection' = 'all'\n\n if (['allInPage', 'some'].includes(selectAll)) {\n defaultSelection = 'currentSelection'\n } else if (query?.where) {\n defaultSelection = 'currentFilters'\n }\n\n setSelectionToUseValue(defaultSelection)\n }, [id, selectAll, query?.where, setSelectionToUseValue])\n\n // Sync where clause with selected option\n useEffect(() => {\n if (id) {\n return\n }\n\n if (selectionToUseValue === 'currentFilters' && query?.where) {\n setWhere(query.where)\n } else if (selectionToUseValue === 'currentSelection' && selected) {\n const ids = [...selected.entries()].filter(([_, isSelected]) => isSelected).map(([id]) => id)\n\n setWhere({ id: { in: ids } })\n } else if (selectionToUseValue === 'all') {\n setWhere({})\n }\n }, [id, selectionToUseValue, query?.where, selected, setWhere])\n\n // Hide component if no other options besides \"all\" are available\n if (availableOptions.length <= 1) {\n return null\n }\n\n return (\n <RadioGroupField\n field={{\n name: 'selectionToUse',\n type: 'radio',\n admin: {},\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: t('plugin-import-export:field-selectionToUse-label'),\n options: availableOptions,\n }}\n // @ts-expect-error - this is not correctly typed in plugins right now\n label={t('plugin-import-export:field-selectionToUse-label')}\n options={availableOptions}\n path=\"selectionToUse\"\n />\n )\n}\n"],"names":["RadioGroupField","useDocumentInfo","useField","useListQuery","useSelection","useTranslation","React","useEffect","useMemo","isWhereEmpty","where","Array","isArray","and","length","or","Object","keys","SelectionToUseField","id","query","selectAll","selected","t","setValue","setSelectionToUseValue","value","selectionToUseValue","path","setWhere","hasMeaningfulFilters","availableOptions","options","label","unshift","includes","defaultSelection","ids","entries","filter","_","isSelected","map","in","field","name","type","admin"],"mappings":"AAAA;;AAIA,SACEA,eAAe,EACfC,eAAe,EACfC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,SAAS,EAAEC,OAAO,QAAQ,QAAO;AAEjD,MAAMC,eAAe,CAACC;IACpB,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAO;IACT;IAEA,uCAAuC;IACvC,IAAIC,MAAMC,OAAO,CAACF,MAAMG,GAAG,GAAG;QAC5B,OAAOH,MAAMG,GAAG,CAACC,MAAM,KAAK;IAC9B;IACA,IAAIH,MAAMC,OAAO,CAACF,MAAMK,EAAE,GAAG;QAC3B,OAAOL,MAAMK,EAAE,CAACD,MAAM,KAAK;IAC7B;IAEA,OAAOE,OAAOC,IAAI,CAACP,OAAOI,MAAM,KAAK;AACv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OV,OAAO;YAC5DmB,SAAST,MAAMV,KAAK;QACtB,OAAO,IAAIiB,wBAAwB,sBAAsBL,UAAU;YACjE,MAAMe,MAAM;mBAAIf,SAASgB,OAAO;aAAG,CAACC,MAAM,CAAC,CAAC,CAACC,GAAGC,WAAW,GAAKA,YAAYC,GAAG,CAAC,CAAC,CAACvB,GAAG,GAAKA;YAE1FU,SAAS;gBAAEV,IAAI;oBAAEwB,IAAIN;gBAAI;YAAE;QAC7B,OAAO,IAAIV,wBAAwB,OAAO;YACxCE,SAAS,CAAC;QACZ;IACF,GAAG;QAACV;QAAIQ;QAAqBP,OAAOV;QAAOY;QAAUO;KAAS;IAE9D,iEAAiE;IACjE,IAAIE,iBAAiBjB,MAAM,IAAI,GAAG;QAChC,OAAO;IACT;IAEA,qBACE,KAACd;QACC4C,OAAO;YACLC,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC;YACR,sEAAsE;YACtEd,OAAOV,EAAE;YACTS,SAASD;QACX;QACA,sEAAsE;QACtEE,OAAOV,EAAE;QACTS,SAASD;QACTH,MAAK;;AAGX,EAAC"}
|
|
@@ -1 +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 { setValue, value } = useField<string>()\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { query } = useListQuery()\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n\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 }, [
|
|
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 { setValue, value } = useField<string>()\n const { value: collectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { query } = useListQuery()\n const { getEntityConfig } = useConfig()\n const { collection } = useImportExport()\n\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 }, [displayedValue, fieldOptions, value])\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={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 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","setValue","value","collectionSlug","path","query","getEntityConfig","collection","displayedValue","setDisplayedValue","collectionConfig","fieldOptions","fields","option","find","field","sort","onChange","div","className","style","label","disabled","readOnly","getOptionValue","String","inputId","replace","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,QAAQ,EAAEC,KAAK,EAAE,GAAGZ;IAC5B,MAAM,EAAEY,OAAOC,cAAc,EAAE,GAAGb,SAAiB;QAAEc,MAAM;IAAiB;IAC5E,MAAM,EAAEC,KAAK,EAAE,GAAGd;IAClB,MAAM,EAAEe,eAAe,EAAE,GAAGlB;IAC5B,MAAM,EAAEmB,UAAU,EAAE,GAAGX;IAEvB,MAAM,CAACY,gBAAgBC,kBAAkB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bC,YAAY;gBACZ,uCAAuC;gBACvCZ,UAAUA;gBACVa,SAASnB;gBACT,gCAAgC;gBAChCT,OAAOM;;;;AAIf,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAWrE,MAAM,MAAM,MAAM,GAAG;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;IACrB,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;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,YAAY,SAAgB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAWrE,MAAM,MAAM,MAAM,GAAG;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;IACrB,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;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,YAAY,SAAgB,gBAAgB,kCA0PxD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getCustomFieldFunctions } from './getCustomFieldFunctions.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\nexport type Export = {\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\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 /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n input: Export\n req: PayloadRequest\n user?: TypedUser\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n download,\n input: {\n id,\n name: nameArg,\n collectionSlug,\n debug = false,\n drafts,\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 if (debug) {\n req.payload.logger.info({\n message: 'Starting export process with args:',\n collectionSlug,\n drafts,\n fields,\n format,\n })\n }\n\n const locale = localeInput ?? localeArg\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\n const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.info({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.info({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n select,\n })\n\n if (download) {\n if (debug) {\n req.payload.logger.info('Pre-scanning all columns before streaming')\n }\n\n const allColumnsSet = new Set<string>()\n const allColumns: string[] = []\n let scanPage = 1\n let hasMore = true\n\n while (hasMore) {\n const result = await payload.find({ ...findArgs, page: scanPage })\n\n result.docs.forEach((doc) => {\n const flat = flattenObject({ doc, fields, toCSVFunctions })\n Object.keys(flat).forEach((key) => {\n if (!allColumnsSet.has(key)) {\n allColumnsSet.add(key)\n allColumns.push(key)\n }\n })\n })\n\n hasMore = result.hasNextPage\n scanPage += 1\n }\n\n if (debug) {\n req.payload.logger.info(`Discovered ${allColumns.length} columns`)\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let streamPage = 1\n\n const stream = new Readable({\n async read() {\n const result = await payload.find({ ...findArgs, page: streamPage })\n\n if (debug) {\n req.payload.logger.info(`Streaming batch ${streamPage} with ${result.docs.length} docs`)\n }\n\n if (result.docs.length === 0) {\n this.push(null)\n return\n }\n\n const batchRows = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n\n const paddedRows = batchRows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of allColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n const csvString = stringify(paddedRows, {\n header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n streamPage += 1\n\n if (!result.hasNextPage) {\n if (debug) {\n req.payload.logger.info('Stream complete - no more pages')\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(stream as any, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv' : 'application/json',\n },\n })\n }\n\n // Non-download path (buffered export)\n if (debug) {\n req.payload.logger.info('Starting file generation')\n }\n\n const outputData: string[] = []\n const rows: Record<string, unknown>[] = []\n const columnsSet = new Set<string>()\n const columns: string[] = []\n let page = 1\n let hasNextPage = true\n\n while (hasNextPage) {\n const result = await payload.find({\n ...findArgs,\n page,\n })\n\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const batchRows = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n\n // Track discovered column keys\n batchRows.forEach((row) => {\n Object.keys(row).forEach((key) => {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n })\n })\n\n rows.push(...batchRows)\n } else {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n\n hasNextPage = result.hasNextPage\n page += 1\n }\n\n if (isCSV) {\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of columns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n outputData.push(\n stringify(paddedRows, {\n header: true,\n columns,\n }),\n )\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n if (debug) {\n req.payload.logger.info(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.info('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.info(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n user,\n })\n }\n if (debug) {\n req.payload.logger.info('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","logger","info","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","findArgs","collection","depth","draft","limit","overrideAccess","page","toCSVFunctions","flattenedFields","allColumnsSet","Set","allColumns","scanPage","hasMore","result","docs","forEach","doc","flat","Object","keys","key","has","add","push","hasNextPage","encoder","TextEncoder","isFirstBatch","streamPage","stream","read","batchRows","map","paddedRows","row","fullRow","col","csvString","header","columns","encode","Response","headers","outputData","rows","columnsSet","jsonInput","JSON","join","buffer","Buffer","from","file","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AAO,CAACC,IAAI,GAAGF,GAAG,CAACE,IAAI,IAAI;YAC7B;YACA,OAAOD;QACT;QAEAQ,WAAWpB,IAAI,CACblE,UAAU4E,YAAY;YACpBK,QAAQ;YACRC;QACF;IAEJ;IAEA,MAAMU,SAASC,OAAOC,IAAI,CAAC3E,WAAW,SAAS,CAAC,CAAC,EAAEmE,WAAWK,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGL,WAAWK,IAAI,CAAC;IAC7F,IAAI5E,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,GAAGV,OAAO,yBAAyB,CAAC;IAC9D;IAEA,IAAI,CAACR,IAAI;QACP,IAAII,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QAC1B;QACAJ,IAAIsE,IAAI,GAAG;YACTnF;YACAoF,MAAMJ;YACNK,UAAU7D,QAAQ,aAAa;YAC/B8D,MAAMN,OAAOpD,MAAM;QACrB;IACF,OAAO;QACL,IAAIzB,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAElB,IAAI;QACnE;QACA,MAAMc,IAAIE,OAAO,CAACwE,MAAM,CAAC;YACvBxF;YACAgC,YAAY1B;YACZ+E,MAAM,CAAC;YACPD,MAAM;gBACJnF;gBACAoF,MAAMJ;gBACNK,UAAU7D,QAAQ,aAAa;gBAC/B8D,MAAMN,OAAOpD,MAAM;YACrB;YACAjB;QACF;IACF;IACA,IAAIR,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC1B;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getCustomFieldFunctions } from './getCustomFieldFunctions.js'\nimport { getFilename } from './getFilename.js'\nimport { getSelect } from './getSelect.js'\n\nexport type Export = {\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\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 /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n input: Export\n req: PayloadRequest\n user?: TypedUser\n}\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n download,\n input: {\n id,\n name: nameArg,\n collectionSlug,\n debug = false,\n drafts,\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 if (debug) {\n req.payload.logger.info({\n message: 'Starting export process with args:',\n collectionSlug,\n drafts,\n fields,\n format,\n })\n }\n\n const locale = localeInput ?? localeArg\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\n const name = `${nameArg ?? `${getFilename()}-${collectionSlug}`}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.info({ message: 'Export configuration:', name, isCSV, locale })\n }\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft: drafts === 'yes',\n limit: 100,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.info({ message: 'Find arguments:', findArgs })\n }\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n if (download) {\n if (debug) {\n req.payload.logger.info('Pre-scanning all columns before streaming')\n }\n\n const allColumnsSet = new Set<string>()\n const allColumns: string[] = []\n let scanPage = 1\n let hasMore = true\n\n while (hasMore) {\n const result = await payload.find({ ...findArgs, page: scanPage })\n\n result.docs.forEach((doc) => {\n const flat = flattenObject({ doc, fields, toCSVFunctions })\n Object.keys(flat).forEach((key) => {\n if (!allColumnsSet.has(key)) {\n allColumnsSet.add(key)\n allColumns.push(key)\n }\n })\n })\n\n hasMore = result.hasNextPage\n scanPage += 1\n }\n\n if (debug) {\n req.payload.logger.info(`Discovered ${allColumns.length} columns`)\n }\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let streamPage = 1\n\n const stream = new Readable({\n async read() {\n const result = await payload.find({ ...findArgs, page: streamPage })\n\n if (debug) {\n req.payload.logger.info(`Streaming batch ${streamPage} with ${result.docs.length} docs`)\n }\n\n if (result.docs.length === 0) {\n this.push(null)\n return\n }\n\n const batchRows = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n\n const paddedRows = batchRows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of allColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n const csvString = stringify(paddedRows, {\n header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n isFirstBatch = false\n streamPage += 1\n\n if (!result.hasNextPage) {\n if (debug) {\n req.payload.logger.info('Stream complete - no more pages')\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(stream as any, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv' : 'application/json',\n },\n })\n }\n\n // Non-download path (buffered export)\n if (debug) {\n req.payload.logger.info('Starting file generation')\n }\n\n const outputData: string[] = []\n const rows: Record<string, unknown>[] = []\n const columnsSet = new Set<string>()\n const columns: string[] = []\n let page = 1\n let hasNextPage = true\n\n while (hasNextPage) {\n const result = await payload.find({\n ...findArgs,\n page,\n })\n\n if (debug) {\n req.payload.logger.info(\n `Processing batch ${findArgs.page} with ${result.docs.length} documents`,\n )\n }\n\n if (isCSV) {\n const batchRows = result.docs.map((doc) => flattenObject({ doc, fields, toCSVFunctions }))\n\n // Track discovered column keys\n batchRows.forEach((row) => {\n Object.keys(row).forEach((key) => {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n })\n })\n\n rows.push(...batchRows)\n } else {\n const jsonInput = result.docs.map((doc) => JSON.stringify(doc))\n outputData.push(jsonInput.join(',\\n'))\n }\n\n hasNextPage = result.hasNextPage\n page += 1\n }\n\n if (isCSV) {\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of columns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n outputData.push(\n stringify(paddedRows, {\n header: true,\n columns,\n }),\n )\n }\n\n const buffer = Buffer.from(format === 'json' ? `[${outputData.join(',')}]` : outputData.join(''))\n if (debug) {\n req.payload.logger.info(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.info('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.info(`Updating existing export with id: ${id}`)\n }\n await req.payload.update({\n id,\n collection: exportsCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv' : 'application/json',\n size: buffer.length,\n },\n user,\n })\n }\n if (debug) {\n req.payload.logger.info('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","flattenObject","getCustomFieldFunctions","getFilename","getSelect","createExport","args","download","input","id","name","nameArg","collectionSlug","debug","drafts","exportsCollection","fields","format","locale","localeInput","sort","user","where","req","localeArg","payload","logger","info","message","collectionConfig","config","collections","find","slug","isCSV","select","Array","isArray","length","undefined","findArgs","collection","depth","draft","limit","overrideAccess","page","toCSVFunctions","flattenedFields","allColumnsSet","Set","allColumns","scanPage","hasMore","result","docs","forEach","doc","flat","Object","keys","key","has","add","push","hasNextPage","encoder","TextEncoder","isFirstBatch","streamPage","stream","read","batchRows","map","paddedRows","row","fullRow","col","csvString","header","columns","encode","Response","headers","outputData","rows","columnsSet","jsonInput","JSON","join","buffer","Buffer","from","file","data","mimetype","size","update"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,SAAS,QAAQ,iBAAgB;AAiC1C,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,QAAQ,EACRC,OAAO,EACLC,EAAE,EACFC,MAAMC,OAAO,EACbC,cAAc,EACdC,QAAQ,KAAK,EACbC,MAAM,EACNC,iBAAiB,EACjBC,MAAM,EACNC,MAAM,EACNC,QAAQC,WAAW,EACnBC,IAAI,EACJC,IAAI,EACJC,KAAK,EACN,EACDC,KAAK,EAAEL,QAAQM,SAAS,EAAEC,OAAO,EAAE,EACnCF,GAAG,EACJ,GAAGjB;IAEJ,IAAIO,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YACtBC,SAAS;YACThB;YACAE;YACAE;YACAC;QACF;IACF;IAEA,MAAMC,SAASC,eAAeK;IAC9B,MAAMK,mBAAmBJ,QAAQK,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASrB;IAChF,IAAI,CAACiB,kBAAkB;QACrB,MAAM,IAAI9B,SAAS,CAAC,qBAAqB,EAAEa,eAAe,UAAU,CAAC;IACvE;IAEA,MAAMF,OAAO,GAAGC,WAAW,GAAGR,cAAc,CAAC,EAAES,gBAAgB,CAAC,CAAC,EAAEK,QAAQ;IAC3E,MAAMiB,QAAQjB,WAAW;IACzB,MAAMkB,SAASC,MAAMC,OAAO,CAACrB,WAAWA,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,KAAKZ,GAAG,CAAC,CAACE;YAC3B,MAAMC,UAAmC,CAAC;YAC1C,KAAK,MAAMC,OAAOG,QAAS;gBACzBJ,OAAO,CAACC,IAAI,GAAGF,GAAG,CAACE,IAAI,IAAI;YAC7B;YACA,OAAOD;QACT;QAEAQ,WAAWpB,IAAI,CACblE,UAAU4E,YAAY;YACpBK,QAAQ;YACRC;QACF;IAEJ;IAEA,MAAMU,SAASC,OAAOC,IAAI,CAAC3E,WAAW,SAAS,CAAC,CAAC,EAAEmE,WAAWK,IAAI,CAAC,KAAK,CAAC,CAAC,GAAGL,WAAWK,IAAI,CAAC;IAC7F,IAAI5E,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,GAAGV,OAAO,yBAAyB,CAAC;IAC9D;IAEA,IAAI,CAACR,IAAI;QACP,IAAII,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QAC1B;QACAJ,IAAIsE,IAAI,GAAG;YACTnF;YACAoF,MAAMJ;YACNK,UAAU7D,QAAQ,aAAa;YAC/B8D,MAAMN,OAAOpD,MAAM;QACrB;IACF,OAAO;QACL,IAAIzB,OAAO;YACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAElB,IAAI;QACnE;QACA,MAAMc,IAAIE,OAAO,CAACwE,MAAM,CAAC;YACvBxF;YACAgC,YAAY1B;YACZ+E,MAAM,CAAC;YACPD,MAAM;gBACJnF;gBACAoF,MAAMJ;gBACNK,UAAU7D,QAAQ,aAAa;gBAC/B8D,MAAMN,OAAOpD,MAAM;YACrB;YACAjB;QACF;IACF;IACA,IAAIR,OAAO;QACTU,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC1B;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,6CAKvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/export/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,QAAQ,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,6CAKvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA6H/B,CAAA"}
|
|
@@ -6,20 +6,30 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
6
6
|
if (Array.isArray(value)) {
|
|
7
7
|
value.forEach((item, index)=>{
|
|
8
8
|
if (typeof item === 'object' && item !== null) {
|
|
9
|
+
// Case: hasMany polymorphic relationships
|
|
10
|
+
if ('relationTo' in item && 'value' in item && typeof item.value === 'object' && item.value !== null) {
|
|
11
|
+
row[`${`${newKey}_${index}`}_relationTo`] = item.relationTo;
|
|
12
|
+
row[`${`${newKey}_${index}`}_id`] = item.value.id;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
9
15
|
flatten(item, `${newKey}_${index}`);
|
|
10
16
|
} else {
|
|
11
17
|
if (toCSVFunctions?.[newKey]) {
|
|
12
18
|
const columnName = `${newKey}_${index}`;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
try {
|
|
20
|
+
const result = toCSVFunctions[newKey]({
|
|
21
|
+
columnName,
|
|
22
|
+
data: row,
|
|
23
|
+
doc,
|
|
24
|
+
row,
|
|
25
|
+
siblingDoc,
|
|
26
|
+
value: item
|
|
27
|
+
});
|
|
28
|
+
if (typeof result !== 'undefined') {
|
|
29
|
+
row[columnName] = result;
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new Error(`Error in toCSVFunction for array item "${columnName}": ${JSON.stringify(item)}\n${error.message}`);
|
|
23
33
|
}
|
|
24
34
|
} else {
|
|
25
35
|
row[`${newKey}_${index}`] = item;
|
|
@@ -30,30 +40,38 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
30
40
|
if (!toCSVFunctions?.[newKey]) {
|
|
31
41
|
flatten(value, newKey);
|
|
32
42
|
} else {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
try {
|
|
44
|
+
const result = toCSVFunctions[newKey]({
|
|
45
|
+
columnName: newKey,
|
|
46
|
+
data: row,
|
|
47
|
+
doc,
|
|
48
|
+
row,
|
|
49
|
+
siblingDoc,
|
|
50
|
+
value
|
|
51
|
+
});
|
|
52
|
+
if (typeof result !== 'undefined') {
|
|
53
|
+
row[newKey] = result;
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error(`Error in toCSVFunction for nested object "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
59
|
} else {
|
|
46
60
|
if (toCSVFunctions?.[newKey]) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
try {
|
|
62
|
+
const result = toCSVFunctions[newKey]({
|
|
63
|
+
columnName: newKey,
|
|
64
|
+
data: row,
|
|
65
|
+
doc,
|
|
66
|
+
row,
|
|
67
|
+
siblingDoc,
|
|
68
|
+
value
|
|
69
|
+
});
|
|
70
|
+
if (typeof result !== 'undefined') {
|
|
71
|
+
row[newKey] = result;
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error(`Error in toCSVFunction for field "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
57
75
|
}
|
|
58
76
|
} else {
|
|
59
77
|
row[newKey] = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).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 flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n const result = toCSVFunctions[newKey]({\n
|
|
1
|
+
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).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 // Case: hasMany polymorphic relationships\n if (\n 'relationTo' in item &&\n 'value' in item &&\n typeof item.value === 'object' &&\n item.value !== null\n ) {\n row[`${`${newKey}_${index}`}_relationTo`] = item.relationTo\n row[`${`${newKey}_${index}`}_id`] = item.value.id\n return\n }\n\n flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n try {\n const result = toCSVFunctions[newKey]({\n columnName,\n data: row,\n doc,\n row,\n siblingDoc,\n value: item,\n })\n if (typeof result !== 'undefined') {\n row[columnName] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for array item \"${columnName}\": ${JSON.stringify(item)}\\n${(error as Error).message}`,\n )\n }\n } else {\n row[`${newKey}_${index}`] = item\n }\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n if (!toCSVFunctions?.[newKey]) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for nested object \"${newKey}\": ${JSON.stringify(value)}\\n${(error as Error).message}`,\n )\n }\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for field \"${newKey}\": ${JSON.stringify(value)}\\n${(error as Error).message}`,\n )\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","relationTo","id","columnName","result","data","error","Error","JSON","stringify","message","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,UAAU,CAACC,YAAsBJ;QACrCK,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASV,SAAS,GAAGA,OAAO,CAAC,EAAEQ,KAAK,GAAGA;YAE7C,IAAIG,MAAMC,OAAO,CAACH,QAAQ;gBACxBA,MAAMF,OAAO,CAAC,CAACM,MAAMC;oBACnB,IAAI,OAAOD,SAAS,YAAYA,SAAS,MAAM;wBAC7C,0CAA0C;wBAC1C,IACE,g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ACmC,eAAe;YACrD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3BvB,OAAOkC,IAAI,CAACrC,KAAKK,OAAO,CAAC,CAACC;oBACxB,IAAI8B,MAAME,IAAI,CAAChC,MAAM;wBACnBkB,aAAa,CAAClB,IAAI,GAAGN,GAAG,CAACM,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOkB;IACT;IAEA,OAAOxB;AACT,EAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type FlattenedField
|
|
1
|
+
import { type FlattenedField } from 'payload';
|
|
2
2
|
import type { ToCSVFunction } from '../types.js';
|
|
3
3
|
type Args = {
|
|
4
4
|
fields: FlattenedField[];
|
|
5
|
-
select: SelectIncludeType | undefined;
|
|
6
5
|
};
|
|
7
|
-
export declare const getCustomFieldFunctions: ({ fields
|
|
6
|
+
export declare const getCustomFieldFunctions: ({ fields }: Args) => Record<string, ToCSVFunction>;
|
|
8
7
|
export {};
|
|
9
8
|
//# sourceMappingURL=getCustomFieldFunctions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAwFtF,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { traverseFields } from 'payload';
|
|
2
|
-
export const getCustomFieldFunctions = ({ fields
|
|
2
|
+
export const getCustomFieldFunctions = ({ fields })=>{
|
|
3
3
|
const result = {};
|
|
4
4
|
const buildCustomFunctions = ({ field, parentRef, ref })=>{
|
|
5
5
|
// @ts-expect-error ref is untyped
|
|
@@ -33,7 +33,8 @@ export const getCustomFieldFunctions = ({ fields, select })=>{
|
|
|
33
33
|
data[`${ref.prefix}${field.name}_relationTo`] = relationTo;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return undefined
|
|
36
|
+
return undefined // prevents further flattening
|
|
37
|
+
;
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
} else {
|
|
@@ -64,9 +65,6 @@ export const getCustomFieldFunctions = ({ fields, select })=>{
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
// TODO: do this so we only return the functions needed based on the select used
|
|
68
|
-
////@ts-expect-error ref is untyped
|
|
69
|
-
// ref.select = typeof select !== 'undefined' || select[field.name] ? select : {}
|
|
70
68
|
};
|
|
71
69
|
traverseFields({
|
|
72
70
|
callback: buildCustomFunctions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\nexport const getCustomFieldFunctions = ({ fields }: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n const relationTo = (value as { relationTo: string; value: { id: number | string } })\n .relationTo\n const relatedDoc = (value as { relationTo: string; value: { id: number | string } })\n .value\n if (relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = relationTo\n }\n }\n return undefined // prevents further flattening\n }\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n value,\n }: {\n value: Record<string, unknown>[]\n }) =>\n value.map((val: number | Record<string, unknown> | string) =>\n typeof val === 'object' ? val.id : val,\n )\n } else {\n // polymorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<Record<string, any>> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n if (val && typeof val === 'object') {\n const relationTo = val.relationTo\n const relatedDoc = val.value\n if (relationTo && relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo\n }\n }\n })\n }\n return undefined\n }\n }\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getCustomFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","hasMany","Array","isArray","relationTo","value","id","data","relatedDoc","undefined","map","val","forEach","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAAwC,CAAC;IAE/C,MAAMC,uBAA+C,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC7E,kCAAkC;QAClCA,IAAIC,MAAM,GAAGF,UAAUE,MAAM,IAAI;QACjC,IAAIH,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,OAAO;YAClD,kCAAkC;YAClC,MAAMC,eAAeJ,WAAWE,SAAS,GAAGF,UAAUE,MAAM,CAAC,CAAC,CAAC,GAAG;YAClE,kCAAkC;YAClCD,IAAIC,MAAM,GAAG,GAAGE,eAAeL,MAAMM,IAAI,CAAC,CAAC,CAAC;QAC9C;QAEA,IAAI,OAAON,MAAMO,MAAM,EAAE,CAAC,uBAAuB,EAAEC,UAAU,YAAY;YACvE,kCAAkC;YAClCV,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAGN,MAAMO,MAAM,CAAC,uBAAuB,EAAEC;QAC/E,OAAO,IAAIR,MAAMI,IAAI,KAAK,kBAAkBJ,MAAMI,IAAI,KAAK,UAAU;YACnE,IAAIJ,MAAMS,OAAO,KAAK,MAAM;gBAC1B,IAAI,CAACC,MAAMC,OAAO,CAACX,MAAMY,UAAU,GAAG;oBACpC,qBAAqB;oBACrB,kCAAkC;oBAClCd,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAA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AAMO,OAAO,CAAC,CAACD,KAAKE;gCAClB,IAAIF,OAAO,OAAOA,QAAQ,UAAU;oCAClC,MAAMP,aAAaO,IAAIP,UAAU;oCACjC,MAAMI,aAAaG,IAAIN,KAAK;oCAC5B,IAAID,cAAcI,cAAc,OAAOA,eAAe,UAAU;wCAC9D,kCAAkC;wCAClCD,IAAI,CAAC,GAAGb,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEe,EAAE,GAAG,CAAC,CAAC,GAAGL,WAAWF,EAAE;wCAC1D,kCAAkC;wCAClCC,IAAI,CAAC,GAAGb,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEe,EAAE,WAAW,CAAC,CAAC,GAAGT;oCACvD;gCACF;4BACF;wBACF;wBACA,OAAOK;oBACT;gBACF;YACF;QACF;IACF;IAEAtB,eAAe;QAAE2B,UAAUvB;QAAsBF;IAAO;IAExD,OAAOC;AACT,EAAC"}
|
|
@@ -1 +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,
|
|
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,EA+M/C,CAAA"}
|
package/dist/export/getFields.js
CHANGED
|
@@ -114,12 +114,13 @@ export const getFields = (config)=>{
|
|
|
114
114
|
]
|
|
115
115
|
},
|
|
116
116
|
{
|
|
117
|
-
// virtual field for the UI component to modify the hidden `where` field
|
|
118
117
|
name: 'selectionToUse',
|
|
119
118
|
type: 'radio',
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
admin: {
|
|
120
|
+
components: {
|
|
121
|
+
Field: '@payloadcms/plugin-import-export/rsc#SelectionToUseField'
|
|
122
|
+
}
|
|
123
|
+
},
|
|
123
124
|
options: [
|
|
124
125
|
{
|
|
125
126
|
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
@@ -136,8 +137,7 @@ export const getFields = (config)=>{
|
|
|
136
137
|
label: ({ t })=>t('plugin-import-export:selectionToUse-allDocuments'),
|
|
137
138
|
value: 'all'
|
|
138
139
|
}
|
|
139
|
-
]
|
|
140
|
-
virtual: true
|
|
140
|
+
]
|
|
141
141
|
},
|
|
142
142
|
{
|
|
143
143
|
name: 'fields',
|
|
@@ -166,11 +166,16 @@ export const getFields = (config)=>{
|
|
|
166
166
|
name: 'where',
|
|
167
167
|
type: 'json',
|
|
168
168
|
admin: {
|
|
169
|
-
|
|
170
|
-
Field: '@payloadcms/plugin-import-export/rsc#WhereField'
|
|
171
|
-
}
|
|
169
|
+
hidden: true
|
|
172
170
|
},
|
|
173
|
-
defaultValue: {}
|
|
171
|
+
defaultValue: {},
|
|
172
|
+
hooks: {
|
|
173
|
+
beforeValidate: [
|
|
174
|
+
({ value })=>{
|
|
175
|
+
return value ?? {};
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
}
|
|
174
179
|
}
|
|
175
180
|
],
|
|
176
181
|
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getFields.ts"],"sourcesContent":["import type { Config, Field, SelectField } from 'payload'\n\nimport { getFilename } from './getFilename.js'\n\nexport const getFields = (config: Config): Field[] => {\n let localeField: SelectField | undefined\n if (config.localization) {\n localeField = {\n name: 'locale',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-locale-label'),\n options: [\n {\n label: ({ t }) => t('general:allLocales'),\n value: 'all',\n },\n ...config.localization.locales.map((locale) => ({\n label: typeof locale === 'string' ? locale : locale.label,\n value: typeof locale === 'string' ? locale : locale.code,\n })),\n ],\n }\n }\n\n return [\n {\n type: 'collapsible',\n fields: [\n {\n name: 'name',\n type: 'text',\n defaultValue: () => getFilename(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-name-label'),\n },\n {\n type: 'row',\n fields: [\n {\n name: 'format',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'csv',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-format-label'),\n options: [\n {\n label: 'CSV',\n value: 'csv',\n },\n {\n label: 'JSON',\n value: 'json',\n },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n placeholder: 'No limit',\n width: '33%',\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-limit-label'),\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SortBy',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-sort-label'),\n },\n ],\n },\n {\n type: 'row',\n fields: [\n ...(localeField ? [localeField] : []),\n {\n name: 'drafts',\n type: 'select',\n admin: {\n condition: (data) => {\n const collectionConfig = (config.collections ?? []).find(\n (collection) => collection.slug === data.collectionSlug,\n )\n return Boolean(\n typeof collectionConfig?.versions === 'object' &&\n collectionConfig?.versions?.drafts,\n )\n },\n width: '33%',\n },\n defaultValue: 'yes',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-drafts-label'),\n options: [\n {\n label: ({ t }) => t('general:yes'),\n value: 'yes',\n },\n {\n label: ({ t }) => t('general:no'),\n value: 'no',\n },\n ],\n },\n // {\n // name: 'depth',\n // type: 'number',\n // // @ts-expect-error - this is not correctly typed in plugins right now\n // label: ({ t }) => t('plugin-import-export:field-depth-label'),\n // admin: {\n // width: '33%',\n // },\n // defaultValue: 1,\n // required: true,\n // },\n ],\n },\n {\n // virtual field for the UI component to modify the hidden `where` field\n name: 'selectionToUse',\n type: 'radio',\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-selectionToUse-label'),\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ],\n virtual: true,\n },\n {\n name: 'fields',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport',\n },\n },\n hasMany: true,\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-fields-label'),\n },\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#CollectionField',\n },\n hidden: true,\n },\n required: true,\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#WhereField',\n },\n },\n defaultValue: {},\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:exportOptions'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#Preview',\n },\n },\n },\n ]\n}\n"],"names":["getFilename","getFields","config","localeField","localization","name","type","admin","width","defaultValue","label","t","options","value","locales","map","locale","code","fields","required","placeholder","components","Field","condition","data","collectionConfig","collections","find","collection","slug","collectionSlug","Boolean","versions","drafts","virtual","hasM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oBACE7B,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;oBACF;oBACAa,SAAS;oBACT,sEAAsE;oBACtEzB,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;gBACtB;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;wBACAc,QAAQ;oBACV;oBACAjB,UAAU;gBACZ;gBACA;oBACEd,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;oBACF;oBACAb,cAAc,CAAC;gBACjB;aACD;YACD,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;QACtB;QACA;YACEN,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLc,YAAY;oBACVC,OAAO;gBACT;YACF;QACF;KACD;AACH,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/getFields.ts"],"sourcesContent":["import type { Config, Field, SelectField } from 'payload'\n\nimport { getFilename } from './getFilename.js'\n\nexport const getFields = (config: Config): Field[] => {\n let localeField: SelectField | undefined\n if (config.localization) {\n localeField = {\n name: 'locale',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-locale-label'),\n options: [\n {\n label: ({ t }) => t('general:allLocales'),\n value: 'all',\n },\n ...config.localization.locales.map((locale) => ({\n label: typeof locale === 'string' ? locale : locale.label,\n value: typeof locale === 'string' ? locale : locale.code,\n })),\n ],\n }\n }\n\n return [\n {\n type: 'collapsible',\n fields: [\n {\n name: 'name',\n type: 'text',\n defaultValue: () => getFilename(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-name-label'),\n },\n {\n type: 'row',\n fields: [\n {\n name: 'format',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'csv',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-format-label'),\n options: [\n {\n label: 'CSV',\n value: 'csv',\n },\n {\n label: 'JSON',\n value: 'json',\n },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n placeholder: 'No limit',\n width: '33%',\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-limit-label'),\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SortBy',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-sort-label'),\n },\n ],\n },\n {\n type: 'row',\n fields: [\n ...(localeField ? [localeField] : []),\n {\n name: 'drafts',\n type: 'select',\n admin: {\n condition: (data) => {\n const collectionConfig = (config.collections ?? []).find(\n (collection) => collection.slug === data.collectionSlug,\n )\n return Boolean(\n typeof collectionConfig?.versions === 'object' &&\n collectionConfig?.versions?.drafts,\n )\n },\n width: '33%',\n },\n defaultValue: 'yes',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-drafts-label'),\n options: [\n {\n label: ({ t }) => t('general:yes'),\n value: 'yes',\n },\n {\n label: ({ t }) => t('general:no'),\n value: 'no',\n },\n ],\n },\n // {\n // name: 'depth',\n // type: 'number',\n // // @ts-expect-error - this is not correctly typed in plugins right now\n // label: ({ t }) => t('plugin-import-export:field-depth-label'),\n // admin: {\n // width: '33%',\n // },\n // defaultValue: 1,\n // required: true,\n // },\n ],\n },\n {\n name: 'selectionToUse',\n type: 'radio',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SelectionToUseField',\n },\n },\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ],\n },\n {\n name: 'fields',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport',\n },\n },\n hasMany: true,\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-fields-label'),\n },\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#CollectionField',\n },\n hidden: true,\n },\n required: true,\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n hidden: true,\n },\n defaultValue: {},\n hooks: {\n beforeValidate: [\n ({ value }) => {\n return value ?? {}\n },\n ],\n },\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:exportOptions'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#Preview',\n },\n },\n },\n ]\n}\n"],"names":["getFilename","getFields","config","localeField","localization","name","type","admin","width","defaultValue","label","t","options","value","locales","map","locale","code","fields","required","placeholder","components","Field","condition","data","collectionConfig","collections","find","collection","slug","collectionSlug","Boolean","versions","drafts","hasMany","hidden","hooks","beforeValidate"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAY,CAACC;IACxB,IAAIC;IACJ,IAAID,OAAOE,YAAY,EAAE;QACvBD,cAAc;YACZE,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,OAAO;YACT;YACAC,cAAc;YACd,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBC,SAAS;gBACP;oBACEF,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;mBACGX,OAAOE,Y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R,OAAOA,SAAS,CAAC;4BACnB;yBACD;oBACH;gBACF;aACD;YACD,sEAAsE;YACtEH,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;QACtB;QACA;YACEN,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLc,YAAY;oBACVC,OAAO;gBACT;YACF;QACF;KACD;AACH,EAAC"}
|
package/dist/exports/rsc.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export { ExportSaveButton } from '../components/ExportSaveButton/index.js';
|
|
|
4
4
|
export { FieldsToExport } from '../components/FieldsToExport/index.js';
|
|
5
5
|
export { ImportExportProvider } from '../components/ImportExportProvider/index.js';
|
|
6
6
|
export { Preview } from '../components/Preview/index.js';
|
|
7
|
+
export { SelectionToUseField } from '../components/SelectionToUseField/index.js';
|
|
7
8
|
export { SortBy } from '../components/SortBy/index.js';
|
|
8
|
-
export { WhereField } from '../components/WhereField/index.js';
|
|
9
9
|
//# sourceMappingURL=rsc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/exports/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/exports/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA"}
|
package/dist/exports/rsc.js
CHANGED
|
@@ -4,7 +4,7 @@ export { ExportSaveButton } from '../components/ExportSaveButton/index.js';
|
|
|
4
4
|
export { FieldsToExport } from '../components/FieldsToExport/index.js';
|
|
5
5
|
export { ImportExportProvider } from '../components/ImportExportProvider/index.js';
|
|
6
6
|
export { Preview } from '../components/Preview/index.js';
|
|
7
|
+
export { SelectionToUseField } from '../components/SelectionToUseField/index.js';
|
|
7
8
|
export { SortBy } from '../components/SortBy/index.js';
|
|
8
|
-
export { WhereField } from '../components/WhereField/index.js';
|
|
9
9
|
|
|
10
10
|
//# sourceMappingURL=rsc.js.map
|
package/dist/exports/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { CollectionField } from '../components/CollectionField/index.js'\nexport { ExportListMenuItem } from '../components/ExportListMenuItem/index.js'\nexport { ExportSaveButton } from '../components/ExportSaveButton/index.js'\nexport { FieldsToExport } from '../components/FieldsToExport/index.js'\nexport { ImportExportProvider } from '../components/ImportExportProvider/index.js'\nexport { Preview } from '../components/Preview/index.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { CollectionField } from '../components/CollectionField/index.js'\nexport { ExportListMenuItem } from '../components/ExportListMenuItem/index.js'\nexport { ExportSaveButton } from '../components/ExportSaveButton/index.js'\nexport { FieldsToExport } from '../components/FieldsToExport/index.js'\nexport { ImportExportProvider } from '../components/ImportExportProvider/index.js'\nexport { Preview } from '../components/Preview/index.js'\nexport { SelectionToUseField } from '../components/SelectionToUseField/index.js'\nexport { SortBy } from '../components/SortBy/index.js'\n"],"names":["CollectionField","ExportListMenuItem","ExportSaveButton","FieldsToExport","ImportExportProvider","Preview","SelectionToUseField","SortBy"],"mappings":"AAAA,SAASA,eAAe,QAAQ,yCAAwC;AACxE,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,gBAAgB,QAAQ,0CAAyC;AAC1E,SAASC,cAAc,QAAQ,wCAAuC;AACtE,SAASC,oBAAoB,QAAQ,8CAA6C;AAClF,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SAASC,mBAAmB,QAAQ,6CAA4C;AAChF,SAASC,MAAM,QAAQ,gCAA+B"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAA;AAKrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAA;AAKrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,MA6IjB,CAAA;AAEH,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,WAAW;QAC1B,sBAAsB,CAAC,EAAE;YACvB,KAAK,CAAC,EAAE,aAAa,CAAA;SACtB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -84,8 +84,7 @@ export const importExportPlugin = (pluginConfig)=>(config)=>{
|
|
|
84
84
|
});
|
|
85
85
|
const docs = result.docs;
|
|
86
86
|
const toCSVFunctions = getCustomFieldFunctions({
|
|
87
|
-
fields: collection.config.fields
|
|
88
|
-
select
|
|
87
|
+
fields: collection.config.fields
|
|
89
88
|
});
|
|
90
89
|
const possibleKeys = getFlattenedFieldKeys(collection.config.fields);
|
|
91
90
|
const transformed = docs.map((doc)=>{
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, FlattenedField } from 'payload'\n\nimport { addDataAndFileToRequest, deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { flattenObject } from './export/flattenObject.js'\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js'\nimport { getSelect } from './export/getSelect.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\nimport { getFlattenedFieldKeys } from './utilities/getFlattenedFieldKeys.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n // Inject custom REST endpoints into the config\n config.endpoints = config.endpoints || []\n config.endpoints.push({\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n limit?: number\n locale?: string\n sort?: any\n where?: any\n }\n\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft: draft === 'yes',\n limit: limit && limit > 10 ? 10 : limit,\n locale,\n overrideAccess: false,\n req,\n select,\n sort,\n where,\n })\n\n const docs = result.docs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collection.config.fields as FlattenedField[],\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, FlattenedField } from 'payload'\n\nimport { addDataAndFileToRequest, deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { flattenObject } from './export/flattenObject.js'\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js'\nimport { getSelect } from './export/getSelect.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\nimport { getFlattenedFieldKeys } from './utilities/getFlattenedFieldKeys.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n // Inject custom REST endpoints into the config\n config.endpoints = config.endpoints || []\n config.endpoints.push({\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n limit?: number\n locale?: string\n sort?: any\n where?: any\n }\n\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft: draft === 'yes',\n limit: limit && limit > 10 ? 10 : limit,\n locale,\n overrideAccess: false,\n req,\n select,\n sort,\n where,\n })\n\n const docs = result.docs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collection.config.fields as FlattenedField[],\n })\n\n const possibleKeys = getFlattenedFieldKeys(collection.config.fields as FlattenedField[])\n\n const transformed = docs.map((doc) => {\n const row = flattenObject({\n doc,\n fields,\n toCSVFunctions,\n })\n\n for (const key of possibleKeys) {\n if (!(key in row)) {\n row[key] = null\n }\n }\n\n return row\n })\n\n return Response.json({\n docs: transformed,\n totalDocs: result.totalDocs,\n })\n },\n method: 'post',\n path: '/preview-data',\n })\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n toCSV?: ToCSVFunction\n }\n }\n}\n"],"names":["addDataAndFileToRequest","deepMergeSimple","flattenObject","getCreateCollectionExportTask","getCustomFieldFunctions","getSelect","getExportCollection","translations","getFlattenedFieldKeys","importExportPlugin","pluginConfig","config","exportCollection","collections","push","admin","components","providers","jobs","tasks","collectionsToUpdate","usePluginCollections","length","filter","collection","includes","slug","forEach","listMenuItems","clientProps","exportCollectionSlug","path","i18n","endpoints","handler","req","collectionSlug","draft","fields","limit","locale","sort","where","data","payload","Response","json","error","status","select","Array","isArray","undefined","result","find","depth","overrideAccess","docs","toCSVFunctions","possibleKeys","transformed","map","doc","row","key","totalDocs","method","simplifiedTranslations","Object","entries","reduce","acc","value"],"mapp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OA,UAAU;oBACjBE,OAAOA,SAASA,QAAQ,KAAK,KAAKA;oBAClCC;oBACAgB,gBAAgB;oBAChBrB;oBACAc;oBACAR;oBACAC;gBACF;gBAEA,MAAMe,OAAOJ,OAAOI,IAAI;gBAExB,MAAMC,iBAAiBtD,wBAAwB;oBAC7CkC,QAAQd,WAAWb,MAAM,CAAC2B,MAAM;gBAClC;gBAEA,MAAMqB,eAAenD,sBAAsBgB,WAAWb,MAAM,CAAC2B,MAAM;gBAEnE,MAAMsB,cAAcH,KAAKI,GAAG,CAAC,CAACC;oBAC5B,MAAMC,MAAM7D,cAAc;wBACxB4D;wBACAxB;wBACAoB;oBACF;oBAEA,KAAK,MAAMM,OAAOL,aAAc;wBAC9B,IAAI,CAAEK,CAAAA,OAAOD,GAAE,GAAI;4BACjBA,GAAG,CAACC,IAAI,GAAG;wBACb;oBACF;oBAEA,OAAOD;gBACT;gBAEA,OAAOlB,SAASC,IAAI,CAAC;oBACnBW,MAAMG;oBACNK,WAAWZ,OAAOY,SAAS;gBAC7B;YACF;YACAC,QAAQ;YACRnC,MAAM;QACR;QAEA;;KAEC,GACD,MAAMoC,yBAAyBC,OAAOC,OAAO,CAAC9D,cAAc+D,MAAM,CAChE,CAACC,KAAK,CAACP,KAAKQ,MAAM;YAChBD,GAAG,CAACP,IAAI,GAAGQ,MAAMjE,YAAY;YAC7B,OAAOgE;QACT,GACA,CAAC;QAGH5D,OAAOqB,IAAI,GAAG;YACZ,GAAGrB,OAAOqB,IAAI;YACdzB,cAAcN,gBAAgBkE,wBAAwBxD,OAAOqB,IAAI,EAAEzB,gBAAgB,CAAC;QACtF;QAEA,OAAOI;IACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFlattenedFieldKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,KAAK,uBAAuB,GACxB;IACE,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,cAAc,EAAE,CAAA;QACxB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;IACH,IAAI,EAAE,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;CACrC,GACD,cAAc,CAAA;AAElB,eAAO,MAAM,qBAAqB,WAAY,uBAAuB,EAAE,sBAAgB,MAAM,
|
|
1
|
+
{"version":3,"file":"getFlattenedFieldKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,KAAK,uBAAuB,GACxB;IACE,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,cAAc,EAAE,CAAA;QACxB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;IACH,IAAI,EAAE,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;CACrC,GACD,cAAc,CAAA;AAElB,eAAO,MAAM,qBAAqB,WAAY,uBAAuB,EAAE,sBAAgB,MAAM,EA4E5F,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export const getFlattenedFieldKeys = (fields, prefix = '')=>{
|
|
2
2
|
const keys = [];
|
|
3
3
|
fields.forEach((field)=>{
|
|
4
|
-
|
|
4
|
+
const fieldHasToCSVFunction = 'custom' in field && typeof field.custom === 'object' && 'plugin-import-export' in field.custom && field.custom['plugin-import-export']?.toCSV;
|
|
5
|
+
if (!('name' in field) || typeof field.name !== 'string' || fieldHasToCSVFunction) {
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
8
|
const name = prefix ? `${prefix}_${field.name}` : field.name;
|
|
@@ -25,11 +26,21 @@ export const getFlattenedFieldKeys = (fields, prefix = '')=>{
|
|
|
25
26
|
break;
|
|
26
27
|
case 'relationship':
|
|
27
28
|
if (field.hasMany) {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (Array.isArray(field.relationTo)) {
|
|
30
|
+
// hasMany polymorphic
|
|
31
|
+
keys.push(`${name}_0_relationTo`, `${name}_0_id`);
|
|
32
|
+
} else {
|
|
33
|
+
// hasMany monomorphic
|
|
34
|
+
keys.push(`${name}_0`);
|
|
35
|
+
}
|
|
30
36
|
} else {
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
if (Array.isArray(field.relationTo)) {
|
|
38
|
+
// hasOne polymorphic
|
|
39
|
+
keys.push(`${name}_relationTo`, `${name}_id`);
|
|
40
|
+
} else {
|
|
41
|
+
// hasOne monomorphic
|
|
42
|
+
keys.push(name);
|
|
43
|
+
}
|
|
33
44
|
}
|
|
34
45
|
break;
|
|
35
46
|
case 'tabs':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"sourcesContent":["import { type FlattenedField } from 'payload'\n\ntype FieldWithPresentational =\n | {\n fields?: FlattenedField[]\n name?: string\n tabs?: {\n fields: FlattenedField[]\n name?: string\n }[]\n type: 'collapsible' | 'row' | 'tabs'\n }\n | FlattenedField\n\nexport const getFlattenedFieldKeys = (fields: FieldWithPresentational[], prefix = ''): string[] => {\n const keys: string[] = []\n\n fields.forEach((field) => {\n if (!('name' in field) || typeof field.name !== 'string') {\n return\n }\n\n const name = prefix ? `${prefix}_${field.name}` : field.name\n\n switch (field.type) {\n case 'array': {\n const subKeys = getFlattenedFieldKeys(field.fields as FlattenedField[], `${name}_0`)\n keys.push(...subKeys)\n break\n }\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKeys = getFlattenedFieldKeys(block.fields as FlattenedField[], `${name}_0`)\n keys.push(...blockKeys)\n })\n break\n case 'collapsible':\n case 'group':\n case 'row':\n keys.push(...getFlattenedFieldKeys(field.fields as FlattenedField[], name))\n break\n case 'relationship':\n if (field.hasMany) {\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"sourcesContent":["import { type FlattenedField } from 'payload'\n\ntype FieldWithPresentational =\n | {\n fields?: FlattenedField[]\n name?: string\n tabs?: {\n fields: FlattenedField[]\n name?: string\n }[]\n type: 'collapsible' | 'row' | 'tabs'\n }\n | FlattenedField\n\nexport const getFlattenedFieldKeys = (fields: FieldWithPresentational[], prefix = ''): string[] => {\n const keys: string[] = []\n\n fields.forEach((field) => {\n const fieldHasToCSVFunction =\n 'custom' in field &&\n typeof field.custom === 'object' &&\n 'plugin-import-export' in field.custom &&\n field.custom['plugin-import-export']?.toCSV\n\n if (!('name' in field) || typeof field.name !== 'string' || fieldHasToCSVFunction) {\n return\n }\n\n const name = prefix ? `${prefix}_${field.name}` : field.name\n\n switch (field.type) {\n case 'array': {\n const subKeys = getFlattenedFieldKeys(field.fields as FlattenedField[], `${name}_0`)\n keys.push(...subKeys)\n break\n }\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKeys = getFlattenedFieldKeys(block.fields as FlattenedField[], `${name}_0`)\n keys.push(...blockKeys)\n })\n break\n case 'collapsible':\n case 'group':\n case 'row':\n keys.push(...getFlattenedFieldKeys(field.fields as FlattenedField[], name))\n break\n case 'relationship':\n if (field.hasMany) {\n if (Array.isArray(field.relationTo)) {\n // hasMany polymorphic\n keys.push(`${name}_0_relationTo`, `${name}_0_id`)\n } else {\n // hasMany monomorphic\n keys.push(`${name}_0`)\n }\n } else {\n if (Array.isArray(field.relationTo)) {\n // hasOne polymorphic\n keys.push(`${name}_relationTo`, `${name}_id`)\n } else {\n // hasOne monomorphic\n keys.push(name)\n }\n }\n break\n case 'tabs':\n if (field.tabs) {\n field.tabs.forEach((tab) => {\n if (tab.name) {\n const tabPrefix = prefix ? `${prefix}_${tab.name}` : tab.name\n keys.push(...getFlattenedFieldKeys(tab.fields, tabPrefix))\n } else {\n keys.push(...getFlattenedFieldKeys(tab.fields, prefix))\n }\n })\n }\n break\n default:\n if ('hasMany' in field && field.hasMany) {\n // Push placeholder for first index\n keys.push(`${name}_0`)\n } else {\n keys.push(name)\n }\n break\n }\n })\n\n return keys\n}\n"],"names":["getFlattenedFieldKeys","fields","prefix","keys","forEach","field","fieldHasToCSVFunction","custom","toCSV","name","type","subKeys","push","blocks","block","blockKeys","hasMany","Array","isArray","relationTo","tabs","tab","tabPrefix"],"mappings":"AAcA,OAAO,MAAMA,wBAAwB,CAACC,QAAmCC,SAAS,EAAE;IAClF,MAAMC,OAAiB,EAAE;IAEzBF,OAAOG,OAAO,CAAC,CAACC;QACd,MAAMC,wBACJ,YAAYD,SACZ,OAAOA,MAAME,MAAM,KAAK,YACxB,0BAA0BF,MAAME,MAAM,IACtCF,MAAME,MAAM,CAAC,uBAAuB,EAAEC;QAExC,IAAI,CAAE,CAAA,UAAUH,KAAI,KAAM,OAAOA,MAAMI,IAAI,KAAK,YAAYH,uBAAuB;YACjF;QACF;QAEA,MAAMG,OAAOP,SAAS,GAAGA,OAAO,CAAC,EAAEG,MAAMI,IAAI,EAAE,GAAGJ,MAAMI,IAAI;QAE5D,OAAQJ,MAAMK,IAAI;YAChB,KAAK;gBAAS;oBACZ,MAAMC,UAAUX,sBAAsBK,MAAMJ,MAAM,EAAsB,GAAGQ,KAAK,EAAE,CAAC;oBACnFN,KAAKS,IAAI,IAAID;oBACb;gBACF;YACA,KAAK;gBACHN,MAAMQ,MAAM,CAACT,OAAO,CAAC,CAACU;oBACpB,MAAMC,YAAYf,sBAAsBc,MAAMb,MAAM,EAAsB,GAAGQ,KAAK,EAAE,CAAC;oBACrFN,KAAKS,IAAI,IAAIG;gBACf;gBACA;YACF,KAAK;YACL,KAAK;YACL,KAAK;gBACHZ,KAAKS,IAAI,IAAIZ,sBAAsBK,MAAMJ,MAAM,EAAsBQ;gBACrE;YACF,KAAK;gBACH,IAAIJ,MA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version": "3.47.0-canary.2",
|
|
4
4
|
"description": "Import-Export plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"csv-parse": "^5.6.0",
|
|
65
65
|
"csv-stringify": "^6.5.2",
|
|
66
66
|
"qs-esm": "7.0.2",
|
|
67
|
-
"@payloadcms/
|
|
68
|
-
"@payloadcms/
|
|
67
|
+
"@payloadcms/translations": "3.47.0-canary.2",
|
|
68
|
+
"@payloadcms/ui": "3.47.0-canary.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@payloadcms/ui": "3.47.0-canary.1",
|
|
72
71
|
"@payloadcms/eslint-config": "3.28.0",
|
|
73
|
-
"
|
|
72
|
+
"@payloadcms/ui": "3.47.0-canary.2",
|
|
73
|
+
"payload": "3.47.0-canary.2"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.47.0-canary.
|
|
77
|
-
"payload": "3.47.0-canary.
|
|
76
|
+
"@payloadcms/ui": "3.47.0-canary.2",
|
|
77
|
+
"payload": "3.47.0-canary.2"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"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,EA8D9B,CAAA"}
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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\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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