@@ -61,6 +61,7 @@ interface MultipleFieldToolbarProps {
6161}
6262
6363function handleReplaceAsset ( fieldMetadata : CslpData ) {
64+ // TODO avoid sending whole fieldMetadata
6465 visualBuilderPostMessage ?. send (
6566 VisualBuilderPostMessageEvents . OPEN_ASSET_MODAL ,
6667 {
@@ -123,7 +124,9 @@ function FieldToolbarComponent(
123124 const [ displayAllApps , setDisplayAllApps ] = useState ( false ) ;
124125 const moreButtonRef = useRef < HTMLButtonElement > ( null ) ;
125126 const toolbarRef = useRef < HTMLDivElement > ( null ) ;
126- const [ appListPosition , setAppListPosition ] = useState < "left" | "right" > ( "right" ) ;
127+ const [ appListPosition , setAppListPosition ] = useState < "left" | "right" > (
128+ "right"
129+ ) ;
127130
128131 const parentPath =
129132 fieldMetadata ?. multipleFieldMetadata ?. parentDetails ?. parentCslpValue ||
@@ -168,6 +171,13 @@ function FieldToolbarComponent(
168171 isMultiple = ( fieldSchema as IReferenceContentTypeSchema )
169172 . field_metadata . ref_multiple ;
170173
174+ // field is multiple but an instance is not selected
175+ // instead the whole field (all instances) is selected.
176+ // Currently, when whole featured_blogs is selected in canvas,
177+ // the fieldPathWithIndex and instance.fieldPathWithIndex are the same
178+ // cannot rely on -1 index, as the non-negative index then refers to the index of
179+ // the featured_blogs block in page_components
180+ // It is not needed except taxanomy.
171181 isWholeMultipleField =
172182 isMultiple &&
173183 ( fieldMetadata . fieldPathWithIndex ===
@@ -176,29 +186,33 @@ function FieldToolbarComponent(
176186
177187 isReplaceAllowed =
178188 ALLOWED_REPLACE_FIELDS . includes ( fieldType ) && ! isWholeMultipleField ;
189+ // if (
190+ // DEFAULT_MULTIPLE_FIELDS.includes(fieldType) &&
191+ // isWholeMultipleField &&
192+ // !isVariant
193+ // ) {
194+ // return null;
195+ // }
179196 }
180197
181198 const invertTooltipPosition =
182199 targetElement . getBoundingClientRect ( ) . top <= TOOLTIP_TOP_EDGE_BUFFER ;
183200
184201 const handleMoreIconClick = ( ) => {
185-
186-
187- if ( toolbarRef . current ) {
188- const rect = toolbarRef . current . getBoundingClientRect ( ) ;
189- const spaceRight = window . innerWidth - rect . right ;
190- const spaceLeft = rect . left ;
191- let position = '' ;
192-
193- if ( spaceRight < APP_LIST_MIN_WIDTH ) {
194- position = "left" ;
195- } else if ( spaceRight > APP_LIST_MIN_WIDTH ) {
196- position = "right" ;
197- } else {
198- position = spaceRight > spaceLeft ? "right" : "left" ;
202+ if ( toolbarRef . current ) {
203+ const rect = toolbarRef . current . getBoundingClientRect ( ) ;
204+ const spaceRight = window . innerWidth - rect . right ;
205+ const spaceLeft = rect . left ;
206+ let position = "" ;
207+
208+ if ( spaceRight < APP_LIST_MIN_WIDTH ) {
209+ position = "left" ;
210+ } else if ( spaceRight > APP_LIST_MIN_WIDTH ) {
211+ position = "right" ;
212+ } else {
213+ position = spaceRight > spaceLeft ? "right" : "left" ;
199214 }
200215 setAppListPosition ( position as "left" | "right" ) ;
201-
202216 }
203217
204218 setDisplayAllApps ( ! displayAllApps ) ;
@@ -221,6 +235,8 @@ function FieldToolbarComponent(
221235 ) }
222236 data-tooltip = { "Edit" }
223237 onClick = { ( e ) => {
238+ // TODO the listener for field path is attached to the common parent requiring
239+ // propagation to be stopped, should ideally only attach onClick to fieldpath dropdown
224240 e . preventDefault ( ) ;
225241 e . stopPropagation ( ) ;
226242 handleEdit ( fieldMetadata ) ;
@@ -331,16 +347,13 @@ function FieldToolbarComponent(
331347 </ button >
332348 ) ;
333349
334-
335-
336-
337-
350+ // TODO sibling count is incorrect for this purpose
338351
339352 const totalElementCount = targetElement ?. parentNode ?. childElementCount ?? 1 ;
340353 const indexOfElement = fieldMetadata ?. multipleFieldMetadata ?. index ;
341354
342- const disableMoveLeft = indexOfElement === 0 ;
343- const disableMoveRight = indexOfElement === totalElementCount - 1 ;
355+ const disableMoveLeft = indexOfElement === 0 ; // first element
356+ const disableMoveRight = indexOfElement === totalElementCount - 1 ; // last element
344357
345358 useEffect ( ( ) => {
346359 async function fetchFieldSchema ( ) {
@@ -377,18 +390,16 @@ function FieldToolbarComponent(
377390
378391 useEffect ( ( ) => {
379392 const event = visualBuilderPostMessage ?. on (
380- VisualBuilderPostMessageEvents . FIELD_LOCATION_DATA ,
393+ VisualBuilderPostMessageEvents . FIELD_LOCATION_DATA ,
381394 ( data : { data : any } ) => {
382- setFieldLocationData ( data . data . fieldLocationData ) ;
395+ setFieldLocationData ( data . data . fieldLocationData ) ;
383396 }
384397 ) ;
385398 return ( ) => {
386399 event ?. unregister ( ) ;
387400 } ;
388401 } , [ ] ) ;
389402
390-
391-
392403 const multipleFieldToolbarButtonClasses = classNames (
393404 "visual-builder__button visual-builder__button--secondary" ,
394405 visualBuilderStyles ( ) [ "visual-builder__button" ] ,
@@ -401,9 +412,6 @@ function FieldToolbarComponent(
401412 }
402413 ) ;
403414
404-
405-
406-
407415 return (
408416 < div
409417 className = { classNames (
@@ -554,13 +562,24 @@ function FieldToolbarComponent(
554562 </ >
555563 ) }
556564
557- < FieldLocationIcon fieldLocationData = { fieldLocationData } multipleFieldToolbarButtonClasses = { multipleFieldToolbarButtonClasses } handleMoreIconClick = { handleMoreIconClick } moreButtonRef = { moreButtonRef } toolbarRef = { toolbarRef } />
558-
565+ < FieldLocationIcon
566+ fieldLocationData = { fieldLocationData }
567+ multipleFieldToolbarButtonClasses = {
568+ multipleFieldToolbarButtonClasses
569+ }
570+ handleMoreIconClick = { handleMoreIconClick }
571+ moreButtonRef = { moreButtonRef }
572+ toolbarRef = { toolbarRef }
573+ />
559574 </ >
560575 </ div >
561576 </ div >
562577 { displayAllApps && (
563- < FieldLocationAppList toolbarRef = { toolbarRef } apps = { fieldLocationData ?. apps || [ ] as any [ ] } position = { appListPosition } />
578+ < FieldLocationAppList
579+ toolbarRef = { toolbarRef }
580+ apps = { fieldLocationData ?. apps || ( [ ] as any [ ] ) }
581+ position = { appListPosition }
582+ />
564583 ) }
565584 </ div >
566585 ) ;
0 commit comments