Skip to content

Commit ac3cbe6

Browse files
committed
feat(plugin-import-export): working on adding page arg and other improvements
1 parent f6afda8 commit ac3cbe6

File tree

7 files changed

+38
-6
lines changed

7 files changed

+38
-6
lines changed

packages/plugin-import-export/src/components/Preview/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const Preview = () => {
2828
const { collection } = useImportExport()
2929
const { config } = useConfig()
3030
const { value: where } = useField({ path: 'where' })
31+
const { value: page } = useField({ path: 'page' })
3132
const { value: limit } = useField<number>({ path: 'limit' })
3233
const { value: fields } = useField<string[]>({ path: 'fields' })
3334
const { value: sort } = useField({ path: 'sort' })
@@ -71,6 +72,7 @@ export const Preview = () => {
7172
format,
7273
limit,
7374
locale,
75+
page,
7476
sort,
7577
where,
7678
}),
@@ -168,6 +170,7 @@ export const Preview = () => {
168170
i18n,
169171
limit,
170172
locale,
173+
page,
171174
sort,
172175
where,
173176
])

packages/plugin-import-export/src/export/createExport.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export type Export = {
2323
format: 'csv' | 'json'
2424
globals?: string[]
2525
id: number | string
26+
limit?: number
2627
locale?: string
2728
name: string
29+
page?: number
2830
slug: string
2931
sort: Sort
3032
user: string
@@ -57,6 +59,8 @@ export const createExport = async (args: CreateExportArgs) => {
5759
locale: localeInput,
5860
sort,
5961
user,
62+
page,
63+
limit,
6064
where,
6165
},
6266
req: { locale: localeArg, payload },

packages/plugin-import-export/src/export/getFields.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const getFields = (config: Config, pluginConfig?: ImportExportPluginConfi
1111
name: 'locale',
1212
type: 'select',
1313
admin: {
14-
width: '33%',
14+
width: '180px',
1515
},
1616
defaultValue: 'all',
1717
// @ts-expect-error - this is not correctly typed in plugins right now
@@ -49,7 +49,7 @@ export const getFields = (config: Config, pluginConfig?: ImportExportPluginConfi
4949
admin: {
5050
// Hide if a forced format is set via plugin config
5151
condition: () => !pluginConfig?.format,
52-
width: '33%',
52+
width: '180px',
5353
},
5454
defaultValue: (() => {
5555
// Default to plugin-defined format, otherwise 'csv'
@@ -74,11 +74,24 @@ export const getFields = (config: Config, pluginConfig?: ImportExportPluginConfi
7474
type: 'number',
7575
admin: {
7676
placeholder: 'No limit',
77-
width: '33%',
77+
width: '180px',
7878
},
7979
// @ts-expect-error - this is not correctly typed in plugins right now
8080
label: ({ t }) => t('plugin-import-export:field-limit-label'),
8181
},
82+
{
83+
name: 'page',
84+
type: 'number',
85+
admin: {
86+
condition: ({ limit }) => {
87+
return typeof limit === 'number' && limit !== 0
88+
},
89+
width: '180px',
90+
},
91+
defaultValue: 1,
92+
// @ts-expect-error - this is not correctly typed in plugins right now
93+
label: ({ t }) => t('plugin-import-export:field-page-label'),
94+
},
8295
{
8396
name: 'sort',
8497
type: 'text',
@@ -109,7 +122,7 @@ export const getFields = (config: Config, pluginConfig?: ImportExportPluginConfi
109122
collectionConfig?.versions?.drafts,
110123
)
111124
},
112-
width: '33%',
125+
width: '180px',
113126
},
114127
defaultValue: 'yes',
115128
// @ts-expect-error - this is not correctly typed in plugins right now
@@ -163,6 +176,7 @@ export const getFields = (config: Config, pluginConfig?: ImportExportPluginConfi
163176
value: 'all',
164177
},
165178
],
179+
virtual: true,
166180
},
167181
{
168182
name: 'fields',

packages/plugin-import-export/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const importExportPlugin =
6363
path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',
6464
})
6565

66-
// // Find fields explicitly marked as disabled for import/export
66+
// Find fields explicitly marked as disabled for import/export
6767
const disabledFieldAccessors = collectDisabledFieldPaths(collection.fields)
6868

6969
// Store disabled field accessors in the admin config for use in the UI
@@ -90,13 +90,14 @@ export const importExportPlugin =
9090
handler: async (req) => {
9191
await addDataAndFileToRequest(req)
9292

93-
const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {
93+
const { collectionSlug, draft, fields, limit, locale, page, sort, where } = req.data as {
9494
collectionSlug: string
9595
draft?: 'no' | 'yes'
9696
fields?: string[]
9797
format?: 'csv' | 'json'
9898
limit?: number
9999
locale?: string
100+
page?: number
100101
sort?: any
101102
where?: any
102103
}
@@ -118,6 +119,7 @@ export const importExportPlugin =
118119
limit: limit && limit > 10 ? 10 : limit,
119120
locale,
120121
overrideAccess: false,
122+
page,
121123
req,
122124
select,
123125
sort,

packages/plugin-import-export/src/translations/languages/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const enTranslations = {
1111
'field-limit-label': 'Limit',
1212
'field-locale-label': 'Locale',
1313
'field-name-label': 'File name',
14+
'field-page-label': 'Page',
1415
'field-selectionToUse-label': 'Selection to use',
1516
'field-sort-label': 'Sort by',
1617
'selectionToUse-allDocuments': 'Use all documents',

packages/plugin-import-export/src/translations/languages/translation-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
"field-name-label": {
5050
"type": "string"
5151
},
52+
"field-page-label": {
53+
"type": "string"
54+
},
5255
"field-selectionToUse-label": {
5356
"type": "string"
5457
},

test/plugin-import-export/payload-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ export interface Export {
267267
name?: string | null;
268268
format?: ('csv' | 'json') | null;
269269
limit?: number | null;
270+
page?: number | null;
270271
sort?: string | null;
271272
locale?: ('all' | 'en' | 'es' | 'de') | null;
272273
drafts?: ('yes' | 'no') | null;
@@ -303,6 +304,7 @@ export interface ExportsTask {
303304
name?: string | null;
304305
format?: ('csv' | 'json') | null;
305306
limit?: number | null;
307+
page?: number | null;
306308
sort?: string | null;
307309
locale?: ('all' | 'en' | 'es' | 'de') | null;
308310
drafts?: ('yes' | 'no') | null;
@@ -603,6 +605,7 @@ export interface ExportsSelect<T extends boolean = true> {
603605
name?: T;
604606
format?: T;
605607
limit?: T;
608+
page?: T;
606609
sort?: T;
607610
locale?: T;
608611
drafts?: T;
@@ -630,6 +633,7 @@ export interface ExportsTasksSelect<T extends boolean = true> {
630633
name?: T;
631634
format?: T;
632635
limit?: T;
636+
page?: T;
633637
sort?: T;
634638
locale?: T;
635639
drafts?: T;
@@ -721,6 +725,7 @@ export interface TaskCreateCollectionExport {
721725
name?: string | null;
722726
format?: ('csv' | 'json') | null;
723727
limit?: number | null;
728+
page?: number | null;
724729
sort?: string | null;
725730
locale?: ('all' | 'en' | 'es' | 'de') | null;
726731
drafts?: ('yes' | 'no') | null;

0 commit comments

Comments
 (0)