Skip to content

Commit 7810833

Browse files
committed
feat: collection empty states
1 parent b68d9a5 commit 7810833

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/library-authoring/EmptyStates.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/require-default-props */
12
import React, { useContext } from 'react';
23
import { useParams } from 'react-router';
34
import { FormattedMessage } from '@edx/frontend-platform/i18n';
@@ -10,27 +11,37 @@ import messages from './messages';
1011
import { LibraryContext } from './common/context';
1112
import { useContentLibrary } from './data/apiHooks';
1213

13-
export const NoComponents = () => {
14+
type NoSearchResultsProps = {
15+
searchType?: 'collection' | 'component',
16+
};
17+
18+
export const NoComponents = ({ searchType = 'component' }: NoSearchResultsProps) => {
1419
const { openAddContentSidebar } = useContext(LibraryContext);
1520
const { libraryId } = useParams();
1621
const { data: libraryData } = useContentLibrary(libraryId);
1722
const canEditLibrary = libraryData?.canEditLibrary ?? false;
1823

1924
return (
2025
<Stack direction="horizontal" gap={3} className="mt-6 justify-content-center">
21-
<FormattedMessage {...messages.noComponents} />
26+
{searchType === 'collection'
27+
? <FormattedMessage {...messages.noCollections} />
28+
: <FormattedMessage {...messages.noComponents} />}
2229
{canEditLibrary && (
2330
<Button iconBefore={Add} onClick={() => openAddContentSidebar()}>
24-
<FormattedMessage {...messages.addComponent} />
31+
{searchType === 'collection'
32+
? <FormattedMessage {...messages.addCollection} />
33+
: <FormattedMessage {...messages.addComponent} />}
2534
</Button>
2635
)}
2736
</Stack>
2837
);
2938
};
3039

31-
export const NoSearchResults = () => (
32-
<Stack direction="horizontal" gap={3} className="mt-6 justify-content-center">
33-
<FormattedMessage {...messages.noSearchResults} />
40+
export const NoSearchResults = ({ searchType = 'component' }: NoSearchResultsProps) => (
41+
<Stack direction="horizontal" gap={3} className="my-6 justify-content-center">
42+
{searchType === 'collection'
43+
? <FormattedMessage {...messages.noSearchResultsCollections} />
44+
: <FormattedMessage {...messages.noSearchResults} />}
3445
<ClearFiltersButton variant="primary" size="md" />
3546
</Stack>
3647
);

src/library-authoring/LibraryCollections.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const LibraryCollections = ({ variant }: LibraryCollectionsProps) => {
5151
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
5252

5353
if (totalCollectionHits === 0) {
54-
return isFiltered ? <NoSearchResults /> : <NoComponents />;
54+
return isFiltered ? <NoSearchResults searchType="collection" /> : <NoComponents searchType="collection" />;
5555
}
5656

5757
return (

src/library-authoring/messages.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,31 @@ const messages = defineMessages({
2525
defaultMessage: 'No matching components found in this library.',
2626
description: 'Message displayed when no search results are found',
2727
},
28+
noSearchResultsCollections: {
29+
id: 'course-authoring.library-authoring.no-search-results-collections',
30+
defaultMessage: 'No matching collections found in this library.',
31+
description: 'Message displayed when no matching collections are found',
32+
},
2833
noComponents: {
2934
id: 'course-authoring.library-authoring.no-components',
3035
defaultMessage: 'You have not added any content to this library yet.',
3136
description: 'Message displayed when the library is empty',
3237
},
38+
noCollections: {
39+
id: 'course-authoring.library-authoring.no-collections',
40+
defaultMessage: 'You have not added any collection to this library yet.',
41+
description: 'Message displayed when the library has no collections',
42+
},
3343
addComponent: {
3444
id: 'course-authoring.library-authoring.add-component',
3545
defaultMessage: 'Add component',
3646
description: 'Button text to add a new component',
3747
},
48+
addCollection: {
49+
id: 'course-authoring.library-authoring.add-collection',
50+
defaultMessage: 'Add collection',
51+
description: 'Button text to add a new collection',
52+
},
3853
homeTab: {
3954
id: 'course-authoring.library-authoring.home-tab',
4055
defaultMessage: 'Home',

0 commit comments

Comments
 (0)