@@ -58,25 +58,29 @@ export function ContentRelationshipFieldPicker(
5858 </ Box >
5959 < TreeView
6060 title = "Exposed fields"
61- subtitle = { `(${ getTotalExposedFields ( customTypes ) } )` }
61+ subtitle = { `(${ countExposedFields ( form . values ) } )` }
6262 >
63- { customTypes . map ( ( ct ) => (
64- < TreeViewSection
65- key = { ct . id }
66- title = { ct . label }
67- subtitle = { `(${ ct . fields . length } fields exposed)` }
68- badge = "Custom Type"
69- >
70- { ct . fields . map ( ( field ) => (
71- < TreeViewCheckboxField
72- key = { field . id }
73- id = { field . id }
74- title = { field . label }
75- customTypeId = { ct . id }
76- />
77- ) ) }
78- </ TreeViewSection >
79- ) ) }
63+ { customTypes . map ( ( ct ) => {
64+ const count = countExposedFields ( form . values [ ct . id ] ) ;
65+
66+ return (
67+ < TreeViewSection
68+ key = { ct . id }
69+ title = { ct . label }
70+ subtitle = { count > 0 ? `(${ count } fields exposed)` : undefined }
71+ badge = "Custom Type"
72+ >
73+ { ct . fields . map ( ( field ) => (
74+ < TreeViewCheckboxField
75+ key = { field . id }
76+ id = { field . id }
77+ title = { field . label }
78+ customTypeId = { ct . id }
79+ />
80+ ) ) }
81+ </ TreeViewSection >
82+ ) ;
83+ } ) }
8084 </ TreeView >
8185 </ Box >
8286 < Box backgroundColor = "white" flexDirection = "column" padding = { 12 } >
@@ -146,8 +150,19 @@ function useCustomTypes() {
146150 return simplifiedCustomTypes ;
147151}
148152
149- function getTotalExposedFields ( customTypes : SimplifiedCustomType [ ] ) {
150- return customTypes . reduce ( ( acc , ct ) => acc + ct . fields . length , 0 ) ;
153+ function countExposedFields ( fields : CustomTypeFieldMap | FieldMap | undefined ) {
154+ if ( ! fields ) return 0 ;
155+
156+ return Object . values ( fields ) . reduce < number > (
157+ ( acc , value : boolean | FieldMap ) => {
158+ if ( typeof value === "boolean" ) {
159+ return acc + ( value ? 1 : 0 ) ;
160+ }
161+
162+ return acc + Object . values ( value ) . filter ( Boolean ) . length ;
163+ } ,
164+ 0 ,
165+ ) ;
151166}
152167
153168function getInitialValues ( value : CustomTypeFields ) {
0 commit comments