Skip to content

Commit 49a2d70

Browse files
authored
feat: allow passing false as PayloadComponent which signals that the component should not be rendered (#7682)
If it's undefined/null => Fallback Component may be rendered If it's false => No component should be rendered - as if an empty component was passed in This ensures that the user does not have to install `@payloadcms/ui` anymore, which previously exported an empty component to be used in component paths
1 parent cb7fa00 commit 49a2d70

File tree

15 files changed

+41
-18
lines changed

15 files changed

+41
-18
lines changed

packages/payload/src/admin/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,13 @@ export type MappedClientComponent<TComponentClientProps extends JsonObject = Jso
227227
type: 'client'
228228
}
229229

230+
export type MappedEmptyComponent = {
231+
type: 'empty'
232+
}
233+
230234
export type MappedComponent<TComponentClientProps extends JsonObject = JsonObject> =
231235
| MappedClientComponent<TComponentClientProps>
236+
| MappedEmptyComponent
232237
| MappedServerComponent<TComponentClientProps>
233238
| undefined
234239

packages/payload/src/auth/baseFields/apiKey.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const apiKeyFields = [
1313
type: 'checkbox',
1414
admin: {
1515
components: {
16-
Field: '@payloadcms/ui/shared#emptyComponent',
16+
Field: false,
1717
},
1818
},
1919
label: ({ t }) => t('authentication:enableAPIKey'),
@@ -23,7 +23,7 @@ export const apiKeyFields = [
2323
type: 'text',
2424
admin: {
2525
components: {
26-
Field: '@payloadcms/ui/shared#emptyComponent',
26+
Field: false,
2727
},
2828
},
2929
hooks: {

packages/payload/src/auth/baseFields/email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const emailFieldConfig: EmailField = {
77
type: 'email',
88
admin: {
99
components: {
10-
Field: '@payloadcms/ui/shared#emptyComponent',
10+
Field: false,
1111
},
1212
},
1313
hooks: {

packages/payload/src/auth/baseFields/username.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const usernameFieldConfig: TextField = {
77
type: 'text',
88
admin: {
99
components: {
10-
Field: '@payloadcms/ui/shared#emptyComponent',
10+
Field: false,
1111
},
1212
},
1313
hooks: {

packages/payload/src/auth/baseFields/verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const verificationFields: Field[] = [
2626
},
2727
admin: {
2828
components: {
29-
Field: '@payloadcms/ui/shared#emptyComponent',
29+
Field: false,
3030
},
3131
},
3232
label: ({ t }) => t('authentication:verified'),

packages/payload/src/bin/generateImportMap/parsePayloadComponent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export function parsePayloadComponent(payloadComponent: PayloadComponent): {
44
exportName: string
55
path: string
66
} {
7+
if (!payloadComponent) {
8+
return null
9+
}
710
const pathAndMaybeExport =
811
typeof payloadComponent === 'string' ? payloadComponent : payloadComponent.path
912

packages/payload/src/config/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { default as sharp } from 'sharp'
1313
import type { DeepRequired } from 'ts-essentials'
1414

1515
import type { RichTextAdapterProvider } from '../admin/RichText.js'
16-
import type { DocumentTabConfig, MappedComponent, RichTextAdapter } from '../admin/types.js'
16+
import type { DocumentTabConfig, RichTextAdapter } from '../admin/types.js'
1717
import type { AdminViewConfig, ServerSideEditViewProps } from '../admin/views/types.js'
1818
import type { Permissions } from '../auth/index.js'
1919
import type {
@@ -38,12 +38,12 @@ import type { PayloadLogger } from '../utilities/logger.js'
3838
/**
3939
* The string path pointing to the React component. If one of the generics is `never`, you effectively mark it as a server-only or client-only component.
4040
*
41-
* If the path is an empty string, it will be treated as () => null
41+
* If it is `false` an empty component will be rendered.
4242
*/
4343
export type PayloadComponent<
4444
TComponentServerProps extends never | object = Record<string, any>,
4545
TComponentClientProps extends never | object = Record<string, any>,
46-
> = RawPayloadComponent<TComponentServerProps, TComponentClientProps> | string
46+
> = RawPayloadComponent<TComponentServerProps, TComponentClientProps> | false | string
4747

4848
// We need the actual object as its own type, otherwise the infers for the PayloadClientReactComponent / PayloadServerReactComponent will not work due to the string union.
4949
// We also NEED to actually use those generics for this to work, thus they are part of the props.

packages/payload/src/versions/baseFields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const baseVersionFields: Field[] = [
1717
type: 'select',
1818
admin: {
1919
components: {
20-
Field: '@payloadcms/ui/shared#emptyComponent',
20+
Field: false,
2121
},
2222
disableBulkEdit: true,
2323
},

packages/richtext-slate/src/field/elements/textAlign/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import type { RichTextCustomElement } from '../../../types.js'
33
export const textAlign: RichTextCustomElement = {
44
name: 'alignment',
55
Button: '@payloadcms/richtext-slate/client#TextAlignElementButton',
6-
Element: '@payloadcms/ui/shared#emptyComponent',
6+
Element: false,
77
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@ export {
2121
} from '../../utilities/groupNavItems.js'
2222
export { hasSavePermission } from '../../utilities/hasSavePermission.js'
2323
export { isEditing } from '../../utilities/isEditing.js'
24-
25-
export const emptyComponent = () => null

0 commit comments

Comments
 (0)