This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
FormArrayControl component and Adapters for radios and checkboxes #1312
Merged
Merged
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
8ec2817
working FormArrayControl component and Adapters for radio and checkboxes
amazingphilippe 43b350c
broken, but added a Field component to ease markup
amazingphilippe 224e8dd
Merge branch 'master' of github.com:cds-snc/report-a-cybercrime into …
amazingphilippe 0554387
rebuilt the howdiditstart page using checkbox component.
amazingphilippe 984bb3f
lint and passing tests. Not all new components have tests
amazingphilippe aa7c496
added a test for FormArrayControl
amazingphilippe 082a5fc
merged with master
amazingphilippe 9747eba
cleaned up inputs, they also work properly now.
amazingphilippe c027e39
tweaked input and text-area to accept attributes from react-final-form
amazingphilippe 555f53e
passing tests
amazingphilippe 0c3aca6
added condition to prevent rendering of node if conditional field doe…
amazingphilippe 572b87b
some tweaks to ensure correct labelling of fields
amazingphilippe 5bcaa44
#1312- Added the privacy consent checkbox fixes
khalidelaggan ca03257
#1312- Added whatWasAffected checkbox fixes
khalidelaggan 7c2fdd5
cleanups
khalidelaggan e031580
Added the money lost checkbox fixes
khalidelaggan 5e9cada
Added the missing UI container
khalidelaggan 7d857e8
Added the information page checkbox fixes
khalidelaggan 162fbe8
Added the conditional form for single field
khalidelaggan d124ba8
Merge branch 'master' into checkbox-component
khalidelaggan edede7e
Merge branch 'master' into checkbox-component
khalidelaggan 21bd04b
Merge conflicts
khalidelaggan f9bbb27
Merge branch 'checkbox-component' of github.com:cds-snc/report-a-cybe…
khalidelaggan 5d5d02a
Added missing dependencies
khalidelaggan fe34926
Merge branch 'master' into checkbox-component
khalidelaggan 3e7af8e
Updated feedback forms
khalidelaggan 0ed51a7
Merge remote-tracking branch 'origin/master' into checkbox-component
khalidelaggan a8fb04a
Added the final forms fixes
khalidelaggan d822876
Merge branch 'master' into checkbox-component
khalidelaggan 6e21f71
Remove unwanted copy - Not included in the mocks
khalidelaggan d31a275
Merge branch 'checkbox-component' of github.com:cds-snc/report-a-cybe…
khalidelaggan 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 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,24 @@ | ||
import React from 'react' | ||
import { ThemeProvider } from 'emotion-theming' | ||
import canada from '../../../theme/canada' | ||
import { render, cleanup } from '@testing-library/react' | ||
import { Field } from '../' | ||
import { Form } from 'react-final-form' | ||
|
||
describe('<Field />', () => { | ||
afterEach(cleanup) | ||
|
||
it('renders', () => { | ||
const submitMock = jest.fn() | ||
|
||
render( | ||
<ThemeProvider theme={canada}> | ||
<Form | ||
initialValues="" | ||
onSubmit={submitMock} | ||
render={() => <Field name="name" label="foo" helperText="help" />} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
}) | ||
}) |
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,39 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from '@emotion/core' | ||
import PropTypes from 'prop-types' | ||
import { FormErrorMessage, FormControl } from '@chakra-ui/core' | ||
import { FormHelperText } from '../FormHelperText' | ||
import { FormLabel } from '../FormLabel' | ||
import { Field as FieldAdapter } from 'react-final-form' | ||
import { UniqueID } from '../unique-id' | ||
import { Input } from '../input' | ||
|
||
export const Field = ({ name, label, helperText, errorMessage, component }) => { | ||
return ( | ||
<UniqueID> | ||
{id => { | ||
return ( | ||
<FormControl aria-labelledby={id}> | ||
<FormLabel id={id} htmlFor={name}> | ||
{label} | ||
</FormLabel> | ||
<FormHelperText>{helperText}</FormHelperText> | ||
<FormErrorMessage>{errorMessage}</FormErrorMessage> | ||
<FieldAdapter name={name} id={name} component={component} /> | ||
</FormControl> | ||
) | ||
}} | ||
</UniqueID> | ||
) | ||
} | ||
Field.defaultProps = { | ||
component: Input, | ||
} | ||
|
||
Field.propTypes = { | ||
children: PropTypes.any, | ||
name: PropTypes.string, | ||
label: PropTypes.any, | ||
helperText: PropTypes.any, | ||
errorMessage: PropTypes.any, | ||
} |
36 changes: 36 additions & 0 deletions
36
f2/src/components/FormArrayControl/__tests__/FormArrayControl.test.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,36 @@ | ||
import React from 'react' | ||
import { ThemeProvider } from 'emotion-theming' | ||
import canada from '../../../theme/canada' | ||
import { render, cleanup } from '@testing-library/react' | ||
import { FormArrayControl } from '../' | ||
import { Form } from 'react-final-form' | ||
|
||
describe('<FormArrayControl />', () => { | ||
afterEach(cleanup) | ||
|
||
it('renders children', () => { | ||
const submitMock = jest.fn() | ||
|
||
const { getAllByText } = render( | ||
<ThemeProvider theme={canada}> | ||
<Form | ||
initialValues="" | ||
onSubmit={submitMock} | ||
render={() => ( | ||
<FormArrayControl name="foo" label="bar" helperText="help"> | ||
<p>all</p> | ||
</FormArrayControl> | ||
)} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
|
||
const label = getAllByText(/bar/) | ||
const help = getAllByText(/help/) | ||
const test = getAllByText(/all/) | ||
|
||
expect(label).toHaveLength(1) | ||
expect(help).toHaveLength(1) | ||
expect(test).toHaveLength(1) | ||
}) | ||
}) |
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,53 @@ | ||
/** @jsx jsx */ | ||
import PropTypes from 'prop-types' | ||
import { jsx } from '@emotion/core' | ||
import { FormErrorMessage, FormControl, Stack } from '@chakra-ui/core' | ||
import { useField } from 'react-final-form' | ||
import { FormLabel } from '../FormLabel' | ||
import { FormHelperText } from '../FormHelperText' | ||
import { UniqueID } from '../unique-id' | ||
|
||
export const FormArrayControl = ({ | ||
label, | ||
helperText, | ||
errorMessage, | ||
name, | ||
children, | ||
...rest | ||
}) => { | ||
const { | ||
meta: { error, touched }, | ||
} = useField(name, { subscription: { touched: true, error: true } }) | ||
return ( | ||
<UniqueID> | ||
{id => { | ||
return ( | ||
<FormControl | ||
as="fieldset" | ||
aria-labelledby={id} | ||
isInvalid={error && touched} | ||
{...rest} | ||
> | ||
<FormLabel id={id} as="legend" htmlFor={name}> | ||
{label} | ||
</FormLabel> | ||
<FormHelperText>{helperText}</FormHelperText> | ||
<FormErrorMessage>{errorMessage}</FormErrorMessage> | ||
{/** This component comes with a group attribute. We don't need to use Chakra's <CheckboxGroup> or <RadioGroup> as per the Chakra docs */} | ||
<Stack shouldWrapChildren spacing={4}> | ||
{children} | ||
</Stack> | ||
</FormControl> | ||
) | ||
}} | ||
</UniqueID> | ||
) | ||
} | ||
|
||
FormArrayControl.propTypes = { | ||
label: PropTypes.any, | ||
helperText: PropTypes.any, | ||
errorMessage: PropTypes.any, | ||
name: PropTypes.string, | ||
children: PropTypes.any, | ||
} |
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
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.
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.
We might want
props.conditionalField
in the &&, otherwise if there’s no conditional it’ll still make an empty<ConditionalForm/>
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.
Oh, I had this issue. Good call