@@ -10,9 +10,9 @@ import {
1010} from '@openedx/paragon' ;
1111import { MoreVert } from '@openedx/paragon/icons' ;
1212
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' ;
1616import { type ContainerHit , Highlight , PublishStatus } from '../../search-manager' ;
1717import { useComponentPickerContext } from '../common/context/ComponentPickerContext' ;
1818import { useLibraryContext } from '../common/context/LibraryContext' ;
@@ -21,32 +21,41 @@ import { useRemoveItemsFromCollection } from '../data/apiHooks';
2121import { useLibraryRoutes } from '../routes' ;
2222import messages from './messages' ;
2323import ContainerDeleter from './ContainerDeleter' ;
24+ import ContainerRemover from './ContainerRemover' ;
2425import { useRunOnNextRender } from '../../utils' ;
2526import BaseCard from '../components/BaseCard' ;
2627import AddComponentWidget from '../components/AddComponentWidget' ;
2728
2829type ContainerMenuProps = {
2930 containerKey : string ;
31+ displayName : string ;
3032} ;
3133
32- export const ContainerMenu = ( { containerKey } : ContainerMenuProps ) => {
34+ export const ContainerMenu = ( { containerKey, displayName } : ContainerMenuProps ) => {
3335 const intl = useIntl ( ) ;
34- const { libraryId, collectionId } = useLibraryContext ( ) ;
36+ const { libraryId, collectionId, containerId } = useLibraryContext ( ) ;
3537 const {
3638 sidebarItemInfo,
3739 closeLibrarySidebar,
3840 setSidebarAction,
3941 } = useSidebarContext ( ) ;
42+
4043 const { showToast } = useContext ( ToastContext ) ;
4144 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 ( ) ;
4352
4453 const removeComponentsMutation = useRemoveItemsFromCollection ( libraryId , collectionId ) ;
4554
46- const removeFromCollection = ( ) => {
55+ const handleRemoveFromCollection = ( ) => {
4756 removeComponentsMutation . mutateAsync ( [ containerKey ] ) . then ( ( ) => {
4857 if ( sidebarItemInfo ?. id === containerKey ) {
49- // Close sidebar if current component is open
58+ // Close sidebar if current component is open
5059 closeLibrarySidebar ( ) ;
5160 }
5261 showToast ( intl . formatMessage ( messages . removeComponentFromCollectionSuccess ) ) ;
@@ -55,6 +64,14 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
5564 } ) ;
5665 } ;
5766
67+ const handleRemove = ( ) => {
68+ if ( insideCollection ) {
69+ handleRemoveFromCollection ( ) ;
70+ } else if ( insideSection || insideSubsection ) {
71+ confirmRemove ( ) ;
72+ }
73+ } ;
74+
5875 const scheduleJumpToCollection = useRunOnNextRender ( ( ) => {
5976 // TODO: Ugly hack to make sure sidebar shows add to collection section
6077 // This needs to run after all changes to url takes place to avoid conflicts.
@@ -70,6 +87,8 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
7087 navigateTo ( { containerId : containerKey } ) ;
7188 } , [ navigateTo , containerKey ] ) ;
7289
90+ const containerType = containerId ? getBlockType ( containerId ) : 'collection' ;
91+
7392 return (
7493 < >
7594 < Dropdown id = "container-card-dropdown" >
@@ -89,9 +108,14 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
89108 < Dropdown . Item onClick = { confirmDelete } >
90109 < FormattedMessage { ...messages . menuDeleteContainer } />
91110 </ 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+ />
95119 </ Dropdown . Item >
96120 ) }
97121 < Dropdown . Item onClick = { showManageCollections } >
@@ -106,6 +130,14 @@ export const ContainerMenu = ({ containerKey } : ContainerMenuProps) => {
106130 containerId = { containerKey }
107131 />
108132 ) }
133+ { isConfirmingRemove && (
134+ < ContainerRemover
135+ isOpen = { isConfirmingRemove }
136+ close = { cancelRemove }
137+ containerKey = { containerKey }
138+ displayName = { displayName }
139+ />
140+ ) }
109141 </ >
110142 ) ;
111143} ;
@@ -262,7 +294,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
262294 { componentPickerMode ? (
263295 < AddComponentWidget usageKey = { containerKey } blockType = { itemType } />
264296 ) : (
265- < ContainerMenu containerKey = { containerKey } />
297+ < ContainerMenu containerKey = { containerKey } displayName = { displayName } />
266298 ) }
267299 </ ActionRow >
268300 ) }
0 commit comments