@@ -10,9 +10,9 @@ import {
10
10
} from '@openedx/paragon' ;
11
11
import { MoreVert } from '@openedx/paragon/icons' ;
12
12
13
- import { getItemIcon , getComponentStyleColor } from '../.. /generic/block-type-utils' ;
14
- import { getBlockType } from '../.. /generic/key-utils' ;
15
- import { ToastContext } from '../.. /generic/toast-context' ;
13
+ import { getItemIcon , getComponentStyleColor } from '@src /generic/block-type-utils' ;
14
+ import { getBlockType } from '@src /generic/key-utils' ;
15
+ import { ToastContext } from '@src /generic/toast-context' ;
16
16
import { type ContainerHit , Highlight , PublishStatus } from '../../search-manager' ;
17
17
import { useComponentPickerContext } from '../common/context/ComponentPickerContext' ;
18
18
import { useLibraryContext } from '../common/context/LibraryContext' ;
@@ -21,32 +21,41 @@ import { useRemoveItemsFromCollection } from '../data/apiHooks';
21
21
import { useLibraryRoutes } from '../routes' ;
22
22
import messages from './messages' ;
23
23
import ContainerDeleter from './ContainerDeleter' ;
24
+ import ContainerRemover from './ContainerRemover' ;
24
25
import { useRunOnNextRender } from '../../utils' ;
25
26
import BaseCard from '../components/BaseCard' ;
26
27
import AddComponentWidget from '../components/AddComponentWidget' ;
27
28
28
29
type ContainerMenuProps = {
29
30
containerKey : string ;
31
+ displayName : string ;
30
32
} ;
31
33
32
- export const ContainerMenu = ( { containerKey } : ContainerMenuProps ) => {
34
+ export const ContainerMenu = ( { containerKey, displayName } : ContainerMenuProps ) => {
33
35
const intl = useIntl ( ) ;
34
- const { libraryId, collectionId } = useLibraryContext ( ) ;
36
+ const { libraryId, collectionId, containerId } = useLibraryContext ( ) ;
35
37
const {
36
38
sidebarItemInfo,
37
39
closeLibrarySidebar,
38
40
setSidebarAction,
39
41
} = useSidebarContext ( ) ;
42
+
40
43
const { showToast } = useContext ( ToastContext ) ;
41
44
const [ isConfirmingDelete , confirmDelete , cancelDelete ] = useToggle ( false ) ;
42
- const { navigateTo, insideCollection } = useLibraryRoutes ( ) ;
45
+ const [ isConfirmingRemove , confirmRemove , cancelRemove ] = useToggle ( false ) ;
46
+ const {
47
+ navigateTo,
48
+ insideCollection,
49
+ insideSection,
50
+ insideSubsection,
51
+ } = useLibraryRoutes ( ) ;
43
52
44
53
const removeComponentsMutation = useRemoveItemsFromCollection ( libraryId , collectionId ) ;
45
54
46
- const removeFromCollection = ( ) => {
55
+ const handleRemoveFromCollection = ( ) => {
47
56
removeComponentsMutation . mutateAsync ( [ containerKey ] ) . then ( ( ) => {
48
57
if ( sidebarItemInfo ?. id === containerKey ) {
49
- // Close sidebar if current component is open
58
+ // Close sidebar if current component is open
50
59
closeLibrarySidebar ( ) ;
51
60
}
52
61
showToast ( intl . formatMessage ( messages . removeComponentFromCollectionSuccess ) ) ;
@@ -55,6 +64,14 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
55
64
} ) ;
56
65
} ;
57
66
67
+ const handleRemove = ( ) => {
68
+ if ( insideCollection ) {
69
+ handleRemoveFromCollection ( ) ;
70
+ } else if ( insideSection || insideSubsection ) {
71
+ confirmRemove ( ) ;
72
+ }
73
+ } ;
74
+
58
75
const scheduleJumpToCollection = useRunOnNextRender ( ( ) => {
59
76
// TODO: Ugly hack to make sure sidebar shows add to collection section
60
77
// This needs to run after all changes to url takes place to avoid conflicts.
@@ -70,6 +87,8 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
70
87
navigateTo ( { containerId : containerKey } ) ;
71
88
} , [ navigateTo , containerKey ] ) ;
72
89
90
+ const containerType = containerId ? getBlockType ( containerId ) : 'collection' ;
91
+
73
92
return (
74
93
< >
75
94
< Dropdown id = "container-card-dropdown" >
@@ -89,9 +108,14 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
89
108
< Dropdown . Item onClick = { confirmDelete } >
90
109
< FormattedMessage { ...messages . menuDeleteContainer } />
91
110
</ Dropdown . Item >
92
- { insideCollection && (
93
- < Dropdown . Item onClick = { removeFromCollection } >
94
- < FormattedMessage { ...messages . menuRemoveFromCollection } />
111
+ { ( insideCollection || insideSection || insideSubsection ) && (
112
+ < Dropdown . Item onClick = { handleRemove } >
113
+ < FormattedMessage
114
+ { ...messages . menuRemoveFromContainer }
115
+ values = { {
116
+ containerType,
117
+ } }
118
+ />
95
119
</ Dropdown . Item >
96
120
) }
97
121
< Dropdown . Item onClick = { showManageCollections } >
@@ -106,6 +130,14 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
106
130
containerId = { containerKey }
107
131
/>
108
132
) }
133
+ { isConfirmingRemove && (
134
+ < ContainerRemover
135
+ isOpen = { isConfirmingRemove }
136
+ close = { cancelRemove }
137
+ containerKey = { containerKey }
138
+ displayName = { displayName }
139
+ />
140
+ ) }
109
141
</ >
110
142
) ;
111
143
} ;
@@ -262,7 +294,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
262
294
{ componentPickerMode ? (
263
295
< AddComponentWidget usageKey = { containerKey } blockType = { itemType } />
264
296
) : (
265
- < ContainerMenu containerKey = { containerKey } />
297
+ < ContainerMenu containerKey = { containerKey } displayName = { displayName } />
266
298
) }
267
299
</ ActionRow >
268
300
) }
0 commit comments