@@ -34,12 +34,12 @@ import { getDOMEditStack } from "../utils/getCsDataOfElement";
3434import { VariantIcon } from "./icons/variant" ;
3535import {
3636 BASE_VARIANT_STATUS ,
37- FieldRevertComponent ,
3837 getFieldVariantStatus ,
3938 IVariantStatus ,
4039 VariantRevertDropdown ,
4140} from "./FieldRevert/FieldRevertComponent" ;
4241import { LoadingIcon } from "./icons/loading" ;
42+ import { EntryPermissions } from "../utils/getEntryPermissions" ;
4343
4444export type FieldDetails = Pick <
4545 VisualBuilderCslpEventDetails ,
@@ -52,6 +52,7 @@ interface MultipleFieldToolbarProps {
5252 eventDetails : VisualBuilderCslpEventDetails ;
5353 hideOverlay : ( ) => void ;
5454 isVariant ?: boolean ;
55+ entryPermissions ?: EntryPermissions ;
5556}
5657
5758function handleReplaceAsset ( fieldMetadata : CslpData ) {
@@ -107,7 +108,11 @@ function handleFormFieldFocus(eventDetails: VisualBuilderCslpEventDetails) {
107108function FieldToolbarComponent (
108109 props : MultipleFieldToolbarProps
109110) : JSX . Element | null {
110- const { eventDetails, isVariant : isVariantOrParentOfVariant } = props ;
111+ const {
112+ eventDetails,
113+ isVariant : isVariantOrParentOfVariant ,
114+ entryPermissions,
115+ } = props ;
111116 const { fieldMetadata, editableElement : targetElement } = eventDetails ;
112117 const [ isFormLoading , setIsFormLoading ] = useState ( false ) ;
113118
@@ -131,16 +136,17 @@ function FieldToolbarComponent(
131136 let fieldType = null ;
132137 let isWholeMultipleField = false ;
133138
139+ let disableFieldActions = false ;
134140 if ( fieldSchema ) {
135- const { isDisabled } = isFieldDisabled ( fieldSchema , {
136- editableElement : targetElement ,
137- fieldMetadata ,
138- } ) ;
139-
140- // field is disabled, no actions needed
141- if ( isDisabled ) {
142- return null ;
143- }
141+ const { isDisabled } = isFieldDisabled (
142+ fieldSchema ,
143+ {
144+ editableElement : targetElement ,
145+ fieldMetadata ,
146+ } ,
147+ entryPermissions
148+ ) ;
149+ disableFieldActions = isDisabled ;
144150
145151 fieldType = getFieldType ( fieldSchema ) ;
146152 isModalEditable = ALLOWED_MODAL_EDITABLE_FIELD . includes ( fieldType ) ;
@@ -165,7 +171,8 @@ function FieldToolbarComponent(
165171 fieldMetadata . instance . fieldPathWithIndex ||
166172 fieldMetadata . multipleFieldMetadata ?. index === - 1 ) ;
167173
168- isReplaceAllowed = ALLOWED_REPLACE_FIELDS . includes ( fieldType ) && ! isWholeMultipleField ;
174+ isReplaceAllowed =
175+ ALLOWED_REPLACE_FIELDS . includes ( fieldType ) && ! isWholeMultipleField ;
169176 // if (
170177 // DEFAULT_MULTIPLE_FIELDS.includes(fieldType) &&
171178 // isWholeMultipleField &&
@@ -201,6 +208,7 @@ function FieldToolbarComponent(
201208 e . stopPropagation ( ) ;
202209 handleEdit ( fieldMetadata ) ;
203210 } }
211+ disabled = { disableFieldActions }
204212 >
205213 < Icon />
206214 </ button >
@@ -232,6 +240,7 @@ function FieldToolbarComponent(
232240 return ;
233241 }
234242 } }
243+ disabled = { disableFieldActions }
235244 >
236245 < ReplaceAssetIcon />
237246 </ button >
@@ -250,8 +259,10 @@ function FieldToolbarComponent(
250259 invertTooltipPosition ,
251260 } ,
252261 {
253- [ visualBuilderStyles ( ) [ "visual-builder__button--comment-loader" ] ] : isFormLoading ,
254- "visual-builder__button--comment-loader" : isFormLoading
262+ [ visualBuilderStyles ( ) [
263+ "visual-builder__button--comment-loader"
264+ ] ] : isFormLoading ,
265+ "visual-builder__button--comment-loader" : isFormLoading ,
255266 }
256267 ) }
257268 data-tooltip = { "Form" }
@@ -303,6 +314,7 @@ function FieldToolbarComponent(
303314 </ button >
304315 ) ;
305316
317+ // TODO sibling count is incorrect for this purpose
306318 const totalElementCount = targetElement ?. parentNode ?. childElementCount ?? 1 ;
307319 const indexOfElement = fieldMetadata ?. multipleFieldMetadata ?. index ;
308320
@@ -387,6 +399,7 @@ function FieldToolbarComponent(
387399 closeDropdown = { closeVariantDropdown }
388400 invertTooltipPosition = { invertTooltipPosition }
389401 toggleVariantDropdown = { toggleVariantDropdown }
402+ disabled = { disableFieldActions }
390403 />
391404 ) : null }
392405 { isMultiple && ! isWholeMultipleField ? (
@@ -409,7 +422,9 @@ function FieldToolbarComponent(
409422 "previous"
410423 ) ;
411424 } }
412- disabled = { disableMoveLeft }
425+ disabled = {
426+ disableFieldActions || disableMoveLeft
427+ }
413428 >
414429 < MoveLeftIcon
415430 className = { classNames ( {
@@ -419,7 +434,10 @@ function FieldToolbarComponent(
419434 "visual-builder__rotate--90"
420435 ] ] : direction === "vertical" ,
421436 } ) }
422- disabled = { disableMoveLeft }
437+ disabled = {
438+ disableFieldActions ||
439+ disableMoveLeft
440+ }
423441 />
424442 </ button >
425443
@@ -441,7 +459,9 @@ function FieldToolbarComponent(
441459 "next"
442460 ) ;
443461 } }
444- disabled = { disableMoveRight }
462+ disabled = {
463+ disableFieldActions || disableMoveRight
464+ }
445465 >
446466 < MoveRightIcon
447467 className = { classNames ( {
@@ -451,7 +471,10 @@ function FieldToolbarComponent(
451471 "visual-builder__rotate--90"
452472 ] ] : direction === "vertical" ,
453473 } ) }
454- disabled = { disableMoveRight }
474+ disabled = {
475+ disableFieldActions ||
476+ disableMoveRight
477+ }
455478 />
456479 </ button >
457480
@@ -470,6 +493,7 @@ function FieldToolbarComponent(
470493 e . stopPropagation ( ) ;
471494 handleDeleteInstance ( fieldMetadata ) ;
472495 } }
496+ disabled = { disableFieldActions }
473497 >
474498 < DeleteIcon />
475499 </ button >
0 commit comments