Skip to content

Commit 276c17c

Browse files
committed
fix: uniform messages while adding to collection
1 parent 608feb0 commit 276c17c

9 files changed

Lines changed: 42 additions & 38 deletions

File tree

src/library-authoring/add-content/AddContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { useLibraryContext } from '../common/context/LibraryContext';
2929
import { PickLibraryContentModal } from './PickLibraryContentModal';
3030
import { blockTypes } from '../../editors/data/constants/app';
3131

32+
import genericMessages from '../generic/messages';
3233
import messages from './messages';
3334
import type { BlockTypeMetadata } from '../data/api';
3435
import { getContainerTypeFromId, ContainerType } from '../../generic/key-utils';
@@ -301,7 +302,7 @@ const AddContent = () => {
301302
const linkComponent = (opaqueKey: string) => {
302303
if (collectionId) {
303304
addComponentsToCollectionMutation.mutateAsync([opaqueKey]).catch(() => {
304-
showToast(intl.formatMessage(messages.errorAssociateComponentToCollectionMessage));
305+
showToast(intl.formatMessage(genericMessages.manageCollectionsFailed));
305306
});
306307
}
307308
if (unitId) {

src/library-authoring/add-content/PickLibraryContentModal.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('<PickLibraryContentModal />', () => {
9292
}
9393
});
9494
expect(onClose).toHaveBeenCalled();
95-
expect(mockShowToast).toHaveBeenCalledWith('Content linked successfully.');
95+
expect(mockShowToast).toHaveBeenCalledWith('Content added to collection');
9696
});
9797

