From b6143e3919b7535fda17c3a62818b1d791fc6cbf Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Thu, 14 Jan 2021 14:07:38 +0000 Subject: [PATCH] Add Back To Workflow button Add a back button to the subject set picker, and an onClose callback which is called when the button is clicked. --- .../src/screens/ClassifyPage/ClassifyPage.js | 9 ++++-- .../components/WorkflowMenu/WorkflowMenu.js | 8 +++++- .../SubjectSetPicker/SubjectSetPicker.js | 24 +++++++++++++--- .../SubjectSetPicker/SubjectSetPicker.spec.js | 28 +++++++++++++++++-- .../SubjectSetPicker.stories.js | 14 ++++++++++ .../SubjectSetPicker/locales/en.json | 1 + 6 files changed, 74 insertions(+), 10 deletions(-) diff --git a/packages/app-project/src/screens/ClassifyPage/ClassifyPage.js b/packages/app-project/src/screens/ClassifyPage/ClassifyPage.js index 18d4478f06c..d8c845b5f2d 100644 --- a/packages/app-project/src/screens/ClassifyPage/ClassifyPage.js +++ b/packages/app-project/src/screens/ClassifyPage/ClassifyPage.js @@ -42,6 +42,10 @@ function ClassifyPage (props) { return true } + function onClose() { + setActiveWorkflow(null) + } + return ( @@ -55,8 +59,8 @@ function ClassifyPage (props) { {!canClassify && ( setActiveWorkflow(null)} - onEsc={() => setActiveWorkflow(null)} + closeFn={onClose} + onEsc={onClose} headingBackground='brand' title={activeWorkflow ? (activeWorkflow.displayName || 'Choose a subject set') : 'Choose a workflow'} titleColor='neutral-6' @@ -67,6 +71,7 @@ function ClassifyPage (props) { workflows={workflows} /> : setActiveWorkflow(null)} + closeFn={onClose} headingBackground='brand' title={activeWorkflow.displayName || 'Choose a subject set'} titleColor='neutral-6' > + + {counterpart('SubjectSetPicker.back')} + + + ) +} function SubjectSetPicker (props) { - const { active, closeFn, owner, project, title, workflow } = props + const { onClose, owner, project, workflow } = props /* Vertical spacing for the picker instructions. The theme's named margins are set in multiples of 10px, so set 15px explicitly. @@ -36,6 +48,7 @@ function SubjectSetPicker (props) { return ( <> + {onClose && } SubjectSetPicker', function () { const cards = wrapper.find(SubjectSetCard) expect(cards.length).to.equal(mockWorkflow.subjectSets.length) }) + + describe('the onClose callback', function () { + + before(function () { + wrapper.setProps({ + onClose: sinon.stub() + }) + }) + + it('should show a back button', function () { + const button = wrapper.find(BackButton).first() + expect(button).to.have.lengthOf(1) + }) + + it('should be called when the back button is clicked', function () { + const button = wrapper.find(BackButton).first() + const onClose = button.prop('onClick') + button.simulate('click') + expect(onClose).to.have.been.calledOnce() + }) + }) }) \ No newline at end of file diff --git a/packages/app-project/src/shared/components/SubjectSetPicker/SubjectSetPicker.stories.js b/packages/app-project/src/shared/components/SubjectSetPicker/SubjectSetPicker.stories.js index 072048ba6e6..e21d514216e 100644 --- a/packages/app-project/src/shared/components/SubjectSetPicker/SubjectSetPicker.stories.js +++ b/packages/app-project/src/shared/components/SubjectSetPicker/SubjectSetPicker.stories.js @@ -46,6 +46,20 @@ export function Default({ dark, workflow }) { ) } +export function WithBackButton({ dark, workflow }) { + function onClose() { + alert('you clicked the back button.') + } + return ( + + + + ) +} + export function Tablet({ active, dark, title, workflow }) { return ( diff --git a/packages/app-project/src/shared/components/SubjectSetPicker/locales/en.json b/packages/app-project/src/shared/components/SubjectSetPicker/locales/en.json index d7b3c292a18..89bcdb253eb 100644 --- a/packages/app-project/src/shared/components/SubjectSetPicker/locales/en.json +++ b/packages/app-project/src/shared/components/SubjectSetPicker/locales/en.json @@ -1,5 +1,6 @@ { "SubjectSetPicker": { + "back": "Back to workflow", "heading": "Choose where to start", "byline": "Choose a subject set to start transcribing." }