Skip to content

Commit 1efa94d

Browse files
authored
fix: update delete and remove modals design [FC-0097] (#2453)
Changes the Remove/Delete Component/Container dialogs according to the design. It also standardized the messages from Components and Containers.
1 parent d98a34a commit 1efa94d

25 files changed

+392
-300
lines changed

src/course-libraries/ReviewTabContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const ItemReviewList = ({
144144

145145
const {
146146
hits,
147-
isLoading: isIndexDataLoading,
147+
isPending: isIndexDataPending,
148148
hasError,
149149
hasNextPage,
150150
isFetchingNextPage,
@@ -243,7 +243,7 @@ const ItemReviewList = ({
243243
}
244244
}, [blockData]);
245245

246-
if (isIndexDataLoading) {
246+
if (isIndexDataPending) {
247247
return <Loading />;
248248
}
249249

src/library-authoring/LibraryContent.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import fetchMock from 'fetch-mock-jest';
22

3+
import { getContentSearchConfigUrl } from '@src/search-manager/data/api';
34
import {
45
fireEvent,
56
render,
67
screen,
78
initializeMocks,
8-
} from '../testUtils';
9-
import { getContentSearchConfigUrl } from '../search-manager/data/api';
9+
} from '@src/testUtils';
10+
1011
import { mockContentLibrary } from './data/api.mocks';
1112
import mockEmptyResult from '../search-modal/__mocks__/empty-search-result.json';
1213
import { LibraryProvider } from './common/context/LibraryContext';
@@ -27,7 +28,7 @@ const data = {
2728
fetchNextPage: mockFetchNextPage,
2829
searchKeywords: '',
2930
isFiltered: false,
30-
isLoading: false,
31+
isPending: false,
3132
};
3233

3334
const returnEmptyResult = (_url: string, req) => {
@@ -77,7 +78,7 @@ describe('<LibraryHome />', () => {
7778
it('should render a spinner while loading', async () => {
7879
mockUseSearchContext.mockReturnValue({
7980
...data,
80-
isLoading: true,
81+
isPending: true,
8182
});
8283

8384
render(<LibraryContent />, withLibraryId(mockContentLibrary.libraryId));

src/library-authoring/LibraryContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const LibraryContent = ({ contentType = ContentType.home }: LibraryContentProps)
3636
isFetchingNextPage,
3737
hasNextPage,
3838
fetchNextPage,
39-
isLoading,
39+
isPending,
4040
isFiltered,
4141
usageKey,
4242
} = useSearchContext();
@@ -56,7 +56,7 @@ const LibraryContent = ({ contentType = ContentType.home }: LibraryContentProps)
5656
true,
5757
);
5858

59-
if (isLoading) {
59+
if (isPending) {
6060
return <LoadingSpinner />;
6161
}
6262
if (totalHits === 0) {

src/library-authoring/component-info/ComponentUsage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const ComponentUsage = ({ usageKey }: ComponentUsageProps) => {
3535
data: dataDownstreamLinks,
3636
isError: isErrorDownstreamLinks,
3737
error: errorDownstreamLinks,
38-
isLoading: isLoadingDownstreamLinks,
38+
isPending: isPendingDownstreamLinks,
3939
} = useEntityLinks({ upstreamKey: usageKey, contentType: 'components' });
4040

4141
const downstreamKeys = useMemo(
@@ -47,14 +47,14 @@ export const ComponentUsage = ({ usageKey }: ComponentUsageProps) => {
4747
hits: downstreamHits,
4848
isError: isErrorIndexDocuments,
4949
error: errorIndexDocuments,
50-
isLoading: isLoadingIndexDocuments,
50+
isPending: isPendingIndexDocuments,
5151
} = useContentFromSearchIndex(downstreamKeys);
5252

5353
if (isErrorDownstreamLinks || isErrorIndexDocuments) {
5454
return <AlertError error={errorDownstreamLinks || errorIndexDocuments} />;
5555
}
5656

57-
if (isLoadingDownstreamLinks || (isLoadingIndexDocuments && !!downstreamKeys.length)) {
57+
if (isPendingDownstreamLinks || (isPendingIndexDocuments && !!downstreamKeys.length)) {
5858
return <Loading />;
5959
}
6060

src/library-authoring/components/CollectionCard.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import {
77
IconButton,
88
useToggle,
99
} from '@openedx/paragon';
10-
import { MoreVert } from '@openedx/paragon/icons';
10+
import { Delete, MoreVert } from '@openedx/paragon/icons';
1111

12-
import { type CollectionHit } from '../../search-manager';
12+
import DeleteModal from '@src/generic/delete-modal/DeleteModal';
13+
import { ToastContext } from '@src/generic/toast-context';
14+
import { type CollectionHit } from '@src/search-manager';
1315
import { useComponentPickerContext } from '../common/context/ComponentPickerContext';
1416
import { useLibraryContext } from '../common/context/LibraryContext';
1517
import { SidebarBodyItemId, useSidebarContext } from '../common/context/SidebarContext';
1618
import { useLibraryRoutes } from '../routes';
1719
import BaseCard from './BaseCard';
18-
import { ToastContext } from '../../generic/toast-context';
1920
import { useDeleteCollection, useRestoreCollection } from '../data/apiHooks';
20-
import DeleteModal from '../../generic/delete-modal/DeleteModal';
2121
import messages from './messages';
2222

2323
type CollectionMenuProps = {
@@ -98,7 +98,8 @@ const CollectionMenu = ({ hit } : CollectionMenuProps) => {
9898
<DeleteModal
9999
isOpen={isDeleteModalOpen}
100100
close={closeDeleteModal}
101-
variant="warning"
101+
variant="danger"
102+
icon={Delete}
102103
category={type}
103104
description={intl.formatMessage(messages.deleteCollectionConfirm, {
104105
collectionTitle: displayName,

src/library-authoring/components/ComponentDeleter.test.tsx

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import type { ToastActionData } from '../../generic/toast-context';
1+
import type { ToastActionData } from '@src/generic/toast-context';
2+
import { mockContentSearchConfig, mockSearchResult, hydrateSearchResult } from '@src/search-manager/data/api.mock';
23
import {
34
fireEvent,
45
render,
56
screen,
67
initializeMocks,
78
waitFor,
8-
} from '../../testUtils';
9+
} from '@src/testUtils';
910
import { LibraryProvider } from '../common/context/LibraryContext';
1011
import { SidebarProvider } from '../common/context/SidebarContext';
1112
import {
1213
mockContentLibrary, mockDeleteLibraryBlock, mockLibraryBlockMetadata, mockRestoreLibraryBlock,
1314
} from '../data/api.mocks';
1415
import ComponentDeleter from './ComponentDeleter';
15-
import { mockContentSearchConfig, mockSearchResult } from '../../search-manager/data/api.mock';
1616

1717
mockContentLibrary.applyMock(); // Not required, but avoids 404 errors in the logs when <LibraryProvider> loads data
1818
mockLibraryBlockMetadata.applyMock();
@@ -41,28 +41,16 @@ describe('<ComponentDeleter />', () => {
4141
beforeEach(() => {
4242
const mocks = initializeMocks();
4343
mockShowToast = mocks.mockShowToast;
44-
mockSearchResult({
45-
results: [ // @ts-ignore
46-
{
47-
hits: [],
48-
},
49-
],
50-
});
51-
});
52-
53-
it('is invisible when isConfirmingDelete is false', async () => {
54-
const mockCancel = jest.fn();
55-
render(<ComponentDeleter usageKey={usageKey} isConfirmingDelete={false} cancelDelete={mockCancel} />, renderArgs);
56-
57-
const modal = screen.queryByRole('dialog', { name: 'Delete Component' });
58-
expect(modal).not.toBeInTheDocument();
44+
mockSearchResult(hydrateSearchResult([{
45+
displayName: 'Introduction to Testing 2',
46+
}]));
5947
});
6048

6149
it('should shows a confirmation prompt the card with title and description', async () => {
6250
const mockCancel = jest.fn();
63-
render(<ComponentDeleter usageKey={usageKey} isConfirmingDelete cancelDelete={mockCancel} />, renderArgs);
51+
render(<ComponentDeleter usageKey={usageKey} close={mockCancel} />, renderArgs);
6452

65-
const modal = screen.getByRole('dialog', { name: 'Delete Component' });
53+
const modal = await screen.findByRole('dialog', { name: 'Delete Component' });
6654
expect(modal).toBeVisible();
6755

6856
// It should mention the component's name in the confirm dialog:
@@ -76,9 +64,9 @@ describe('<ComponentDeleter />', () => {
7664

7765
it('deletes the block when confirmed, shows a toast with undo option and restores block on undo', async () => {
7866
const mockCancel = jest.fn();
79-
render(<ComponentDeleter usageKey={usageKey} isConfirmingDelete cancelDelete={mockCancel} />, renderArgs);
67+
render(<ComponentDeleter usageKey={usageKey} close={mockCancel} />, renderArgs);
8068

81-
const modal = screen.getByRole('dialog', { name: 'Delete Component' });
69+
const modal = await screen.findByRole('dialog', { name: 'Delete Component' });
8270
expect(modal).toBeVisible();
8371

8472
const deleteButton = screen.getByRole('button', { name: 'Delete' });
@@ -99,23 +87,17 @@ describe('<ComponentDeleter />', () => {
9987

10088
it('should show units message if `unitsData` is set with one unit', async () => {
10189
const mockCancel = jest.fn();
102-
mockSearchResult({
103-
results: [ // @ts-ignore
104-
{
105-
hits: [{
106-
units: {
107-
displayName: ['Unit 1'],
108-
key: ['unit1'],
109-
},
110-
}],
111-
},
112-
],
113-
});
90+
mockSearchResult(hydrateSearchResult([{
91+
displayName: 'Introduction to Testing 2',
92+
units: {
93+
displayName: ['Unit 1'],
94+
key: ['unit1'],
95+
},
96+
}]));
11497
render(
11598
<ComponentDeleter
11699
usageKey={usageKey}
117-
isConfirmingDelete
118-
cancelDelete={mockCancel}
100+
close={mockCancel}
119101
/>,
120102
renderArgs,
121103
);
@@ -131,23 +113,17 @@ describe('<ComponentDeleter />', () => {
131113

132114
it('should show units message if `unitsData` is set with multiple units', async () => {
133115
const mockCancel = jest.fn();
134-
mockSearchResult({
135-
results: [ // @ts-ignore
136-
{
137-
hits: [{
138-
units: {
139-
displayName: ['Unit 1', 'Unit 2'],
140-
key: ['unit1', 'unit2'],
141-
},
142-
}],
143-
},
144-
],
145-
});
116+
mockSearchResult(hydrateSearchResult([{
117+
displayName: 'Introduction to Testing 2',
118+
units: {
119+
displayName: ['Unit 1', 'Unit 2'],
120+
key: ['unit1', 'unit2'],
121+
},
122+
}]));
146123
render(
147124
<ComponentDeleter
148125
usageKey={usageKey}
149-
isConfirmingDelete
150-
cancelDelete={mockCancel}
126+
close={mockCancel}
151127
/>,
152128
renderArgs,
153129
);

0 commit comments

Comments
 (0)