-
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.
- Loading branch information
1 parent
fd3884d
commit 44a6b44
Showing
7 changed files
with
341 additions
and
15 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/views/AlertDetails/AreaAlertInfo/AreaInfoDetail/i18n.json
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,13 @@ | ||
{ | ||
"namespace": "areaAlertInfo", | ||
"strings": { | ||
"areaAlertInfoGeoCode":"Geo Code", | ||
"areaAlertInfoValueName": "Value Name", | ||
"areaAlertInfoValue": "Value", | ||
"areaAlertAreaDescription": "Area Description", | ||
"areaAlertPolygon": "Area Polygon & Circle", | ||
"areaAlertChooseAnOption": "Choose an option", | ||
"areaAlertGeocodes": "Geocodes" | ||
} | ||
} | ||
|
110 changes: 110 additions & 0 deletions
110
src/views/AlertDetails/AreaAlertInfo/AreaInfoDetail/index.tsx
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,110 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
Check warning on line 1 in src/views/AlertDetails/AreaAlertInfo/AreaInfoDetail/index.tsx GitHub Actions / Lint JS
|
||
import { | ||
Header, | ||
SelectInput, | ||
Table, | ||
TabPanel, | ||
TextOutput, | ||
} from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
import { createStringColumn } from '@ifrc-go/ui/utils'; | ||
|
||
import { GetAreaAlertInfoQuery } from '#generated/types/graphql'; | ||
import { stringIdSelector } from '#utils/selectors'; | ||
import { EntriesAsList } from '../../../../types'; | ||
|
||
import i18n from './i18n.json'; | ||
|
||
type AreaInfo = NonNullable<NonNullable<GetAreaAlertInfoQuery['public']>['alertInfo']>['areas'][number]; | ||
|
||
type PolygonInfo = NonNullable<AreaInfo['polygons'][number]>; | ||
type GeocodeInfo = NonNullable<AreaInfo['geocodes'][number]>; | ||
|
||
export interface FilterValue { | ||
polygon: string | undefined; | ||
} | ||
|
||
interface Props { | ||
data: AreaInfo; | ||
onChange?: React.Dispatch<React.SetStateAction<FilterValue>>; | ||
value?: FilterValue; | ||
} | ||
|
||
const keySelector = (polygon: PolygonInfo) => polygon.id; | ||
const labelSelector = (polygon: PolygonInfo) => polygon.value; | ||
|
||
function AreaInfoDetail(props: Props) { | ||
const { | ||
data, | ||
onChange, | ||
value, | ||
} = props; | ||
|
||
const strings = useTranslation(i18n); | ||
|
||
const columns = useMemo(() => ([ | ||
createStringColumn<GeocodeInfo, string>( | ||
'value', | ||
strings.areaAlertInfoGeoCode, | ||
(item) => item.alertInfoAreaId, | ||
), | ||
createStringColumn<GeocodeInfo, string>( | ||
'value', | ||
strings.areaAlertInfoValueName, | ||
(item) => item.valueName, | ||
), | ||
createStringColumn<GeocodeInfo, string>( | ||
'value', | ||
strings.areaAlertInfoValue, | ||
(item) => item.value, | ||
), | ||
]), [ | ||
strings.areaAlertInfoGeoCode, | ||
strings.areaAlertInfoValueName, | ||
strings.areaAlertInfoValue, | ||
]); | ||
|
||
const handleChange = useCallback( | ||
(...args: EntriesAsList<FilterValue>) => { | ||
const [val, key] = args; | ||
onChange((prevValue): FilterValue => ({ | ||
...prevValue, | ||
[key]: val, | ||
})); | ||
}, | ||
[onChange], | ||
); | ||
|
||
return ( | ||
<TabPanel name={data.id}> | ||
<TextOutput | ||
label={strings.areaAlertAreaDescription} | ||
value={data?.areaDesc} | ||
/> | ||
<Header | ||
heading={strings.areaAlertPolygon} | ||
/> | ||
<SelectInput | ||
name="polygon" | ||
placeholder={strings.areaAlertChooseAnOption} | ||
options={data?.polygons} | ||
keySelector={keySelector} | ||
labelSelector={labelSelector} | ||
value={value?.polygon} | ||
onChange={handleChange} | ||
/> | ||
<Header | ||
heading={strings.areaAlertGeocodes} | ||
/> | ||
<Table | ||
columns={columns} | ||
keySelector={stringIdSelector} | ||
data={data?.geocodes} | ||
filtered={false} | ||
pending={false} | ||
/> | ||
</TabPanel> | ||
); | ||
} | ||
|
||
export default AreaInfoDetail; |
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,26 @@ | ||
{ | ||
"namespace": "areaAlertInfo", | ||
"strings": { | ||
"alertInfoArea": "Area", | ||
"alertInfoHeadline": "Headline", | ||
"alertInfoLanguage": "Language", | ||
"alertInfoEvent": "Event", | ||
"alertInfoUrgency": "Urgency", | ||
"alertInfoSeverity": "Severity", | ||
"alertInfoCertainty": "Certainty", | ||
"alertInfoOnset": "Onset", | ||
"alertInfoExpires": "Expires", | ||
"alertInfoSenderName": "Sender Name", | ||
"alertInfoAreaDescription": "Area Description", | ||
"alertInfoDescription": "Description", | ||
"alertInfoInstruction": "Instruction", | ||
"alertInfoCategory": "Category", | ||
"alertInfoResponseType": "Response Type", | ||
"alertInfoAudience": "Audience", | ||
"alertInfoEventCode": "Event Code", | ||
"alertInfoEffective": "Effective", | ||
"alertInfoWeb": "Web", | ||
"alertInfoContact": "Contact" | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.area-info { | ||
display: flex; | ||
} |
Oops, something went wrong.