9898
it(`show error when api call fails (${context})`, async () => {

src/library-authoring/add-content/PickLibraryContentModal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ToastContext } from '../../generic/toast-context';
66
import { useLibraryContext } from '../common/context/LibraryContext';
77
import type { SelectedComponent } from '../common/context/ComponentPickerContext';
88
import { useAddItemsToCollection, useAddComponentsToContainer } from '../data/apiHooks';
9+
import genericMessages from '../generic/messages';
910
import messages from './messages';
1011

1112
interface PickLibraryContentModalFooterProps {
@@ -69,16 +70,16 @@ export const PickLibraryContentModal: React.FC<PickLibraryContentModalProps> = (
6970
if (collectionId) {
7071
updateCollectionItemsMutation.mutateAsync(usageKeys)
7172
.then(() => {
72-
showToast(intl.formatMessage(messages.successAssociateComponentMessage));
73+
showToast(intl.formatMessage(genericMessages.manageCollectionsSuccess));
7374
})
7475
.catch(() => {
75-
showToast(intl.formatMessage(messages.errorAssociateComponentToCollectionMessage));
76+
showToast(intl.formatMessage(genericMessages.manageCollectionsFailed));
7677
});
7778
}
7879
if (unitId) {
7980
updateUnitComponentsMutation.mutateAsync(usageKeys)
8081
.then(() => {
81-
showToast(intl.formatMessage(messages.successAssociateComponentMessage));
82+
showToast(intl.formatMessage(messages.successAssociateComponentToContainerMessage));
8283
})
8384
.catch(() => {
8485
showToast(intl.formatMessage(messages.errorAssociateComponentToContainerMessage));

src/library-authoring/add-content/messages.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,10 @@ const messages = defineMessages({
8484
+ ' The {detail} text provides more information about the error.'
8585
),
8686
},
87-
successAssociateComponentMessage: {
88-
id: 'course-authoring.library-authoring.associate-collection-content.success.text',
87+
successAssociateComponentToContainerMessage: {
88+
id: 'course-authoring.library-authoring.associate-container-content.success.text',
8989
defaultMessage: 'Content linked successfully.',
90-
description: 'Message when linking of content to a collection in library is success',
91-
},
92-
errorAssociateComponentToCollectionMessage: {
93-
id: 'course-authoring.library-authoring.associate-collection-content.error.text',
94-
defaultMessage: 'There was an error linking the content to this collection.',
95-
description: 'Message when linking of content to a collection in library fails',
90+
description: 'Message when linking of content to a container in library is success',
9691
},
9792
errorAssociateComponentToContainerMessage: {
9893
id: 'course-authoring.library-authoring.associate-container-content.error.text',

src/library-authoring/generic/manage-collections/ManageCollections.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('<ManageCollections />', () => {
7777
await waitFor(() => {
7878
expect(axiosMock.history.patch.length).toEqual(1);
7979
});
80-
expect(mockShowToast).toHaveBeenCalledWith('Item collections updated');
80+
expect(mockShowToast).toHaveBeenCalledWith('Content added to collection');
8181
expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual({
8282
collection_keys: ['my-first-collection', 'my-second-collection'],
8383
});
@@ -103,7 +103,7 @@ describe('<ManageCollections />', () => {
103103
await waitFor(() => {
104104
expect(axiosMock.history.patch.length).toEqual(1);
105105
});
106-
expect(mockShowToast).toHaveBeenCalledWith('Item collections updated');
106+
expect(mockShowToast).toHaveBeenCalledWith('Content added to collection');
107107
expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual({
108108
collection_keys: ['my-first-collection', 'my-second-collection'],
109109
});

src/library-authoring/generic/manage-collections/ManageCollections.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ToastContext } from '../../../generic/toast-context';
1616
import { CollectionMetadata } from '../../data/api';
1717
import { useLibraryContext } from '../../common/context/LibraryContext';
1818
import { SidebarActions, useSidebarContext } from '../../common/context/SidebarContext';
19+
import genericMessages from '../messages';
1920
import messages from './messages';
2021

2122
interface ManageCollectionsProps {
@@ -50,9 +51,9 @@ const CollectionsSelectableBox = ({
5051
const handleConfirmation = () => {
5152
setBtnState('pending');
5253
updateCollectionsMutation.mutateAsync(selectedCollections).then(() => {
53-
showToast(intl.formatMessage(messages.manageCollectionsToComponentSuccess));
54+
showToast(intl.formatMessage(genericMessages.manageCollectionsSuccess));
5455
}).catch(() => {
55-
showToast(intl.formatMessage(messages.manageCollectionsToComponentFailed));
56+
showToast(intl.formatMessage(genericMessages.manageCollectionsFailed));
5657
}).finally(() => {
5758
setBtnState('default');
5859
onClose();

src/library-authoring/generic/manage-collections/messages.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ const messages = defineMessages({
2121
defaultMessage: 'Collection selection',
2222
description: 'Aria label text for collection selection box',
2323
},
24-
manageCollectionsToComponentSuccess: {
25-
id: 'course-authoring.library-authoring.manage-collections.add-success',
26-
defaultMessage: 'Item collections updated',
27-
description: 'Message to display on updating item collections',
28-
},
29-
manageCollectionsToComponentFailed: {
30-
id: 'course-authoring.library-authoring.manage-collections.add-failed',
31-
defaultMessage: 'Failed to update item collections',
32-
description: 'Message to display on failure of updating item collections',
33-
},
3424
manageCollectionsToComponentConfirmBtn: {
3525
id: 'course-authoring.library-authoring.manage-collections.add-confirm-btn',
3626
defaultMessage: 'Confirm',
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineMessages } from '@edx/frontend-platform/i18n';
2+
3+
const messages = defineMessages({
4+
manageCollectionsSuccess: {
5+
id: 'course-authoring.library-authoring.manage-collections.success',
6+
defaultMessage: 'Content added to collection',
7+
description: 'Message to display on updating item collections',
8+
},
9+
manageCollectionsFailed: {
10+
id: 'course-authoring.library-authoring.manage-collections.failed',
11+
defaultMessage: 'Failed adding content to collection',
12+
description: 'Message to display on failure of updating item collections',
13+
},
14+
});
15+
16+
export default messages;

src/library-authoring/units/LibraryUnitBlocks.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,16 @@ export const LibraryUnitBlocks = ({ preview }: LibraryUnitBlocksProps) => {
220220
disabled={preview}
221221
>
222222
{hidePreviewFor !== block.id && (
223-
<div className={classNames('p-3', {
224-
'container-mw-md': block.blockType === blockTypes.video,
225-
})}
226-
>
227-
<LibraryBlock
228-
usageKey={block.id}
229-
version={showOnlyPublished ? 'published' : undefined}
230-
minHeight={calculateMinHeight(block)}
231-
/>
232-
</div>
223+
<div className={classNames('p-3', {
224+
'container-mw-md': block.blockType === blockTypes.video,
225+
})}
226+
>
227+
<LibraryBlock
228+
usageKey={block.id}
229+
version={showOnlyPublished ? 'published' : undefined}
230+
minHeight={calculateMinHeight(block)}
231+
/>
232+
</div>
233233
)}
234234
</SortableItem>
235235
</IframeProvider>
@@ -247,7 +247,7 @@ export const LibraryUnitBlocks = ({ preview }: LibraryUnitBlocksProps) => {
247247
>
248248
{renderedBlocks}
249249
</DraggableList>
250-
{ !preview && (
250+
{!preview && (
251251
<div className="d-flex">
252252
<div className="w-100 mr-2">
253253
<Button

0 commit comments

Comments
 (0)