-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: show authorities in a MultiSelect rather than an input text field
- Loading branch information
Showing
5 changed files
with
112 additions
and
29 deletions.
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,57 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { Field, MultiSelect, MultiSelectOption } from '@dhis2/ui' | ||
import * as React from 'react' | ||
import { ApiRouteData, Authority } from '../../types/RouteInfo' | ||
|
||
type AuthoritiesSelectProps = { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
route: ApiRouteData | {} | ||
authorities: Authority[] | ||
onSelect: React.Dispatch<React.SetStateAction<string[]>> | ||
} | ||
|
||
const AuthoritiesSelect: React.FC<AuthoritiesSelectProps> = ({ | ||
route, | ||
authorities, | ||
onSelect, | ||
}) => { | ||
const [selectedAuthorities, setSelectedAuthorities] = React.useState< | ||
string[] | ||
>(() => route.authorities ?? []) | ||
|
||
const onChange = ({ selected }) => { | ||
setSelectedAuthorities(selected) | ||
} | ||
const onBlur = () => { | ||
onSelect(selectedAuthorities) | ||
} | ||
return ( | ||
<Field | ||
label={i18n.t('Authorities')} | ||
helpText={i18n.t('Restrict access to cerain authorities')} | ||
> | ||
<MultiSelect | ||
filterPlaceholder={i18n.t('Select authorities')} | ||
clearable | ||
clearText={i18n.t('Clear')} | ||
filterable | ||
onChange={onChange} | ||
selected={selectedAuthorities} | ||
noMatchText={i18n.t('No authority found')} | ||
onBlur={onBlur} | ||
> | ||
{authorities?.map((authority) => { | ||
return ( | ||
<MultiSelectOption | ||
key={authority.id} | ||
label={`${authority.id} (${authority.name})`} | ||
value={authority.id} | ||
></MultiSelectOption> | ||
) | ||
})} | ||
</MultiSelect> | ||
</Field> | ||
) | ||
} | ||
|
||
export default AuthoritiesSelect |
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
097dad9
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.
🎉 Published on https://route-manager.netlify.dhis2.org as production
🚀 Deployed on https://67162241cdd15a2e84e58a86.route-manager.netlify.dhis2.org