fix(ui): ensure field components safely access field.admin property (#7670)

This commit is contained in:
Alessio Gravili
2024-08-14 12:06:01 -04:00
committed by GitHub
parent dc496e4387
commit c65f5027d6
18 changed files with 25 additions and 21 deletions

View File

@@ -40,7 +40,7 @@ const RichTextComponent: React.FC<
readOnly: readOnlyFromAdmin, readOnly: readOnlyFromAdmin,
style, style,
width, width,
}, } = {},
label, label,
required, required,
}, },

View File

@@ -17,7 +17,7 @@ const RichTextEditor = lazy(() =>
export const RichTextField: React.FC<LexicalRichTextFieldProps> = (props) => { export const RichTextField: React.FC<LexicalRichTextFieldProps> = (props) => {
const { const {
admin, admin = {},
field: { richTextComponentMap }, field: { richTextComponentMap },
lexicalEditorConfig, lexicalEditorConfig,
} = props } = props

View File

@@ -64,7 +64,7 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
readOnly: readOnlyFromAdmin, readOnly: readOnlyFromAdmin,
style, style,
width, width,
}, } = {},
label, label,
required, required,
}, },

View File

@@ -43,7 +43,7 @@ export const ArrayFieldComponent: React.FC<ArrayFieldProps> = (props) => {
description, description,
isSortable = true, isSortable = true,
readOnly: readOnlyFromAdmin, readOnly: readOnlyFromAdmin,
}, } = {},
fields, fields,
label, label,
localized, localized,

View File

@@ -42,7 +42,7 @@ const BlocksFieldComponent: React.FC<BlockFieldProps> = (props) => {
field: { field: {
name, name,
_path: pathFromProps, _path: pathFromProps,
admin: { className, description, isSortable = true, readOnly: readOnlyFromAdmin }, admin: { className, description, isSortable = true, readOnly: readOnlyFromAdmin } = {},
blocks, blocks,
label, label,
labels: labelsFromProps, labels: labelsFromProps,

View File

@@ -37,7 +37,7 @@ const CodeFieldComponent: React.FC<CodeFieldProps> = (props) => {
readOnly: readOnlyFromAdmin, readOnly: readOnlyFromAdmin,
style, style,
width, width,
}, } = {},
label, label,
required, required,
}, },

View File

@@ -27,7 +27,7 @@ const CollapsibleFieldComponent: React.FC<CollapsibleFieldProps> = (props) => {
field, field,
field: { field: {
_path: pathFromProps, _path: pathFromProps,
admin: { className, description, initCollapsed = false, readOnly: readOnlyFromAdmin }, admin: { className, description, initCollapsed = false, readOnly: readOnlyFromAdmin } = {},
fields, fields,
label, label,
}, },

View File

@@ -35,7 +35,7 @@ const DateTimeFieldComponent: React.FC<DateFieldProps> = (props) => {
readOnly: readOnlyFromAdmin, readOnly: readOnlyFromAdmin,
style, style,
width, width,
}, } = {},
label, label,
required, required,
}, },

View File

@@ -32,7 +32,7 @@ export const GroupFieldComponent: React.FC<GroupFieldProps> = (props) => {
descriptionProps, descriptionProps,
field, field,
field: { field: {
admin: { className, description, hideGutter, readOnly: readOnlyFromAdmin, style, width }, admin: { className, description, hideGutter, readOnly: readOnlyFromAdmin, style, width } = {},
fields, fields,
label, label,
}, },

View File

@@ -25,7 +25,14 @@ const JSONFieldComponent: React.FC<JSONFieldProps> = (props) => {
field: { field: {
name, name,
_path: pathFromProps, _path: pathFromProps,
admin: { className, description, editorOptions, readOnly: readOnlyFromAdmin, style, width }, admin: {
className,
description,
editorOptions,
readOnly: readOnlyFromAdmin,
style,
width,
} = {},
jsonSchema, jsonSchema,
label, label,
required, required,

View File

@@ -34,7 +34,7 @@ export const PointFieldComponent: React.FC<PointFieldProps> = (props) => {
step, step,
style, style,
width, width,
}, } = {},
label, label,
required, required,
}, },

View File

@@ -50,7 +50,7 @@ const RelationshipFieldComponent: React.FC<RelationshipFieldProps> = (props) =>
sortOptions, sortOptions,
style, style,
width, width,
}, } = {},
hasMany, hasMany,
label, label,
relationTo, relationTo,

View File

@@ -16,10 +16,7 @@ const baseClass = 'row'
const RowFieldComponent: React.FC<RowFieldProps> = (props) => { const RowFieldComponent: React.FC<RowFieldProps> = (props) => {
const { const {
field: { field: { admin: { className } = {}, fields },
admin: { className },
fields,
},
forceRender = false, forceRender = false,
} = props } = props

View File

@@ -27,7 +27,7 @@ const TabsFieldComponent: React.FC<TabsFieldProps> = (props) => {
field, field,
field: { field: {
_path: pathFromProps, _path: pathFromProps,
admin: { className, readOnly: readOnlyFromAdmin }, admin: { className, readOnly: readOnlyFromAdmin } = {},
tabs = [], tabs = [],
}, },
forceRender = false, forceRender = false,

View File

@@ -31,7 +31,7 @@ const TextFieldComponent: React.FC<TextFieldProps> = (props) => {
rtl, rtl,
style, style,
width, width,
}, } = {},
hasMany, hasMany,
label, label,
localized, localized,

View File

@@ -32,7 +32,7 @@ const TextareaFieldComponent: React.FC<TextareaFieldProps> = (props) => {
rtl, rtl,
style, style,
width, width,
}, } = {},
label, label,
localized, localized,
maxLength, maxLength,

View File

@@ -22,7 +22,7 @@ const UploadComponent: React.FC<UploadFieldProps> = (props) => {
field, field,
field: { field: {
_path: pathFromProps, _path: pathFromProps,
admin: { className, readOnly: readOnlyFromAdmin, style, width }, admin: { className, readOnly: readOnlyFromAdmin, style, width } = {},
label, label,
relationTo, relationTo,
required, required,

View File

@@ -37,7 +37,7 @@
], ],
"paths": { "paths": {
"@payload-config": [ "@payload-config": [
"./test/fields/config.ts" "./test/_community/config.ts"
], ],
"@payloadcms/live-preview": [ "@payloadcms/live-preview": [
"./packages/live-preview/src" "./packages/live-preview/src"