Commit e45ad235 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Refactor SidebarContentError as Panel, with shared LabeledButtons

parent 6ee96180
import { SvgIcon } from '@hypothesis/frontend-shared';
import classnames from 'classnames';
import { useStoreProxy } from '../store/use-store'; import { useStoreProxy } from '../store/use-store';
import Button from './Button'; import { LabeledButton } from '../../shared/components/buttons';
import Panel from './Panel';
/** /**
* @typedef SidebarContentErrorProps * @typedef SidebarContentErrorProps
...@@ -43,35 +42,23 @@ export default function SidebarContentError({ ...@@ -43,35 +42,23 @@ export default function SidebarContentError({
})(); })();
return ( return (
<div className="SidebarContentError"> <Panel icon="restricted" title={errorTitle}>
<div className="SidebarContentError__header">
<div className="SidebarContentError__header-icon">
<SvgIcon name="restricted" title={errorTitle} />
</div>
<div className="SidebarContentError__title u-stretch">{errorTitle}</div>
</div>
<div className="SidebarContentError__content">
<p>{errorMessage}</p> <p>{errorMessage}</p>
<div className="SidebarContentError__actions"> <div className="u-layout-row--justify-right u-horizontal-rhythm">
{showClearSelection && ( {showClearSelection && (
<Button <LabeledButton
buttonText="Show all annotations" variant={isLoggedIn ? 'primary' : undefined}
className={classnames({
SidebarContentError__button: !isLoggedIn,
'SidebarContentError__button--primary': isLoggedIn,
})}
onClick={() => store.clearSelection()} onClick={() => store.clearSelection()}
/> >
Show all annotations
</LabeledButton>
)} )}
{!isLoggedIn && ( {!isLoggedIn && (
<Button <LabeledButton variant="primary" onClick={onLoginRequest}>
buttonText="Log in" Log in
className="SidebarContentError__button--primary" </LabeledButton>
onClick={onLoginRequest}
/>
)} )}
</div> </div>
</div> </Panel>
</div>
); );
} }
...@@ -35,11 +35,10 @@ describe('SidebarContentError', () => { ...@@ -35,11 +35,10 @@ describe('SidebarContentError', () => {
}); });
const findButtonByText = (wrapper, text) => { const findButtonByText = (wrapper, text) => {
return wrapper.find('Button').filter({ buttonText: text }); return wrapper
}; .find('LabeledButton')
.filterWhere(button => button.text() === text)
const errorText = wrapper => { .at(0);
return wrapper.find('.SidebarContentError__content').text();
}; };
it('should provide a button to clear the selection (show all annotations)', () => { it('should provide a button to clear the selection (show all annotations)', () => {
...@@ -50,6 +49,7 @@ describe('SidebarContentError', () => { ...@@ -50,6 +49,7 @@ describe('SidebarContentError', () => {
}); });
const clearButton = findButtonByText(wrapper, 'Show all annotations'); const clearButton = findButtonByText(wrapper, 'Show all annotations');
assert.isTrue(clearButton.exists()); assert.isTrue(clearButton.exists());
clearButton.props().onClick(); clearButton.props().onClick();
...@@ -63,10 +63,10 @@ describe('SidebarContentError', () => { ...@@ -63,10 +63,10 @@ describe('SidebarContentError', () => {
const wrapper = createComponent(); const wrapper = createComponent();
assert.include( assert.include(
errorText(wrapper), wrapper.text(),
'The annotation associated with the current URL is unavailable' 'The annotation associated with the current URL is unavailable'
); );
assert.include(errorText(wrapper), 'You may need to log in'); assert.include(wrapper.text(), 'You may need to log in');
}); });
it('should render a log in button', () => { it('should render a log in button', () => {
...@@ -88,10 +88,10 @@ describe('SidebarContentError', () => { ...@@ -88,10 +88,10 @@ describe('SidebarContentError', () => {
const wrapper = createComponent(); const wrapper = createComponent();
assert.include( assert.include(
errorText(wrapper), wrapper.text(),
'The current URL links to an annotation, but that annotation' 'The current URL links to an annotation, but that annotation'
); );
assert.notInclude(errorText(wrapper), 'You may need to log in'); assert.notInclude(wrapper.text(), 'You may need to log in');
}); });
it('should not provide an option to log in', () => { it('should not provide an option to log in', () => {
...@@ -111,10 +111,10 @@ describe('SidebarContentError', () => { ...@@ -111,10 +111,10 @@ describe('SidebarContentError', () => {
const wrapper = createComponent({ errorType: 'group' }); const wrapper = createComponent({ errorType: 'group' });
assert.include( assert.include(
errorText(wrapper), wrapper.text(),
'The group associated with the current URL is unavailable' 'The group associated with the current URL is unavailable'
); );
assert.include(errorText(wrapper), 'You may need to log in'); assert.include(wrapper.text(), 'You may need to log in');
}); });
it('should provide option to log in', () => { it('should provide option to log in', () => {
...@@ -134,10 +134,10 @@ describe('SidebarContentError', () => { ...@@ -134,10 +134,10 @@ describe('SidebarContentError', () => {
const wrapper = createComponent({ errorType: 'group' }); const wrapper = createComponent({ errorType: 'group' });
assert.include( assert.include(
errorText(wrapper), wrapper.text(),
'The current URL links to a group, but that group' 'The current URL links to a group, but that group'
); );
assert.notInclude(errorText(wrapper), 'You may need to log in'); assert.notInclude(wrapper.text(), 'You may need to log in');
}); });
it('should not provide an option to log in', () => { it('should not provide an option to log in', () => {
......
@use "../../mixins/molecules";
@use "../../variables" as var;
.SidebarContentError {
@include molecules.panel;
position: relative;
margin-bottom: 0.75em;
}
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
@use './components/ShareAnnotationsPanel'; @use './components/ShareAnnotationsPanel';
@use './components/SearchInput'; @use './components/SearchInput';
@use './components/ShareLinks'; @use './components/ShareLinks';
@use './components/SidebarContentError';
@use './components/Spinner'; @use './components/Spinner';
@use './components/TagEditor'; @use './components/TagEditor';
@use './components/TagList'; @use './components/TagList';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment