-
Notifications
You must be signed in to change notification settings - Fork 23
feat: Add UI for Managing Required Reports for Phases #1205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stalgiag
wants to merge
15
commits into
development
Choose a base branch
from
req-reports-manage
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ced7c8f
Manage required report, migrate and refactor
stalgiag 3c2713c
Update snapshots
stalgiag 0a86196
Update mock for TestQueue
stalgiag 1474e8a
Add e2e tests for ManageRequiredReports
stalgiag 0dfb7bd
AtVersions, Different order for newly added option
stalgiag 7264830
Update snapshots with testing attributes
stalgiag 76fe39e
Repairs for spliced merge
stalgiag 51cd9e6
Disclosure container styles
stalgiag 5904f9b
Snapshots for updated style classes
stalgiag 7d8304a
Remove duplicated enum
stalgiag 1f7db13
Remove RequiredReportPhase
stalgiag 43df566
Remove custom toggle
stalgiag 85d36f9
Update copy
stalgiag 192520f
Don't show required reports on Data Management, update snapshots
stalgiag df0858b
Update TestQueue e2e test for creating required report after removal …
stalgiag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
208 changes: 208 additions & 0 deletions
208
client/components/common/ManageRequiredReportsDisclosure/CreateRequiredReportForm.jsx
This file contains hidden or 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,208 @@ | ||
| import React, { useState } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { Button, Dropdown, Form } from 'react-bootstrap'; | ||
| import styled from '@emotion/styled'; | ||
| import { AtPropType } from '../proptypes'; | ||
|
|
||
| const CustomToggleButton = styled.button` | ||
| background-color: transparent; | ||
| width: 100%; | ||
| height: 38px; | ||
| text-align: center; | ||
|
|
||
| border: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| display: block; | ||
|
|
||
| .icon-container { | ||
| background-color: red; | ||
| float: right; | ||
| margin-top: 2px; | ||
| margin-right: 3px; | ||
| } | ||
| .icon-chevron { | ||
| font-size: 0.8rem; | ||
| } | ||
| `; | ||
|
|
||
| const CustomToggleP = styled.p` | ||
| border: 1px solid #ced4da; | ||
| border-radius: 0.375rem; | ||
| background-color: #fff; | ||
| padding: 2px; | ||
| width: 100%; | ||
| height: 38px; | ||
| cursor: default; | ||
| display: inline-block; | ||
| `; | ||
|
|
||
| const CustomToggleSpan = styled.span` | ||
| background-image: url('data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3e%3cpath fill=%27none%27 stroke=%27%23343a40%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27 stroke-width=%272%27 d=%27m2 5 6 6 6-6%27/%3e%3c/svg%3e'); | ||
| background-repeat: no-repeat; | ||
| background-position: right 0.75rem center; | ||
| background-size: 16px 12px; | ||
| float: left; | ||
| margin-top: 2px; | ||
| white-space: nowrap; | ||
| background-color: ${props => | ||
| props.phaseLabel === 'Select a Phase' | ||
| ? '#fff' | ||
| : props.phaseLabel === 'Candidate' | ||
| ? '#ff6c00' | ||
| : props.phaseLabel === 'Recommended' | ||
| ? '#8441de' | ||
| : 'black'}; | ||
| border-radius: 14px; | ||
| padding: 2px 32px 2px 14px; | ||
| text-align: left; | ||
| width: 100%; | ||
| font-size: 1rem; | ||
| font-weight: 400; | ||
| color: ${props => (props.phaseLabel === 'Select a Phase' ? 'black' : '#fff')}; | ||
| `; | ||
|
|
||
| const CustomMenu = React.forwardRef(({ children, className }, ref) => { | ||
| const value = ''; | ||
|
|
||
| return ( | ||
| <div ref={ref} className={className}> | ||
| <ul> | ||
| {React.Children.toArray(children).filter( | ||
| child => | ||
| !value || child.props.children.toLowerCase().startsWith(value) | ||
| )} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| // You can learn everything about this component here: https://react-bootstrap.netlify.app/docs/components/dropdowns#custom-dropdown-components | ||
| const CustomToggle = React.forwardRef(({ children, onClick }, ref) => ( | ||
| <CustomToggleButton | ||
| ref={ref} | ||
| onClick={e => { | ||
| e.preventDefault(); | ||
| onClick(e); | ||
| }} | ||
| > | ||
| <CustomToggleP> | ||
| <CustomToggleSpan phaseLabel={children}>{children}</CustomToggleSpan> | ||
| </CustomToggleP> | ||
| </CustomToggleButton> | ||
| )); | ||
|
|
||
| const FormGroup = ({ label, children }) => ( | ||
| <Form.Group className="form-group"> | ||
| <Form.Label className="disclosure-form-label">{label}</Form.Label> | ||
| {children} | ||
| </Form.Group> | ||
| ); | ||
|
|
||
| export const CreateRequiredReportForm = ({ ats, handleCreate }) => { | ||
| const [formState, setFormState] = useState({ | ||
| phase: '', | ||
| at: '', | ||
| browser: '' | ||
| }); | ||
|
|
||
| const handleInputChange = (field, value) => { | ||
| setFormState(prev => ({ ...prev, [field]: value })); | ||
| }; | ||
|
|
||
| const handleSubmit = async () => { | ||
| await handleCreate({ | ||
| atId: formState.at, | ||
| browserId: formState.browser, | ||
| phase: formState.phase.toUpperCase() | ||
| }); | ||
| setFormState({ phase: '', at: '', browser: '' }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="disclosure-row-controls"> | ||
| <FormGroup label="Phase"> | ||
| <Dropdown> | ||
| <Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components"> | ||
| {formState.phase || 'Select a Phase'} | ||
| </Dropdown.Toggle> | ||
| <Dropdown.Menu className="drop-down-div" as={CustomMenu}> | ||
| {['Candidate', 'Recommended'].map(phase => ( | ||
| <Dropdown.Item | ||
| key={phase} | ||
| className="phase-option" | ||
| onClick={() => handleInputChange('phase', phase)} | ||
| > | ||
| {phase} | ||
| </Dropdown.Item> | ||
| ))} | ||
| </Dropdown.Menu> | ||
| </Dropdown> | ||
| </FormGroup> | ||
| <FormGroup label="Assistive Technology"> | ||
| <Form.Select | ||
| value={formState.at} | ||
| onChange={e => handleInputChange('at', e.target.value)} | ||
| required | ||
| > | ||
| <option value="" disabled> | ||
| Select an Assistive Technology | ||
| </option> | ||
| {ats.map(item => ( | ||
| <option key={item.id} value={item.id}> | ||
| {item.name} | ||
| </option> | ||
| ))} | ||
| </Form.Select> | ||
| </FormGroup> | ||
| <FormGroup label="Browser"> | ||
| <Form.Select | ||
| value={formState.browser} | ||
| onChange={e => handleInputChange('browser', e.target.value)} | ||
| required | ||
| > | ||
| <option value="" disabled> | ||
| Select a Browser | ||
| </option> | ||
| {ats | ||
| .find(at => at.id === formState.at) | ||
| ?.browsers.map(item => ( | ||
| <option key={`${item.name}-${item.id}`} value={item.id}> | ||
| {item.name} | ||
| </option> | ||
| ))} | ||
| </Form.Select> | ||
| </FormGroup> | ||
| <FormGroup> | ||
| <Button | ||
| disabled={!formState.phase || !formState.at || !formState.browser} | ||
| onClick={handleSubmit} | ||
| > | ||
| Add Required Reports | ||
| </Button> | ||
| </FormGroup> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| FormGroup.propTypes = { | ||
| label: PropTypes.string, | ||
| children: PropTypes.node.isRequired | ||
| }; | ||
|
|
||
| CustomToggle.propTypes = { | ||
| children: PropTypes.string, | ||
| onClick: PropTypes.func | ||
| }; | ||
|
|
||
| CustomMenu.propTypes = { | ||
| children: PropTypes.array, | ||
| className: PropTypes.string | ||
| }; | ||
|
|
||
| CreateRequiredReportForm.propTypes = { | ||
| ats: PropTypes.arrayOf(AtPropType).isRequired, | ||
| handleCreate: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| CreateRequiredReportForm.propTypes = {}; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This custom menu might be a bit much for just this as I'm not seeing a major advantage to highlighting the selected option's color. It also feels a bit out of place given this and the connected disclosures' options. This feels like a case where simplicity may be better, with a native
<select>.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another case where I agree but didn't want to deviate from the pattern that was previously used. I knew that you and Alex were pairing on the code so I didn't want to be too presumptuous about what was discardable. I assume this custom menu was being used to replicate the original mockups as closely as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 43df566