Skip to content

Commit

Permalink
Merge pull request #174 from creative-commoners/pulls/4/empty-list
Browse files Browse the repository at this point in the history
ENH Show a cannot create message when types is empty
  • Loading branch information
sabina-talipova authored Jan 18, 2024
2 parents 663a13f + 2927d50 commit 4bc4883
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions client/src/components/LinkPicker/LinkPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ const LinkPicker = ({ types, onModalSuccess, onModalClosed, canCreate }) => {
const shouldOpenModal = typeKey !== '';
const className = classnames('link-picker', 'form-control');
const typeArray = Object.values(types);
const message = i18n._t('LinkField.CANNOT_CREATE_LINK', 'Cannot create link');

if (!canCreate) {
if (!canCreate || typeArray.length === 0) {
return (
<div className={className}>
<div className="link-picker__cannot-create">
{i18n._t('LinkField.CANNOT_CREATE_LINK', 'Cannot create link')}
{message}
</div>
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions client/src/components/LinkPicker/tests/LinkPicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ test('LinkPickerMenu render() should display cannot create message if cannot cre
expect(container.querySelectorAll('.link-picker__cannot-create')).toHaveLength(1);
});

test('LinkPickerMenu render() should display cannot create message if types is empty', () => {
const { container } = render(<LinkFieldContext.Provider value={{ loading: false }}>
<LinkPicker {...makeProps({ types: {} })} />
</LinkFieldContext.Provider>);
expect(container.querySelectorAll('.link-picker__menu-toggle')).toHaveLength(0);
expect(container.querySelectorAll('.link-picker__cannot-create')).toHaveLength(1);
});

test('LinkPickerMenu render() should display link type icon if can create', () => {
const { container } = render(<LinkFieldContext.Provider value={{ loading: false }}>
<LinkPicker {...makeProps({ canCreate: true })} />
Expand Down

0 comments on commit 4bc4883

Please sign in to comment.