Skip to content

Commit

Permalink
ENH Show a cannot create message when types is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 18, 2024
1 parent 663a13f commit 2927d50
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
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
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 2927d50

Please sign in to comment.