@@ -8,14 +8,18 @@ import { ConditionalWrapper } from '@components/ConditionalWrapper';
88import { useInputsState , useProfileState , useUIState } from '@src/store' ;
99import { Labels } from './Labels' ;
1010import { Values } from './Values' ;
11+ import { ChildFields } from './ChildFields' ;
1112
12- const checkShouldGroupWrap = ( level : number , entry = { } as SchemaEntry ) => {
13+ export const checkShouldGroupWrap = ( level : number , entry = { } as SchemaEntry ) => {
1314 const { children, type } = entry ;
1415
15- return ( ! children ?. length || type === AdvancedFieldType . dropdown ) && level !== GROUP_BY_LEVEL ;
16+ return ( ! children ?. length || type === AdvancedFieldType . dropdown || type === AdvancedFieldType . group ) &&
17+ type === AdvancedFieldType . group
18+ ? level === GROUP_BY_LEVEL
19+ : level !== GROUP_BY_LEVEL ;
1620} ;
1721
18- const getPreviewWrapper =
22+ export const getPreviewWrapper =
1923 ( {
2024 isBlock,
2125 wrapEntities,
@@ -38,7 +42,7 @@ const getPreviewWrapper =
3842 </ div >
3943 ) ;
4044
41- const getValueGroupWrapper =
45+ export const getValueGroupWrapper =
4246 ( { schemaEntry } : { schemaEntry ?: SchemaEntry } ) =>
4347 ( { children } : { children : ReactNode } ) =>
4448 children ? (
@@ -85,12 +89,15 @@ export const Fields = ({
8589 const hasEmptyChildren = checkEmptyChildren ( base , entry ) ;
8690
8791 const isDependentDropdownOption =
88- entry ?. type === AdvancedFieldType . dropdownOption && ! ! schema . get ( getParentEntryUuid ( entry ?. path ) ) ?. linkedEntry ?. controlledBy ;
92+ entry ?. type === AdvancedFieldType . dropdownOption &&
93+ ! ! schema . get ( getParentEntryUuid ( entry ?. path ) ) ?. linkedEntry ?. controlledBy ;
8994
9095 const controlledEntry = schema . get ( getParentEntryUuid ( entry ?. path || [ ] ) ) ?. linkedEntry ?. controlledBy ;
9196 const controlledEntryValue = controlledEntry ? userValues [ controlledEntry ] : undefined ;
9297 const visibleDropdownOption =
93- isDependentDropdownOption && controlledEntryValue && selectedEntries . includes ( uuid ) ? < div > { entry ?. displayName } </ div > : null ;
98+ isDependentDropdownOption && controlledEntryValue && selectedEntries . includes ( uuid ) ? (
99+ < div > { entry ?. displayName } </ div >
100+ ) : null ;
94101
95102 if ( visibleDropdownOption ) return visibleDropdownOption ;
96103
@@ -104,6 +111,8 @@ export const Fields = ({
104111 // don't render top level entities not selected for preview
105112 if ( isEntity && ! currentlyPreviewedEntityBfid . has ( bfid ) && ! forceRenderAllTopLevelEntities ) return null ;
106113
114+ const isGroupParentEntryType = base . get ( entry . path [ entry . path . length - 2 ] ) ?. type === AdvancedFieldType . group ;
115+
107116 const {
108117 isGroupable,
109118 shouldRenderLabelOrPlaceholders,
@@ -128,9 +137,31 @@ export const Fields = ({
128137 forceRenderAllTopLevelEntities,
129138 } ) ;
130139
140+ const renderChildren = ( children : string [ ] | undefined , isGroup = false ) => {
141+ return (
142+ < ChildFields
143+ schema = { base }
144+ entryChildren = { children }
145+ paths = { paths }
146+ level = { level }
147+ altSchema = { altSchema }
148+ altUserValues = { altUserValues }
149+ altSelectedEntries = { altSelectedEntries }
150+ altDisplayNames = { altDisplayNames }
151+ hideEntities = { hideEntities }
152+ forceRenderAllTopLevelEntities = { forceRenderAllTopLevelEntities }
153+ isGroupable = { isGroupable }
154+ isGroup = { isGroup }
155+ />
156+ ) ;
157+ } ;
158+
131159 return (
132160 < ConditionalWrapper
133- condition = { isBlock || isBlockContents || wrapEntities }
161+ condition = {
162+ ( ( isBlock || isBlockContents || wrapEntities ) && ! isGroupParentEntryType ) ||
163+ entry . type === AdvancedFieldType . group
164+ }
134165 wrapper = { getPreviewWrapper ( { isBlock, isBlockContents, wrapEntities } ) }
135166 >
136167 { shouldRenderLabelOrPlaceholders && (
@@ -152,31 +183,13 @@ export const Fields = ({
152183 htmlId = { htmlId }
153184 />
154185 ) }
155- { children ?. map ( uuid => {
156- const schemaEntry = schema . get ( uuid ) ;
157-
158- return (
159- < ConditionalWrapper
160- key = { uuid }
161- condition = { ! isGroupable && checkShouldGroupWrap ( level , schemaEntry ) }
162- wrapper = { getValueGroupWrapper ( { schemaEntry } ) }
163- >
164- < Fields
165- key = { uuid }
166- uuid = { uuid }
167- base = { base }
168- paths = { paths }
169- level = { level + 1 }
170- altSchema = { altSchema }
171- altUserValues = { altUserValues }
172- altSelectedEntries = { altSelectedEntries }
173- altDisplayNames = { altDisplayNames }
174- hideEntities = { hideEntities }
175- forceRenderAllTopLevelEntities = { forceRenderAllTopLevelEntities }
176- />
177- </ ConditionalWrapper >
178- ) ;
179- } ) }
186+ { entry . type === AdvancedFieldType . group ? (
187+ < div className = "preview-block-contents" data-testid = "preview-fields" >
188+ { renderChildren ( children , true ) }
189+ </ div >
190+ ) : (
191+ renderChildren ( children )
192+ ) }
180193 </ ConditionalWrapper >
181194 ) ;
182195} ;
0 commit comments