@@ -49,12 +49,12 @@ interface LibraryBlockMetadataWithUniqueId extends LibraryBlockMetadata {
49
49
50
50
interface ComponentBlockProps {
51
51
block : LibraryBlockMetadataWithUniqueId ;
52
- preview ?: boolean ;
52
+ readOnly ?: boolean ;
53
53
isDragging ?: boolean ;
54
54
}
55
55
56
56
/** Component header */
57
- const BlockHeader = ( { block } : ComponentBlockProps ) => {
57
+ const BlockHeader = ( { block, readOnly } : ComponentBlockProps ) => {
58
58
const intl = useIntl ( ) ;
59
59
const { showOnlyPublished } = useLibraryContext ( ) ;
60
60
const { showToast } = useContext ( ToastContext ) ;
@@ -98,21 +98,20 @@ const BlockHeader = ({ block }: ComponentBlockProps) => {
98
98
gap = { 2 }
99
99
className = "font-weight-bold"
100
100
// Prevent parent card from being clicked.
101
- /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
102
101
onClick = { ( e ) => e . stopPropagation ( ) }
103
102
>
104
103
< Icon src = { getItemIcon ( block . blockType ) } />
105
104
< InplaceTextEditor
106
105
onSave = { handleSaveDisplayName }
107
106
text = { showOnlyPublished ? ( block . publishedDisplayName ?? block . displayName ) : block . displayName }
107
+ readOnly = { readOnly }
108
108
/>
109
109
</ Stack >
110
110
< ActionRow . Spacer />
111
111
< Stack
112
112
direction = "horizontal"
113
113
gap = { 3 }
114
114
// Prevent parent card from being clicked.
115
- /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
116
115
onClick = { ( e ) => e . stopPropagation ( ) }
117
116
>
118
117
{ ! showOnlyPublished && block . hasUnpublishedChanges && (
@@ -126,15 +125,15 @@ const BlockHeader = ({ block }: ComponentBlockProps) => {
126
125
</ Stack >
127
126
</ Badge >
128
127
) }
129
- < TagCount size = "sm" count = { block . tagsCount } onClick = { jumpToManageTags } />
130
- < ComponentMenu usageKey = { block . originalId } />
128
+ < TagCount size = "sm" count = { block . tagsCount } onClick = { readOnly ? undefined : jumpToManageTags } />
129
+ { ! readOnly && < ComponentMenu usageKey = { block . originalId } /> }
131
130
</ Stack >
132
131
</ >
133
132
) ;
134
133
} ;
135
134
136
135
/** ComponentBlock to render preview of given component under Unit */
137
- const ComponentBlock = ( { block, preview , isDragging } : ComponentBlockProps ) => {
136
+ const ComponentBlock = ( { block, readOnly , isDragging } : ComponentBlockProps ) => {
138
137
const { showOnlyPublished } = useLibraryContext ( ) ;
139
138
const { navigateTo } = useLibraryRoutes ( ) ;
140
139
@@ -189,16 +188,16 @@ const ComponentBlock = ({ block, preview, isDragging }: ComponentBlockProps) =>
189
188
< SortableItem
190
189
id = { block . id }
191
190
componentStyle = { getComponentStyle ( ) }
192
- actions = { < BlockHeader block = { block } /> }
191
+ actions = { < BlockHeader block = { block } readOnly = { readOnly } /> }
193
192
actionStyle = { {
194
193
borderRadius : '8px 8px 0px 0px' ,
195
194
padding : '0.5rem 1rem' ,
196
195
background : '#FBFAF9' ,
197
196
borderBottom : 'solid 1px #E1DDDB' ,
198
197
} }
199
- isClickable
200
- onClick = { ( e : { detail : number ; } ) => handleComponentSelection ( e . detail ) }
201
- disabled = { preview }
198
+ isClickable = { ! readOnly }
199
+ onClick = { ! readOnly ? ( e : { detail : number ; } ) => handleComponentSelection ( e . detail ) : undefined }
200
+ disabled = { readOnly }
202
201
cardClassName = { selected ? 'selected' : undefined }
203
202
>
204
203
{ /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ }
@@ -223,20 +222,22 @@ const ComponentBlock = ({ block, preview, isDragging }: ComponentBlockProps) =>
223
222
224
223
interface LibraryUnitBlocksProps {
225
224
/** set to true if it is rendered as preview
226
- * This disables drag and drop
225
+ * This disables drag and drop, title edit and menus
227
226
*/
228
- preview ?: boolean ;
227
+ readOnly ?: boolean ;
229
228
}
230
229
231
- export const LibraryUnitBlocks = ( { preview } : LibraryUnitBlocksProps ) => {
230
+ export const LibraryUnitBlocks = ( { readOnly : componentReadOnly } : LibraryUnitBlocksProps ) => {
232
231
const intl = useIntl ( ) ;
233
232
const [ orderedBlocks , setOrderedBlocks ] = useState < LibraryBlockMetadataWithUniqueId [ ] > ( [ ] ) ;
234
233
const [ isAddLibraryContentModalOpen , showAddLibraryContentModal , closeAddLibraryContentModal ] = useToggle ( ) ;
235
234
236
235
const [ hidePreviewFor , setHidePreviewFor ] = useState < string | null > ( null ) ;
237
236
const { showToast } = useContext ( ToastContext ) ;
238
237
239
- const { unitId, readOnly, showOnlyPublished } = useLibraryContext ( ) ;
238
+ const { unitId, readOnly : libraryReadOnly , showOnlyPublished } = useLibraryContext ( ) ;
239
+
240
+ const readOnly = componentReadOnly || libraryReadOnly ;
240
241
241
242
const { openAddContentSidebar } = useSidebarContext ( ) ;
242
243
@@ -301,10 +302,11 @@ export const LibraryUnitBlocks = ({ preview }: LibraryUnitBlocksProps) => {
301
302
key = { `${ block . originalId } -${ idx } -${ block . modified } ` }
302
303
block = { block }
303
304
isDragging = { hidePreviewFor === block . id }
305
+ readOnly = { readOnly }
304
306
/>
305
307
) ) }
306
308
</ DraggableList >
307
- { ! preview && (
309
+ { ! readOnly && (
308
310
< div className = "d-flex" >
309
311
< div className = "w-100 mr-2" >
310
312
< Button
0 commit comments