Skip to content

Commit

Permalink
feat(Org. Unit): single select
Browse files Browse the repository at this point in the history
  • Loading branch information
adeelshahid committed May 18, 2018
1 parent 609cd48 commit eebffad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const TYPE_RADIO = 'fieldType/RADIO'
export const TYPE_SELECT = 'fieldType/SELECT'
export const TYPE_SCHEMAS = 'fieldType/SCHEMAS'
export const TYPE_ORG_UNIT = 'fieldType/ORG_UNIT'
export const TYPE_ORG_UNIT_SINGLE_SELECT = 'fieldType/ORG_UNIT_SINGLE_SELECT'
export const TYPE_MORE_OPTIONS = 'fieldType/MORE_OPTIONS'
export const TYPE_DATASET_PICKER = 'fieldType/DATASET_PICKER'

Expand Down Expand Up @@ -124,6 +125,25 @@ export class Form extends React.Component {
/>
</FormControl>
)
} else if (type === TYPE_ORG_UNIT_SINGLE_SELECT) {
const { selected, value } = fieldValues[name]
if (value === null) {
return null
}

return (
<FormControl key={`orgUnitTree-${name}`} className={s.formControl}>
<FormLabel className={s.formLabel}>{label}</FormLabel>
<OrgUnitTree
root={value}
selected={selected}
onSelectClick={(evt, orgUnit) =>
this.props.onChange(name, orgUnit)
}
hideCheckboxes={true}
/>
</FormControl>
)
} else if (type === TYPE_DATASET_PICKER) {
const { selected, value } = fieldValues[name]
if (value === null) {
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TYPE_SELECT,
TYPE_SCHEMAS,
TYPE_ORG_UNIT,
TYPE_ORG_UNIT_SINGLE_SELECT,
TYPE_DATASET_PICKER
} from 'components/Form'
import { api } from 'services'
Expand Down Expand Up @@ -43,6 +44,10 @@ export function getFieldState(name, value, fields, state) {
}

state[name]['selected'] = list
} else if (f.type === TYPE_ORG_UNIT_SINGLE_SELECT) {
let list = state[name]['selected']
console.log('id', value.id, 'path', value.path)
state[name]['selected'] = list.includes(value.path) ? [] : [value.path]
}

return state
Expand Down

0 comments on commit eebffad

Please sign in to comment.