Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty state for library selection on component picker [FC-0062] #1440

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/library-authoring/component-picker/SelectLibrary.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
initializeMocks,
fireEvent,
render,
screen,
} from '../../testUtils';
Expand Down Expand Up @@ -28,10 +29,21 @@ describe('<ComponentPicker />', () => {
expect(await screen.findByText('Loading...')).toBeInTheDocument();
});

it('should render the empty status', async () => {
it('should render the no library status', async () => {
mockGetContentLibraryV2List.applyMockEmpty();
render(<ComponentPicker />);

expect(await screen.findByText(/you don't have any libraries created yet,/i)).toBeInTheDocument();
});

it('should render the no search result status', async () => {
mockGetContentLibraryV2List.applyMockEmpty();
render(<ComponentPicker />);

const searchField = await screen.findByPlaceholderText('Search for a library');
fireEvent.change(searchField, { target: { value: 'test' } });
fireEvent.submit(searchField);

expect(await screen.findByText(/there are no libraries with the current filters/i)).toBeInTheDocument();
});

Expand Down
20 changes: 16 additions & 4 deletions src/library-authoring/component-picker/SelectLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ import AlertError from '../../generic/alert-error';
import { useContentLibraryV2List } from '../data/apiHooks';
import messages from './messages';

const EmptyState = () => (
interface EmptyStateProps {
hasSearchQuery: boolean;
}

const EmptyState = ({ hasSearchQuery }: EmptyStateProps) => (
<Alert className="mt-4 align-self-center">
<Alert.Heading>
<FormattedMessage {...messages.selectLibraryEmptyStateTitle} />
{hasSearchQuery ? (
<FormattedMessage {...messages.selectLibraryNoSearchResultsTitle} />
) : (
<FormattedMessage {...messages.selectLibraryNoLibrariesTitle} />
)}
</Alert.Heading>
<p>
<FormattedMessage {...messages.selectLibraryEmptyStateMessage} />
{hasSearchQuery ? (
<FormattedMessage {...messages.selectLibraryNoSearchResultsMessage} />
) : (
<FormattedMessage {...messages.selectLibraryNoLibrariesMessage} />
)}
</p>
</Alert>
);
Expand Down Expand Up @@ -72,7 +84,7 @@ const SelectLibrary = ({ selectedLibrary, setSelectedLibrary }: SelectLibraryPro
placeholder={intl.formatMessage(messages.selectLibrarySearchPlaceholder)}
/>
<div>
{data.results.length === 0 && (<EmptyState />)}
{data.results.length === 0 && (<EmptyState hasSearchQuery={!!searchQuery} />)}
<Form.RadioSet
name="selected-library"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSelectedLibrary(e.target.value)}
Expand Down
23 changes: 17 additions & 6 deletions src/library-authoring/component-picker/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@ const messages = defineMessages({
defaultMessage: 'Library pagination',
description: 'The pagination label for the select library component',
},
selectLibraryEmptyStateTitle: {
id: 'course-authoring.library-authoring.pick-components.select-library.empty-state.title',
selectLibraryNoSearchResultsTitle: {
id: 'course-authoring.library-authoring.pick-components.select-library.no-search.results.title',
defaultMessage: 'We could not find any result',
description: 'The title for the empty state in the select library component',
description: 'The title for the no search results state in the select library component',
},
selectLibraryEmptyStateMessage: {
id: 'course-authoring.library-authoring.pick-components.select-library.empty-state.message',
selectLibraryNoSearchResultsMessage: {
id: 'course-authoring.library-authoring.pick-components.select-library.no-search.message',
defaultMessage: 'There are no libraries with the current filters.',
description: 'The message for the empty state in the select library component',
description: 'The message for the no search results state in the select library component',
},
selectLibraryNoLibrariesTitle: {
id: 'course-authoring.library-authoring.pick-components.select-library.no-libraries.title',
defaultMessage: 'No libraries found',
description: 'The title for the no libraries state in the select library component',
},
selectLibraryNoLibrariesMessage: {
id: 'course-authoring.library-authoring.pick-components.select-library.no-libraries.message',
defaultMessage: 'You don\'t have any libraries created yet, or you don\'t have access to any libraries. To '
+ 'create a new library, go to Studio Home or contact your system administrator.',
description: 'The message for the no libraries state in the select library component',
},
selectLibraryNextButton: {
id: 'course-authoring.library-authoring.pick-components.select-library.next-button',
Expand Down