-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/CLS2-643-select-investment-project (#6366)
* added field lookup for investment projects * only show the investment project field if someone has selected a company * fixed component tests * fix naming of test * tests fixes * moved component into shared export
- Loading branch information
1 parent
0261d02
commit b1e12d3
Showing
8 changed files
with
488 additions
and
250 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/client/components/Form/elements/FieldInvestmentProjectTypeahead/index.jsx
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,54 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { throttle } from 'lodash' | ||
|
||
import FieldTypeahead from '../FieldTypeahead' | ||
import { apiProxyAxios } from '../../../Task/utils' | ||
|
||
const FieldInvestmentProjectTypeahead = ({ | ||
name, | ||
label, | ||
required, | ||
placeholder = 'Type to search for investment projects', | ||
company = null, | ||
...props | ||
}) => { | ||
return ( | ||
<FieldTypeahead | ||
name={name} | ||
label={label} | ||
placeholder={placeholder} | ||
noOptionsMessage="" | ||
required={required} | ||
loadOptions={throttle( | ||
(searchString) => | ||
apiProxyAxios | ||
.get('/v3/investment', { | ||
params: { | ||
autocomplete: searchString, | ||
investor_company_id: company, | ||
}, | ||
}) | ||
.then(({ data: { results } }) => | ||
results.map(({ id, name }) => ({ | ||
label: name, | ||
chipLabel: name, | ||
value: id, | ||
})) | ||
), | ||
500 | ||
)} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
FieldInvestmentProjectTypeahead.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
label: PropTypes.string.isRequired, | ||
required: PropTypes.string, | ||
isMulti: PropTypes.bool, | ||
placeholder: PropTypes.string, | ||
} | ||
|
||
export default FieldInvestmentProjectTypeahead |
53 changes: 53 additions & 0 deletions
53
src/client/components/Form/elements/__stories__/FieldInvestmentProjectTypeahead.stories.jsx
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 @@ | ||
import React from 'react' | ||
|
||
import FieldInvestmentProjectTypeahead from '../FieldInvestmentProjectTypeahead' | ||
import Form from '../../../Form' | ||
|
||
const options = [ | ||
{ | ||
value: '379f390a-e083-4a2c-9cea-e3b9a08606a7', | ||
label: 'Project A', | ||
}, | ||
{ | ||
value: '8dcd2bb8-dc73-4a42-8655-4ae42d4d3c5a', | ||
label: 'Project B', | ||
}, | ||
] | ||
|
||
export const mockLoadOptions = (query = '') => | ||
new Promise((resolve) => | ||
query && query.length | ||
? setTimeout( | ||
resolve, | ||
200, | ||
options.filter(({ label }) => | ||
label.toLowerCase().includes(query.toLowerCase()) | ||
) | ||
) | ||
: resolve([]) | ||
) | ||
|
||
export default { | ||
title: 'Form/Form Elements/FieldInvestmentProjectTypeahead', | ||
excludeStories: ['mockLoadOptions'], | ||
parameters: { | ||
component: FieldInvestmentProjectTypeahead, | ||
}, | ||
} | ||
|
||
export const Default = () => ( | ||
<Form | ||
id="fieldInvestmentProjectTypeaheadExample" | ||
analyticsFormName="fieldInvestmentProjectTypeaheadExample" | ||
submissionTaskName="Submit Form example" | ||
> | ||
{() => ( | ||
<> | ||
<FieldInvestmentProjectTypeahead | ||
name="investmentProject" | ||
loadOptions={mockLoadOptions} | ||
/> | ||
</> | ||
)} | ||
</Form> | ||
) |
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.