File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed
packages/ui/src/forms/Form Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 1
1
import { type FormField , type FormState } from 'payload'
2
- import { deepCopyObjectComplex } from 'payload/shared'
3
2
4
3
type BlacklistedKeys = 'customComponents' | 'validate'
5
4
const blacklistedKeys : BlacklistedKeys [ ] = [ 'validate' , 'customComponents' ]
6
5
7
6
const sanitizeField = ( incomingField : FormField ) : FormField => {
8
- const field = deepCopyObjectComplex ( incomingField )
7
+ const field = { ... incomingField } // shallow copy, as we only need to remove top-level keys
9
8
10
- blacklistedKeys . forEach ( ( key ) => {
9
+ for ( const key of blacklistedKeys ) {
11
10
delete field [ key ]
12
- } )
11
+ }
13
12
14
13
return field
15
14
}
16
15
17
- /*
18
- Takes in FormState and removes fields that are not serializable.
19
- Returns FormState without blacklisted keys.
20
- * */
16
+ /**
17
+ * Takes in FormState and removes fields that are not serializable.
18
+ * Returns FormState without blacklisted keys.
19
+ */
21
20
export const reduceToSerializableFields = (
22
21
fields : FormState ,
23
22
) : {
24
23
[ key : string ] : Omit < FormField , BlacklistedKeys >
25
24
} => {
26
- return Object . keys ( fields ) . reduce (
27
- ( acc , key ) => {
28
- acc [ key ] = sanitizeField ( fields [ key ] )
29
- return acc
30
- } ,
31
- { } as {
32
- [ key : string ] : Omit < FormField , BlacklistedKeys >
33
- } ,
34
- )
25
+ const result : Record < string , Omit < FormField , BlacklistedKeys > > = { }
26
+
27
+ for ( const key in fields ) {
28
+ result [ key ] = sanitizeField ( fields [ key ] )
29
+ }
30
+
31
+ return result
35
32
}
You can’t perform that action at this time.
0 commit comments