Skip to content

Commit

Permalink
changed policies on mit and ad form to be multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
zachsa committed Jul 23, 2021
1 parent ff19a9a commit 031ba69
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 44 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"EPSG",
"NCCRD",
"REIPPP",
"STAs",
"cdmes",
"cdmm",
Expand Down
8 changes: 4 additions & 4 deletions src/api/src/graphql/schema/type-defs/adaptation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ input AdaptationInput {
# Sector description :: Please describe the sector
otherAdaptationSector: String
# National policy :: Indicate the national policy or strategy that the measure is responding to :: adaptationPolicies
nationalPolicy: ControlledVocabularyInput
nationalPolicy: [ControlledVocabularyInput]
# National policy description :: Please describe the policy
otherNationalPolicy: String
# Provincial or Municipal policy :: Indicate the provincial or municipal policy or strategy that the measure is responding to :: adaptationPolicies
regionalPolicy: ControlledVocabularyInput
regionalPolicy: [ControlledVocabularyInput]
# Regional policy description :: Please describe the policy
otherRegionalPolicy: String
# Indicate the corresponding intervention, goal, or target :: Please select an appropriate value based on your other form inputs above :: adaptationPolicies
target: ControlledVocabularyInput
# Other corresponding intervention, goal, or target :: Please describe based on your other form inputs above
target: [ControlledVocabularyInput]
# Other corresponding intervention(s), goal(s), or target(s) :: Please describe based on your other form inputs above
otherTarget: String

# Hazard :: Select hazard :: hazards
Expand Down
8 changes: 4 additions & 4 deletions src/api/src/graphql/schema/type-defs/mitigation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ input MitigationInput {
# Select the mitigation program the project is linked to :: A programme is a high level support measure that support mitigation actions/project types above e.g 1A1 REIPPP :: mitigationProgramme
mitigationProgramme: ControlledVocabularyInput
# National policy :: Indicate the national policy or strategy that the measure is responding to :: mitigationPolicies
nationalPolicy: ControlledVocabularyInput
# National policy description :: Please describe the policy
nationalPolicy: [ControlledVocabularyInput]
# (Other) national policy(ies) description :: Please describe the policy(ies)
otherNationalPolicy: String
# Provincial or Municipal policy :: Indicate the provincial or municipal policy or strategy that the measure is responding to :: mitigationPolicies
regionalPolicy: ControlledVocabularyInput
# Regional policy description :: Please describe the policy
regionalPolicy: [ControlledVocabularyInput]
# (Other) regional policy(ies) description :: Please describe the policy(ies)
otherRegionalPolicy: String
# Primary intended outcome :: Primary intended outcome (Indicate the expected or achieved goals)
primaryIntendedOutcome: String
Expand Down
4 changes: 2 additions & 2 deletions src/api/src/graphql/schema/type-defs/project.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ input ProjectInput {
# Estimated budget range :: If you don't know the actual budget, please provide a range estimate :: budgetRanges
estimatedBudget: ControlledVocabularyInput
# Indicate the type of measure :: <b>Mitigation</b> measures are defined as 'actions aimed at reducing the extent or likelihood of global climate change through the reduction or displacement of greenhouse gas emissions (GHGs) (e.g. through emission reduction, energy efficiency or renewable energy projects'.<br /><br /><b>Adaptation</b> measures are defined as 'actions preventing or minimising the negative effects and taking advantage of positive effects of global warming in addition to actions which would have occurred naturally or as a matter of course.<br /><br /><b>Cross-cutting</b> Measures that contain elements of both adaptation and mitigation :: interventionTypes
interventionType: ControlledVocabularyInput!
interventionType: ControlledVocabularyInput
# Implementation status :: <b>Operational</b> - Ongoing project <br /><b>Planned project</b> - Project has not begun but is being constructed or has been registered/approved/funded<br /><b>Complete</b> - The project has been finalized<br /><b>Discontinued</b> - planned project terminated :: actionStatus
implementationStatus: ControlledVocabularyInput
# Type of funding :: Any financial resources that is spent on supporting either mitigation and adaption efforts in South Africa. Climate finance refers to <b>domestic</b> (drawn from local public or private organisations), <b>International</b> (bilateral or multilateral grants or loans). <b>Bilateral</b> funding describes money which is given directly from one government to another, whereas <b>multilateral</b> funding comes from numerous different governments and organisations and is usually arranged by an international organisation such as the World Bank or the UN :: fundingTypes
fundingType: ControlledVocabularyInput
# Province :: Select province(s) :: regions
province: [ControlledVocabularyInput]
province: [ControlledVocabularyInput]!
# District municipality :: Select district municipality(s) :: regions
districtMunicipality: [ControlledVocabularyInput]
# Local municipality :: Select local municipality(s) :: regions
Expand Down
6 changes: 4 additions & 2 deletions src/client/src/components/multiselect/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default ({
const theme = useTheme()

return (
<div style={{ marginTop: theme.spacing(2), marginBottom: theme.spacing(1) }}>
<div style={{ marginTop: theme.spacing(2), marginBottom: theme.spacing(1), maxWidth: '100%' }}>
<FormControl margin="normal" fullWidth>
<InputLabel
error={error}
Expand Down Expand Up @@ -78,6 +78,7 @@ export default ({
gap: theme.spacing(1),
flexWrap: 'wrap',
alignItems: 'flex-start',
maxWidth: '100%',
}}
>
{selected.map(value => {
Expand All @@ -90,6 +91,7 @@ export default ({
key={value}
label={value}
style={{
maxWidth: '100%',
...style,
}}
{...props}
Expand All @@ -102,7 +104,7 @@ export default ({
{options.map(option => (
<MenuItem key={option} value={option}>
<Checkbox checked={value.indexOf(option) > -1} />
<ListItemText primary={option} />
<ListItemText primary={option} style={{ overflowX: 'auto' }} />
</MenuItem>
))}
{loading ? <Loading /> : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const NewPointForm = ({ closeFn, points, setPoints }) => {
onChange={e => setLat(e.target.value)}
label="Latitude"
type="number"
helperText="Latitude in degrees"
helperText="Latitude in degrees (East / West)"
fullWidth
variant="outlined"
margin="normal"
Expand All @@ -36,7 +36,7 @@ const NewPointForm = ({ closeFn, points, setPoints }) => {
onChange={e => setLng(e.target.value)}
label="Longitude"
type="number"
helperText="Longitude in degrees"
helperText="Longitude in degrees (North / South)"
fullWidth
variant="outlined"
margin="normal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { useContext, lazy, Suspense } from 'react'
import { GqlBoundFormInput, ControlledVocabularySelect } from '../../form'
import {
GqlBoundFormInput,
ControlledVocabularySelect,
ControlledVocabularySelectMultiple,
} from '../../form'
import { context as formContext } from '../../context'
import Loading from '../../../loading'

Expand All @@ -22,9 +26,9 @@ export default ({ field, formName }) => {
useContext(formContext)
const { name: fieldName, description, type } = field
let [placeholder, helperText, tree] = description?.split('::').map(s => s.trim()) || []
const { name: inputType } = type
const isRequired = !inputType
const value = form[fieldName]
const { kind } = type
const isRequired = kind === 'NON_NULL'
const value = form?.[fieldName] || undefined

if (helperText === '') {
helperText = ` `
Expand All @@ -49,64 +53,64 @@ export default ({ field, formName }) => {
*/
if (fieldName === 'nationalPolicy') {
return (
<ControlledVocabularySelect
<ControlledVocabularySelectMultiple
key={fieldName}
tree={tree}
root="National policy"
roots={['National policy']}
name={fieldName}
value={value}
error={isRequired && !value}
onChange={val =>
updateForm({ [fieldName]: val, target: undefined, otherTarget: undefined })
}
placeholder={placeholder}
label={placeholder}
helperText={helperText}
/>
)
} else if (fieldName === 'otherNationalPolicy') {
if (!form?.nationalPolicy?.term?.match(/^Other\s/)) {
if (!form?.nationalPolicy?.find(({ term }) => term?.match(/^Other\s/))) {
return null
}
} else if (fieldName === 'target') {
if (form.nationalPolicy) {
return (
<ControlledVocabularySelect
<ControlledVocabularySelectMultiple
key={fieldName}
tree={tree}
root={form.nationalPolicy}
roots={form.nationalPolicy.map(({ term }) => term)}
name={fieldName}
value={value}
error={isRequired && !value}
onChange={val => updateForm({ [fieldName]: val, otherTarget: undefined })}
placeholder={placeholder}
label={placeholder}
helperText={helperText}
/>
)
} else {
return null
}
} else if (fieldName === 'otherTarget') {
if (!form?.target || !form.target.term?.match(/^Other/)) {
if (!form?.target || !form.target?.find(({ term }) => term?.match(/^Other/))) {
return null
}
}

if (fieldName === 'regionalPolicy') {
return (
<ControlledVocabularySelect
<ControlledVocabularySelectMultiple
key={fieldName}
tree={tree}
root={'Regional policy'}
roots={['Regional policy']}
name={fieldName}
value={value}
error={isRequired && !value}
onChange={val => updateForm({ [fieldName]: val, otherRegionalPolicy: undefined })}
placeholder={placeholder}
label={placeholder}
helperText={helperText}
/>
)
} else if (fieldName === 'otherRegionalPolicy') {
if (!form?.regionalPolicy?.term?.match(/^Other\s/)) {
if (!form?.regionalPolicy?.find(({ term }) => term?.match(/^Other\s/))) {
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useContext, lazy, Suspense } from 'react'
import Loading from '../../../loading'
import { GqlBoundFormInput, ControlledVocabularySelect } from '../../form'
import {
GqlBoundFormInput,
ControlledVocabularySelect,
ControlledVocabularySelectMultiple,
} from '../../form'
import { context as formContext } from '../../context'

const EnergyCalculator = lazy(() => import('../../form/components/calculators/energy'))
Expand Down Expand Up @@ -35,9 +39,9 @@ export default ({ field, formName }) => {
useContext(formContext)
const { name: fieldName, description, type } = field
let [placeholder, helperText, tree] = description?.split('::').map(s => s.trim()) || []
const { name: inputType } = type
const isRequired = !inputType
const value = form[fieldName]
const { kind } = type
const isRequired = kind === 'NON_NULL'
const value = form?.[fieldName] || undefined

if (helperText === '') {
helperText = ` `
Expand Down Expand Up @@ -193,20 +197,20 @@ export default ({ field, formName }) => {
*/
if (fieldName === 'nationalPolicy') {
return (
<ControlledVocabularySelect
<ControlledVocabularySelectMultiple
key={fieldName}
tree={tree}
root="National policy"
roots={['National policy']}
name={fieldName}
value={value}
error={isRequired && !value}
onChange={val => updateForm({ [fieldName]: val, otherNationalPolicy: undefined })}
placeholder={placeholder}
label={placeholder}
helperText={helperText}
/>
)
} else if (fieldName === 'otherNationalPolicy') {
if (!form?.nationalPolicy?.term?.match(/^Other\s/)) {
if (!form?.nationalPolicy?.find(({ term }) => term?.match(/^Other\s/))) {
return null
}
}
Expand All @@ -216,20 +220,20 @@ export default ({ field, formName }) => {
*/
if (fieldName === 'regionalPolicy') {
return (
<ControlledVocabularySelect
<ControlledVocabularySelectMultiple
key={fieldName}
tree={tree}
root={'Regional policy'}
roots={['Regional policy']}
name={fieldName}
value={value}
error={isRequired && !value}
error={isRequired && !value?.length}
onChange={val => updateForm({ [fieldName]: val, otherRegionalPolicy: undefined })}
placeholder={placeholder}
label={placeholder}
helperText={helperText}
/>
)
} else if (fieldName === 'otherRegionalPolicy') {
if (!form?.regionalPolicy?.term?.match(/^Other\s/)) {
if (!form?.regionalPolicy?.find(({ term }) => term?.match(/^Other\s/))) {
return null
}
}
Expand Down Expand Up @@ -311,7 +315,7 @@ export default ({ field, formName }) => {
}

if (carbonCreditsFields.includes(fieldName)) {
if (!(form.carbonCredit || '').toBoolean()) {
if (!`'${form.carbonCredit}'`.toBoolean()) {
return null
}
}
Expand Down

0 comments on commit 031ba69

Please sign in to comment.