@@ -31,13 +31,13 @@ import { blockTypes } from '../../editors/data/constants/app';
31
31
32
32
import { useLibraryRoutes } from '../routes' ;
33
33
import genericMessages from '../generic/messages' ;
34
- import messages from './messages' ;
34
+ import { messages , getContentMessages } from './messages' ;
35
35
import type { BlockTypeMetadata } from '../data/api' ;
36
36
import { ContainerType } from '../../generic/key-utils' ;
37
37
38
38
type ContentType = {
39
39
name : string ,
40
- disabled : boolean ,
40
+ disabled ? : boolean ,
41
41
icon ?: React . ComponentType ,
42
42
blockType : string ,
43
43
} ;
@@ -64,7 +64,7 @@ type AddAdvancedContentViewProps = {
64
64
const AddContentButton = ( { contentType, onCreateContent } : AddContentButtonProps ) => {
65
65
const {
66
66
name,
67
- disabled,
67
+ disabled = false ,
68
68
icon,
69
69
blockType,
70
70
} = contentType ;
@@ -96,97 +96,132 @@ const AddContentView = ({
96
96
insideSubsection,
97
97
} = useLibraryRoutes ( ) ;
98
98
99
- const collectionButtonData = {
100
- name : intl . formatMessage ( messages . collectionButton ) ,
101
- disabled : false ,
102
- blockType : 'collection' ,
103
- } ;
99
+ const contentMessages = useMemo ( ( ) => (
100
+ getContentMessages ( insideSection , insideSubsection , insideUnit )
101
+ ) , [ insideSection , insideSubsection , insideUnit ] ) ;
102
+
103
+ const collectionButton = (
104
+ < AddContentButton
105
+ key = "collection"
106
+ contentType = { {
107
+ name : intl . formatMessage ( contentMessages . collectionButton ) ,
108
+ blockType : 'collection' ,
109
+ } }
110
+ onCreateContent = { onCreateContent }
111
+ />
112
+ ) ;
104
113
105
- const unitButtonData = {
106
- name : intl . formatMessage ( messages . unitButton ) ,
107
- disabled : false ,
108
- blockType : 'vertical' ,
109
- } ;
114
+ const unitButton = (
115
+ < AddContentButton
116
+ key = "unit"
117
+ contentType = { {
118
+ name : intl . formatMessage ( contentMessages . unitButton ) ,
119
+ blockType : 'unit' ,
120
+ } }
121
+ onCreateContent = { onCreateContent }
122
+ />
123
+ ) ;
110
124
111
- const sectionButtonData = {
112
- name : intl . formatMessage ( messages . sectionButton ) ,
113
- disabled : false ,
114
- blockType : 'chapter' ,
115
- } ;
125
+ const sectionButton = (
126
+ < AddContentButton
127
+ key = "section"
128
+ contentType = { {
129
+ name : intl . formatMessage ( contentMessages . sectionButton ) ,
130
+ blockType : 'section' ,
131
+ } }
132
+ onCreateContent = { onCreateContent }
133
+ />
134
+ ) ;
116
135
117
- const subsectionButtonData = {
118
- name : intl . formatMessage ( messages . subsectionButton ) ,
119
- disabled : false ,
120
- blockType : 'sequential' ,
121
- } ;
136
+ const subsectionButton = (
137
+ < AddContentButton
138
+ key = "subsection"
139
+ contentType = { {
140
+ name : intl . formatMessage ( contentMessages . subsectionButton ) ,
141
+ blockType : 'subsection' ,
142
+ } }
143
+ onCreateContent = { onCreateContent }
144
+ />
145
+ ) ;
122
146
123
- const libraryContentButtonData = {
124
- name : intl . formatMessage ( messages . libraryContentButton ) ,
125
- disabled : false ,
126
- blockType : 'libraryContent' ,
127
- } ;
147
+ const existingContentButton = (
148
+ < AddContentButton
149
+ key = "libraryContent"
150
+ contentType = { {
151
+ name : intl . formatMessage ( contentMessages . libraryContentButton ) ,
152
+ blockType : 'libraryContent' ,
153
+ } }
154
+ onCreateContent = { onCreateContent }
155
+ />
156
+ ) ;
128
157
129
- /** List container content types that should be displayed based on current path */
130
- const visibleContentTypes = useMemo ( ( ) => {
158
+ /* Note: for MVP we are hiding the unsupported types, not just disabling them. */
159
+ const componentButtons = contentTypes . filter ( ct => ! ct . disabled ) . map ( ( contentType ) => (
160
+ < AddContentButton
161
+ key = { `add-content-${ contentType . blockType } ` }
162
+ contentType = { contentType }
163
+ onCreateContent = { onCreateContent }
164
+ />
165
+ ) ) ;
166
+ const separator = (
167
+ < hr className = "w-100 bg-gray-500" />
168
+ ) ;
169
+
170
+ /** List buttons that should be displayed based on current path */
171
+ const visibleButtons = useMemo ( ( ) => {
131
172
if ( insideCollection ) {
132
- // except for add collection button, show everthing .
173
+ // except for add collection button, show everything .
133
174
return [
134
- libraryContentButtonData ,
135
- sectionButtonData ,
136
- subsectionButtonData ,
137
- unitButtonData ,
175
+ existingContentButton ,
176
+ sectionButton ,
177
+ subsectionButton ,
178
+ unitButton ,
179
+ separator ,
180
+ ...componentButtons ,
138
181
] ;
139
182
}
140
183
if ( insideUnit ) {
141
- // Only show libraryContentButton
142
- return [ libraryContentButtonData ] ;
184
+ // Only show existing content button + component buttons
185
+ return [
186
+ existingContentButton ,
187
+ separator ,
188
+ ...componentButtons ,
189
+ ] ;
143
190
}
144
191
if ( insideSection ) {
145
- // Should only allow adding subsections
146
- return [ subsectionButtonData ] ;
192
+ // Only allow adding subsections
193
+ return [
194
+ existingContentButton ,
195
+ subsectionButton ,
196
+ ] ;
147
197
}
148
198
if ( insideSubsection ) {
149
- // Should only allow adding units
150
- return [ unitButtonData ] ;
199
+ // Only allow adding units
200
+ return [
201
+ existingContentButton ,
202
+ unitButton ,
203
+ ] ;
151
204
}
152
- // except for libraryContentButton , show everthing .
205
+ // except for existing content , show everything .
153
206
return [
154
- collectionButtonData ,
155
- sectionButtonData ,
156
- subsectionButtonData ,
157
- unitButtonData ,
207
+ collectionButton ,
208
+ sectionButton ,
209
+ subsectionButton ,
210
+ unitButton ,
211
+ separator ,
212
+ ...componentButtons ,
158
213
] ;
159
- } , [ insideCollection , insideUnit , insideSection , insideSubsection ] ) ;
214
+ } , [ componentButtons , insideCollection , insideUnit , insideSection , insideSubsection ] ) ;
160
215
161
216
return (
162
217
< >
163
- { visibleContentTypes . map ( ( contentType ) => (
164
- < AddContentButton
165
- key = { contentType . blockType }
166
- contentType = { contentType }
167
- onCreateContent = { onCreateContent }
168
- />
169
- ) ) }
170
- { componentPicker && visibleContentTypes . includes ( libraryContentButtonData ) && (
171
- /// Show the "Add Library Content" button for units and collections
218
+ { visibleButtons }
219
+ { componentPicker && visibleButtons . includes ( existingContentButton ) && (
172
220
< PickLibraryContentModal
173
221
isOpen = { isAddLibraryContentModalOpen }
174
222
onClose = { closeAddLibraryContentModal }
175
223
/>
176
224
) }
177
- { ( ! insideSection && ! insideSubsection ) && (
178
- < >
179
- < hr className = "w-100 bg-gray-500" />
180
- { /* Note: for MVP we are hiding the unuspported types, not just disabling them. */ }
181
- { contentTypes . filter ( ct => ! ct . disabled ) . map ( ( contentType ) => (
182
- < AddContentButton
183
- key = { `add-content-${ contentType . blockType } ` }
184
- contentType = { contentType }
185
- onCreateContent = { onCreateContent }
186
- />
187
- ) ) }
188
- </ >
189
- ) }
190
225
</ >
191
226
) ;
192
227
} ;
@@ -423,9 +458,9 @@ const AddContent = () => {
423
458
} else if ( blockType === 'advancedXBlock' ) {
424
459
showAdvancedList ( ) ;
425
460
} else if ( [
426
- ContainerType . Vertical ,
427
- ContainerType . Chapter ,
428
- ContainerType . Sequential ,
461
+ ContainerType . Unit ,
462
+ ContainerType . Subsection ,
463
+ ContainerType . Section ,
429
464
] . includes ( blockType as ContainerType ) ) {
430
465
setCreateContainerModalType ( blockType as ContainerType ) ;
431
466
} else {
0 commit comments