-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #549 from zooniverse/add-feedback-ui
Add feedback modal
- Loading branch information
Showing
8 changed files
with
317 additions
and
31 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/lib-classifier/src/components/Classifier/components/Feedback/FeedbackModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { inject, observer } from 'mobx-react' | ||
import { Button, Box } from 'grommet' | ||
import { Modal } from '@zooniverse/react-components' | ||
import counterpart from 'counterpart' | ||
import en from './locales/en' | ||
|
||
import SubjectViewer from '../SubjectViewer' | ||
|
||
counterpart.registerTranslations('en', en) | ||
|
||
function storeMapper (stores) { | ||
const { | ||
hideFeedback, | ||
hideSubjectViewer, | ||
messages, | ||
showModal | ||
} = stores.classifierStore.feedback | ||
return { | ||
hideFeedback, | ||
hideSubjectViewer, | ||
messages, | ||
showModal | ||
} | ||
} | ||
|
||
@inject(storeMapper) | ||
@observer | ||
class FeedbackModal extends React.Component { | ||
render () { | ||
const label = counterpart('FeedbackModal.label') | ||
const { hideFeedback, hideSubjectViewer, messages, showModal } = this.props | ||
|
||
if (showModal) { | ||
return ( | ||
<Modal | ||
active={showModal} | ||
closeFn={hideFeedback} | ||
title={label} | ||
> | ||
<> | ||
<Box | ||
height='medium' | ||
overflow='auto' | ||
> | ||
{!hideSubjectViewer && <SubjectViewer />} | ||
<ul> | ||
{messages.map(message => | ||
<li key={Math.random()}> | ||
{message} | ||
</li> | ||
)} | ||
</ul> | ||
</Box> | ||
<Box pad={{ top: 'small' }}> | ||
<Button | ||
onClick={hideFeedback} | ||
label={counterpart('FeedbackModal.close')} | ||
primary | ||
/> | ||
</Box> | ||
</> | ||
</Modal> | ||
) | ||
} | ||
|
||
return null | ||
} | ||
} | ||
|
||
FeedbackModal.wrappedComponent.propTypes = { | ||
hideFeedback: PropTypes.func, | ||
messages: PropTypes.arrayOf(PropTypes.string), | ||
showModal: PropTypes.bool | ||
} | ||
|
||
export default FeedbackModal |
31 changes: 31 additions & 0 deletions
31
packages/lib-classifier/src/components/Classifier/components/Feedback/FeedbackModal.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
import { Button } from 'grommet' | ||
import FeedbackModal from './FeedbackModal' | ||
|
||
describe('FeedbackModal', function () { | ||
it('should render without crashing', function () { | ||
const wrapper = shallow(<FeedbackModal.wrappedComponent />) | ||
expect(wrapper).to.be.ok | ||
}) | ||
|
||
it('should not render if showModal false', function () { | ||
const wrapper = shallow(<FeedbackModal.wrappedComponent showModal={false} />) | ||
expect(wrapper.html()).to.be.null | ||
}) | ||
|
||
it('should show messages', function () { | ||
const wrapper = shallow(<FeedbackModal.wrappedComponent showModal messages={['Yay!', 'Good Job', 'Try Again']} />) | ||
const list = wrapper.find('li') | ||
expect(list).to.have.lengthOf(3) | ||
}) | ||
|
||
it('should call hideFeedback on close', function () { | ||
const hideFeedbackStub = sinon.stub() | ||
const wrapper = shallow(<FeedbackModal.wrappedComponent showModal messages={['Yay!', 'Good Job', 'Try Again']} hideFeedback={hideFeedbackStub} />) | ||
wrapper.find(Button).simulate('click') | ||
expect(hideFeedbackStub).to.have.been.called | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
packages/lib-classifier/src/components/Classifier/components/Feedback/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './FeedbackModal' |
6 changes: 6 additions & 0 deletions
6
packages/lib-classifier/src/components/Classifier/components/Feedback/locales/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"FeedbackModal": { | ||
"close": "Close", | ||
"label": "Feedback" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.