Skip to content

Commit a8e3095

Browse files
fix: expose server and client props to custom list slot components (#9159)
### What? Adds `serverProps` and `clientProps` to custom list view slot components. ### Why? They were missing and should be exposed. ### How? Created custom types for list slot components and threads them through into `renderListSlots` function and passes them through to each `RenderServerComponent` that renders list view slot components.
1 parent 5ac4e73 commit a8e3095

File tree

4 files changed

+88
-25
lines changed

4 files changed

+88
-25
lines changed

packages/next/src/views/List/index.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { ListPreferences, ListViewClientProps } from '@payloadcms/ui'
1+
import type {
2+
ListComponentClientProps,
3+
ListComponentServerProps,
4+
ListPreferences,
5+
ListViewClientProps,
6+
} from '@payloadcms/ui'
27
import type { AdminViewProps, ListQuery, Where } from 'payload'
38

49
import { DefaultListView, HydrateAuthProvider, ListQueryProvider } from '@payloadcms/ui'
@@ -168,25 +173,43 @@ export const renderListView = async (
168173
? collectionConfig.admin.description({ t: i18n.t })
169174
: collectionConfig.admin.description
170175

176+
const sharedClientProps: ListComponentClientProps = {
177+
collectionSlug,
178+
hasCreatePermission: permissions?.collections?.[collectionSlug]?.create?.permission,
179+
newDocumentURL: formatAdminURL({
180+
adminRoute,
181+
path: `/collections/${collectionSlug}/create`,
182+
}),
183+
}
184+
185+
const sharedServerProps: ListComponentServerProps = {
186+
collectionConfig,
187+
i18n,
188+
limit,
189+
locale: fullLocale,
190+
params,
191+
payload,
192+
permissions,
193+
searchParams,
194+
user,
195+
}
196+
171197
const listViewSlots = renderListViewSlots({
198+
clientProps: sharedClientProps,
172199
collectionConfig,
173200
description: staticDescription,
174201
payload,
202+
serverProps: sharedServerProps,
175203
})
176204

177205
const clientProps: ListViewClientProps = {
178206
...listViewSlots,
179-
collectionSlug,
207+
...sharedClientProps,
180208
columnState,
181209
disableBulkDelete,
182210
disableBulkEdit,
183211
enableRowSelections,
184-
hasCreatePermission: permissions?.collections?.[collectionSlug]?.create?.permission,
185212
listPreferences,
186-
newDocumentURL: formatAdminURL({
187-
adminRoute,
188-
path: `/collections/${collectionSlug}/create`,
189-
}),
190213
renderedFilters,
191214
Table,
192215
}
@@ -211,19 +234,10 @@ export const renderListView = async (
211234
Fallback={DefaultListView}
212235
importMap={payload.importMap}
213236
serverProps={{
214-
collectionConfig,
215-
collectionSlug,
237+
...sharedServerProps,
216238
data,
217-
i18n,
218-
limit,
219239
listPreferences,
220240
listSearchableFields: collectionConfig.admin.listSearchableFields,
221-
locale: fullLocale,
222-
params,
223-
payload,
224-
permissions,
225-
searchParams,
226-
user,
227241
}}
228242
/>
229243
</ListQueryProvider>

packages/next/src/views/List/renderListViewSlots.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,68 @@
1-
import type { ListViewSlots } from '@payloadcms/ui'
1+
import type {
2+
ListComponentClientProps,
3+
ListComponentServerProps,
4+
ListViewSlots,
5+
} from '@payloadcms/ui'
26
import type { Payload, SanitizedCollectionConfig, StaticDescription } from 'payload'
37

48
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'
59

10+
type Args = {
11+
clientProps: ListComponentClientProps
12+
collectionConfig: SanitizedCollectionConfig
13+
description?: StaticDescription
14+
payload: Payload
15+
serverProps: ListComponentServerProps
16+
}
617
export const renderListViewSlots = ({
18+
clientProps,
719
collectionConfig,
820
description,
921
payload,
10-
}: {
11-
collectionConfig: SanitizedCollectionConfig
12-
description?: StaticDescription
13-
payload: Payload
14-
}): ListViewSlots => {
22+
serverProps,
23+
}: Args): ListViewSlots => {
1524
const result: ListViewSlots = {} as ListViewSlots
1625

1726
if (collectionConfig.admin.components?.afterList) {
1827
result.AfterList = (
1928
<RenderServerComponent
29+
clientProps={clientProps}
2030
Component={collectionConfig.admin.components.afterList}
2131
importMap={payload.importMap}
32+
serverProps={serverProps}
2233
/>
2334
)
2435
}
2536

2637
if (collectionConfig.admin.components?.afterListTable) {
2738
result.AfterListTable = (
2839
<RenderServerComponent
40+
clientProps={clientProps}
2941
Component={collectionConfig.admin.components.afterListTable}
3042
importMap={payload.importMap}
43+
serverProps={serverProps}
3144
/>
3245
)
3346
}
3447

3548
if (collectionConfig.admin.components?.beforeList) {
3649
result.BeforeList = (
3750
<RenderServerComponent
51+
clientProps={clientProps}
3852
Component={collectionConfig.admin.components.beforeList}
3953
importMap={payload.importMap}
54+
serverProps={serverProps}
4055
/>
4156
)
4257
}
4358

4459
if (collectionConfig.admin.components?.beforeListTable) {
4560
result.BeforeListTable = (
4661
<RenderServerComponent
62+
clientProps={clientProps}
4763
Component={collectionConfig.admin.components.beforeListTable}
4864
importMap={payload.importMap}
65+
serverProps={serverProps}
4966
/>
5067
)
5168
}
@@ -55,9 +72,11 @@ export const renderListViewSlots = ({
5572
<RenderServerComponent
5673
clientProps={{
5774
description,
75+
...clientProps,
5876
}}
5977
Component={collectionConfig.admin.components.Description}
6078
importMap={payload.importMap}
79+
serverProps={serverProps}
6180
/>
6281
)
6382
}

packages/ui/src/exports/client/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ export {
272272
type ListViewClientProps,
273273
type ListViewSlots,
274274
} from '../../views/List/index.js'
275-
export type { ListPreferences } from '../../views/List/types.js'
275+
export type {
276+
ListComponentClientProps,
277+
ListComponentServerProps,
278+
ListPreferences,
279+
} from '../../views/List/types.js'
276280

277281
export { DefaultEditView } from '../../views/Edit/index.js'
278282
export { SetDocumentStepNav } from '../../views/Edit/SetDocumentStepNav/index.js'

packages/ui/src/views/List/types.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import type { SanitizedCollectionConfig } from 'payload'
1+
import type { I18n } from '@payloadcms/translations'
2+
import type {
3+
AdminViewProps,
4+
Locale,
5+
Payload,
6+
Permissions,
7+
SanitizedCollectionConfig,
8+
User,
9+
} from 'payload'
210

311
import type { ColumnPreferences } from '../../providers/ListQuery/index.js'
412

@@ -16,3 +24,21 @@ export type ListPreferences = {
1624
limit: number
1725
sort: string
1826
}
27+
28+
export type ListComponentClientProps = {
29+
collectionSlug: SanitizedCollectionConfig['slug']
30+
hasCreatePermission: boolean
31+
newDocumentURL: string
32+
}
33+
34+
export type ListComponentServerProps = {
35+
collectionConfig: SanitizedCollectionConfig
36+
i18n: I18n
37+
limit: number
38+
locale: Locale
39+
params: AdminViewProps['params']
40+
payload: Payload
41+
permissions: Permissions
42+
searchParams: AdminViewProps['searchParams']
43+
user: User
44+
}

0 commit comments

Comments
 (0)