Skip to content

Commit

Permalink
fix: small fixxes
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Dec 23, 2024
1 parent 89ae19b commit a3a9ae5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function ModelSingleSelectField<TModel extends DisplayableModel>({
input.onBlur()
onChange?.(selected)
}}
invalid={meta.touched && !!meta.error}
/>
</Field>
)
Expand Down
24 changes: 24 additions & 0 deletions src/lib/constants/translatedModelConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,37 @@ export const FORM_TYPE = {
SECTION_MULTIORG: i18n.t('Section Multi-org'),
}

const PERIOD_TYPE = {
BiMonthly: i18n.t('BiMonthly'),
BiWeekly: i18n.t('BiWeekly'),
Daily: i18n.t('Daily'),
FinancialApril: i18n.t('FinancialApril'),
FinancialJuly: i18n.t('FinancialJuly'),
FinancialNov: i18n.t('FinancialNov'),
FinancialOct: i18n.t('FinancialOct'),
Monthly: i18n.t('Monthly'),
Quarterly: i18n.t('Quarterly'),
QuarterlyNov: i18n.t('QuarterlyNov'),
SixMonthlyApril: i18n.t('SixMonthlyApril'),
SixMonthlyNov: i18n.t('SixMonthlyNov'),
SixMonthly: i18n.t('SixMonthly'),
TwoYearly: i18n.t('TwoYearly'),
Weekly: i18n.t('Weekly'),
WeeklySaturday: i18n.t('WeeklySaturday'),
WeeklySunday: i18n.t('WeeklySunday'),
WeeklyThursday: i18n.t('WeeklyThursday'),
WeeklyWednesday: i18n.t('WeeklyWednesday'),
Yearly: i18n.t('Yearly'),
}

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

export const getConstantTranslation = (constant: string): string => {
Expand Down
52 changes: 19 additions & 33 deletions src/pages/dataSetsWip/form/CategoryComboField.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
import i18n from '@dhis2/d2-i18n'
import { Field } from '@dhis2/ui'
import React from 'react'
import { useField } from 'react-final-form'
import { ModelSingleSelect } from '../../../components/metadataFormControls/ModelSingleSelect'
import { ModelSingleSelectField } from '../../../components/metadataFormControls/ModelSingleSelect'
import { DEFAULT_CATEGORY_COMBO } from '../../../lib'

export function CategoryComboField() {
const { input, meta } = useField('categoryCombo')

const CATEGORY_COMBOS_QUERY = {
resource: 'categoryCombos',
params: {
filter: ['dataDimensionType:eq:ATTRIBUTE'],
},
}
const CATEGORY_COMBOS_QUERY = {
resource: 'categoryCombos',
params: {
filter: ['dataDimensionType:eq:ATTRIBUTE'],
},
}

const DEFAULT_CATEGORY_SELECT_OPTION = {
id: DEFAULT_CATEGORY_COMBO.id,
displayName: DEFAULT_CATEGORY_COMBO.displayName,
}
const DEFAULT_CATEGORY_SELECT_OPTION = {
id: DEFAULT_CATEGORY_COMBO.id,
displayName: DEFAULT_CATEGORY_COMBO.displayName,
}

export function CategoryComboField() {
return (
<Field
<ModelSingleSelectField
required
name="categoryCombo"
label={i18n.t('{{fieldLabel}} (required)', {
fieldLabel: i18n.t('Category combination'),
})}
error={meta.touched && !!meta.error}
validationText={meta.touched ? meta.error : undefined}
>
<ModelSingleSelect
selected={input.value}
query={CATEGORY_COMBOS_QUERY}
invalid={meta.touched && !!meta.error}
onChange={(selected) => {
input.onChange(selected)
}}
transform={(catCombos) => [
...catCombos,
DEFAULT_CATEGORY_SELECT_OPTION,
]}
/>
</Field>
query={CATEGORY_COMBOS_QUERY}
transform={(catCombos) => [
DEFAULT_CATEGORY_SELECT_OPTION,
...catCombos,
]}
/>
)
}
4 changes: 2 additions & 2 deletions src/pages/dataSetsWip/form/PeriodTypeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useField } from 'react-final-form'
import { useQuery } from 'react-query'
import { SearchableSingleSelect } from '../../../components'
import { useBoundResourceQueryFn } from '../../../lib/query/useBoundQueryFn'
import { getConstantTranslation } from '../../../lib'

Check failure on line 8 in src/pages/dataSetsWip/form/PeriodTypeField.tsx

View workflow job for this annotation

GitHub Actions / lint

`../../../lib` import should occur before import of `../../../lib/query/useBoundQueryFn`

export type PeriodTypes = { periodTypes: [{ name: string }] }
const periodTypesToTranslatedValues: Record<string, string> = {
Expand Down Expand Up @@ -49,8 +50,7 @@ export function PeriodTypeField() {
const options = useMemo(() => {
return data
? data.periodTypes.map((period) => ({
label:
periodTypesToTranslatedValues[period.name] || period.name,
label: getConstantTranslation(period.name),
value: period.name,
}))
: []
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dataSetsWip/form/dataSetFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const dataSetFormSchema = identifiable
style,
dataElements: referenceCollection.default([]),
categoryCombo: z
.object({ id: z.string() })
.default({ id: DEFAULT_CATEGORY_COMBO.id }),
.object({ id: z.string(), displayName: z.string() })
.default({ ...DEFAULT_CATEGORY_COMBO }),
periodType: z.string().default('Monthly'),
})

Expand Down

0 comments on commit a3a9ae5

Please sign in to comment.