Skip to content

Commit

Permalink
feat: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Nov 4, 2024
1 parent 5e98f0c commit dcb5da1
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
29 changes: 25 additions & 4 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-10-28T13:53:29.437Z\n"
"PO-Revision-Date: 2024-10-28T13:53:29.437Z\n"
"POT-Creation-Date: 2024-11-04T08:55:34.983Z\n"
"PO-Revision-Date: 2024-11-04T08:55:34.985Z\n"

msgid "schemas"
msgstr "schemas"
Expand Down Expand Up @@ -819,6 +819,27 @@ msgstr "GeoJSON"
msgid "Disaggregation"
msgstr "Disaggregation"

msgid "Point"
msgstr "Point"

msgid "MultiPoint"
msgstr "MultiPoint"

msgid "LineString"
msgstr "LineString"

msgid "MultiLineString"
msgstr "MultiLineString"

msgid "Polygon"
msgstr "Polygon"

msgid "MultiPolygon"
msgstr "MultiPolygon"

msgid "GeometryCollection"
msgstr "GeometryCollection"

msgid "Aggregation type"
msgstr "Aggregation type"

Expand Down Expand Up @@ -1173,8 +1194,8 @@ msgstr "Filter available programs"
msgid "Filter selected programs"
msgstr "Filter selected programs"

msgid "New organisation unit will be created inside {{displayName}}"
msgstr "New organisation unit will be created inside {{displayName}}"
msgid "Organisation unit will be positioned inside {{displayName}}"
msgstr "Organisation unit will be positioned inside {{displayName}}"

msgid "Creating first organisation unit"
msgstr "Creating first organisation unit"
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/DefaultFormErrorNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const ErrorList = ({ errors }: { errors: Record<string, string> }) => {
>
{labels.get(key) || key}:
</span>
<span>{value}</span>
<span>{JSON.stringify(value)}</span>
</li>
)
})}
Expand Down
11 changes: 11 additions & 0 deletions src/lib/constants/translatedModelConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,22 @@ export const DATA_DIMENSION_TYPE = {
ATTRIBUTE: i18n.t('Attribute'),
}

export const GEOMETRY_TYPE = {
POINT: i18n.t('Point'),
MULTIPOINT: i18n.t('MultiPoint'),
LINESTRING: i18n.t('LineString'),
MULTILINESTRING: i18n.t('MultiLineString'),
POLYGON: i18n.t('Polygon'),
MULTIPOLYGON: i18n.t('MultiPolygon'),
GEOMETRYCOLLECTION: i18n.t('GeometryCollection'),
}

const allConstantTranslations: Record<string, string> = {
...AGGREGATION_TYPE,
...DOMAIN_TYPE,
...VALUE_TYPE,
...DATA_DIMENSION_TYPE,
...GEOMETRY_TYPE,
}

export const getConstantTranslation = (constant: string): string => {
Expand Down
10 changes: 3 additions & 7 deletions src/pages/organisationUnits/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
} from '../../lib'
import { useBoundResourceQueryFn } from '../../lib/query/useBoundQueryFn'
import { OrganisationUnit, PickWithFieldFilters } from '../../types/generated'
import {
FormValues,
OrganisationUnitFormField,
organisationUnitSchema,
} from './form'
import { OrganisationUnitFormField, organisationUnitSchema } from './form'

const fieldFilters = [
...DEFAULT_FIELD_FILTERS,
Expand Down Expand Up @@ -71,8 +67,8 @@ export const Component = () => {
modelId,
})}
section={section}
initialValues={orgUnit.data as FormValues}
validate={(values: FormValues) => {
initialValues={orgUnit.data}
validate={(values: OrgUnitFormValues) => {
return validate(organisationUnitSchema, values)
}}
>
Expand Down
25 changes: 14 additions & 11 deletions src/pages/organisationUnits/form/GeometryFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import i18n from '@dhis2/d2-i18n'
import { Field, InputField } from '@dhis2/ui'
import React from 'react'
import { useField } from 'react-final-form'
import { getConstantTranslation } from '../../../lib'

export function GeometryFields() {
const fieldName = 'geometry'
Expand All @@ -11,8 +12,8 @@ export function GeometryFields() {
longitude,
latitude,
}: {
longitude?: string
latitude?: string
longitude?: number
latitude?: number
}) => {
const geometry = {
type: 'Point',
Expand All @@ -26,37 +27,39 @@ export function GeometryFields() {
<>
<Field
name={fieldName}
error={meta.touched && meta.error}
validationText={meta.touched ? meta.error : undefined}
error={meta.touched && !!meta.error}
validationText={meta.touched ? meta.error?.type : undefined}
>
<InputField
onChange={(e) =>
handleChange({
longitude: e.value,
latitude: input.value.coordinates?.[1],
longitude: e.value
? parseFloat(e.value)
: undefined,
latitude: input.value?.coordinates?.[1],
})
}
label={i18n.t('Longitude')}
inputWidth="400px"
name="longitude"
type="number"
value={input.value.coordinates?.[0].toString()}
value={input.value.coordinates?.[0]?.toString()}
min="-90"
max="90"
step="any"
/>
<InputField
onChange={(e) =>
handleChange({
longitude: input.value.coordinates?.[0],
latitude: e.value,
longitude: input.value?.coordinates?.[0],
latitude: e.value ? parseFloat(e.value) : undefined,
})
}
inputWidth="400px"
label={i18n.t('Longitude')}
name="latitude"
type="number"
value={input.value.coordinates?.[1].toString()}
value={input.value?.coordinates?.[1]?.toString()}
min="-180"
max="180"
step="any"
Expand All @@ -66,7 +69,7 @@ export function GeometryFields() {
) : (
<InputField
value={i18n.t('{{type}} coordinates are not editable', {
type: input.value?.type,
type: getConstantTranslation(input.value?.type),
})}
inputWidth="400px"
disabled
Expand Down
16 changes: 14 additions & 2 deletions src/pages/organisationUnits/form/organisationUnitSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,21 @@ export const organisationUnitSchema = identifiable
parent: z.object({ id: z.string() }).optional(),
geometry: z
.object({
longitude: z.string().optional(),
latitude: z.string().optional(),
type: z.literal('Point'),
coordinates: z.array(z.number()).length(2),
})
.or(
z.object({
type: z.union([
z.literal('Multipoint'),
z.literal('Linestring'),
z.literal('Multilinestring'),
z.literal('Polygon'),
z.literal('Multipolygon'),
z.literal('Geometrycollection'),
]),
})
)
.optional(),
programs: referenceCollection.optional().default([]),
dataSets: referenceCollection.optional().default([]),
Expand Down

0 comments on commit dcb5da1

Please sign in to comment.