Skip to content

Commit

Permalink
Merge branch 'master' of github-chisom:dhis2/maintenance-app-beta int…
Browse files Browse the repository at this point in the history
…o DHIS2-18440/resolve-data-dimension-issues
  • Loading branch information
Chisomchima committed Dec 5, 2024
2 parents e7ec7cb + c10d79f commit 586a3e6
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 30 deletions.
2 changes: 2 additions & 0 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-12-05T06:06:51.471Z\n"
"PO-Revision-Date: 2024-12-05T06:06:51.471Z\n"
"POT-Creation-Date: 2024-12-03T07:31:45.454Z\n"
"PO-Revision-Date: 2024-12-03T07:31:45.455Z\n"

msgid "schemas"
msgstr "schemas"
Expand Down
11 changes: 7 additions & 4 deletions src/components/form/fields/DateField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18n from '@dhis2/d2-i18n'
import { CalendarInput, CalendarInputProps } from '@dhis2/ui'
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'

Check warning on line 3 in src/components/form/fields/DateField.tsx

View workflow job for this annotation

GitHub Actions / lint

'useEffect' is defined but never used
import { useField } from 'react-final-form'
import { selectedLocale, useSystemSetting } from '../../../lib'

Expand All @@ -16,7 +16,7 @@ type DateFieldProps = Omit<
type ValidationProps = {
error: boolean
validationText?: string
valid?: boolean
valid: boolean
validationCode?: string
}
export function DateField({
Expand All @@ -29,9 +29,12 @@ export function DateField({
const locale = selectedLocale
const [validation, setValidation] = useState<ValidationProps>({
error: false,
valid: true,
})

const { input, meta } = useField<string | undefined>(name)
const { input } = useField<string | undefined>(name, {
format: (value) => (value ? value.substring(0, 10) : ''),
})

const handleChange: CalendarInputProps['onDateSelect'] = (
payload: {
Expand All @@ -47,7 +50,7 @@ export function DateField({
validationText: i18n.t('Required'),
})
} else {
setValidation(payload?.validation || { error: false })
setValidation(payload?.validation || { error: false, valid: true })
}
input.onChange(payload?.calendarDateString || '')
input.onBlur()
Expand Down
7 changes: 2 additions & 5 deletions src/components/form/fields/DescriptionField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import { TextAreaFieldFF } from '@dhis2/ui'
import { createMaxCharacterLength, TextAreaFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field as FieldRFF } from 'react-final-form'
import { SchemaSection, useCheckMaxLengthFromSchema } from '../../../lib'

Check warning on line 5 in src/components/form/fields/DescriptionField.tsx

View workflow job for this annotation

GitHub Actions / lint

'useCheckMaxLengthFromSchema' is defined but never used
Expand All @@ -11,10 +11,7 @@ export function DescriptionField({
helpText?: string
schemaSection: SchemaSection
}) {
const validate = useCheckMaxLengthFromSchema(
schemaSection.name,
'description'
)
const validate = createMaxCharacterLength(2000)

return (
<FieldRFF
Expand Down
7 changes: 6 additions & 1 deletion src/components/sectionList/SectionListWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const SectionListWrapper = ({
BaseListModel | undefined
>(undefined)

const onSharingDialogClose = () => {
setSharingDialogId(undefined)
refetch()
}

const SectionListMessage = () => {
if (error) {
console.log(error.details || error)
Expand Down Expand Up @@ -159,7 +164,7 @@ export const SectionListWrapper = ({
but it works if you pass the correct type*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type={schema.singular as any}
onClose={() => setSharingDialogId(undefined)}
onClose={() => onSharingDialogClose()}
/>
)}
{translationDialogModel && (
Expand Down
1 change: 1 addition & 0 deletions src/lib/sectionList/listViews/sectionListViewsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const modelListViewsConfig = {
},
filters: {
default: [],
overrideDefaultAvailable: true,
},
},
categoryOption: {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sectionList/useSectionListSortOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const isValidSortPathForSchema = (schema: Schema, path: string) => {
const schemaProperty = getSchemaPropertyForPath(schema, path)

// sorting for metadata-API only works on simple and persisted properties
if (schemaProperty && schemaProperty.simple && schemaProperty.persisted) {
if (schemaProperty && schemaProperty.simple) {
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion src/pages/categories/form/categorySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod'
import { getDefaults, createFormValidate, modelFormSchemas } from '../../../lib'
import { Category } from '../../../types/generated'

/* Note that this describes what we send to the server,
/* Note that this describes what we send to the server,
and not what is stored in the form. */
const { identifiable, referenceCollection, withAttributeValues } =
modelFormSchemas
Expand Down
2 changes: 1 addition & 1 deletion src/pages/categoryCombos/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fieldFilters = [
...DEFAULT_FIELD_FILTERS,
'name',
'code',
'categories[id,displayName]',
'categories[id,displayName,categoryOptions~size~rename(categoryOptionsSize)],',
'skipTotal',
'dataDimensionType',
] as const
Expand Down
5 changes: 4 additions & 1 deletion src/pages/categoryCombos/form/CategoryComboFormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import i18n from '@dhis2/d2-i18n'
import { CheckboxFieldFF, RadioFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field } from 'react-final-form'
import { useParams } from 'react-router-dom'
import {
StandardFormField,
StandardFormSection,
StandardFormSectionTitle,
StandardFormSectionDescription,
HorizontalFieldGroup,
ModelTransferField,
NameField,
CodeField,
} from '../../../components'
Expand All @@ -18,6 +18,7 @@ import { CategoriesField } from './CategoriesField'
const section = SECTIONS_MAP.categoryCombo

export const CategoryComboFormFields = () => {
const isNewForm = useParams().id === undefined
return (
<>
<StandardFormSection>
Expand Down Expand Up @@ -55,13 +56,15 @@ export const CategoryComboFormFields = () => {
label={i18n.t('Disaggregation')}
type="radio"
value={'DISAGGREGATION'}
disabled={!isNewForm}
/>
<Field<string | undefined>
name="dataDimensionType"
component={RadioFieldFF}
label={i18n.t('Attribute')}
type="radio"
value={'ATTRIBUTE'}
disabled={!isNewForm}
/>
</HorizontalFieldGroup>
</StandardFormField>
Expand Down
1 change: 1 addition & 0 deletions src/pages/categoryCombos/form/categoryComboSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const categoryComboSchema = identifiable
categoryOptionsSize: z.number(),
})
)
.min(1, i18n.t('At least one category is required'))
.refine(
(categories) => {
const generatedCocsCount = categories.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RadioFieldFF, CheckboxFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field } from 'react-final-form'
import {
CustomAttributesSection,
DefaultIdentifiableFields,
DescriptionField,
HorizontalFieldGroup,
Expand Down Expand Up @@ -112,6 +113,7 @@ function CategoryOptionGroupSetFormFields() {
</StandardFormField>
</StandardFormField>
</StandardFormSection>
<CustomAttributesSection schemaSection={section} />
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RadioFieldFF, CheckboxFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field } from 'react-final-form'
import {
CustomAttributesSection,
DefaultIdentifiableFields,
DescriptionField,
HorizontalFieldGroup,
Expand Down Expand Up @@ -99,6 +100,7 @@ function CategoryOptionGroupFormFields() {
/>
</StandardFormField>
</StandardFormField>
<CustomAttributesSection schemaSection={section} />
</StandardFormSection>
</>
)
Expand Down
1 change: 1 addition & 0 deletions src/pages/categoryOptions/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const fieldFilters = [
...DEFAULT_FIELD_FILTERS,
...ATTRIBUTE_VALUES_FIELD_FILTERS,
'name',
'formName',
'code',
'shortName',
'description',
Expand Down
6 changes: 5 additions & 1 deletion src/pages/organisationUnits/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
} from '../../lib'
import { useBoundResourceQueryFn } from '../../lib/query/useBoundQueryFn'
import { OrganisationUnit, PickWithFieldFilters } from '../../types/generated'
import { OrganisationUnitFormField, validate } from './form'
import {
OrganisationUnitFormField,
organisationUnitSchema,
validate,
} from './form'

const fieldFilters = [
...DEFAULT_FIELD_FILTERS,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/organisationUnits/form/OrganisationUnitSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export function OrganisationUnitSelector() {
const fieldName = 'parent'
const { input, meta } = useField(fieldName, { format: (value) => value })
const userRootOrgUnits = useCurrentUserRootOrgUnits()
const userRootOrgUnitsIds = userRootOrgUnits.map((unit) => `/${unit.id}`)
const userRootOrgUnitsIds = userRootOrgUnits.map((unit) => unit.id)
const userRootOrgUnitsPaths = userRootOrgUnits.map((unit) => unit.path)
const [selected, setSelected] = useState<[string] | []>(
input.value?.path ? [input.value.path] : []
)
Expand Down Expand Up @@ -44,7 +45,7 @@ export function OrganisationUnitSelector() {
roots={userRootOrgUnitsIds}
selected={selected}
initiallyExpanded={[
...userRootOrgUnitsIds,
...userRootOrgUnitsPaths,
...selected,
]}
/>
Expand Down
18 changes: 5 additions & 13 deletions src/pages/organisationUnits/form/organisationUnitSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ export const organisationUnitSchema = identifiable
.extend({
shortName: z.string().trim().default(''),
code: z.string().trim().optional(),
description: z
.string()
.trim()
.max(2147483647, {
message: i18n.t('Should not exceed {{maxLength}} characters', {
maxLength: 2147483647,
}),
})
.optional(),
description: z.string().trim().optional(),
image: z.object({ id: z.string() }).optional(),
phoneNumber: z
.string()
Expand All @@ -33,7 +25,7 @@ export const organisationUnitSchema = identifiable
}),
})
.optional(),
openingDate: z.string().date(),
openingDate: z.coerce.date(),
email: z.string().email().optional(),
address: z
.string()
Expand All @@ -47,12 +39,12 @@ export const organisationUnitSchema = identifiable
.string()
.url({ message: i18n.t('Must be a valid url') })
.optional(),
closedDate: z.string().date().optional(),
closedDate: z.coerce.date().optional(),
comment: z
.string()
.max(2147483647, {
.max(2000, {
message: i18n.t('Should not exceed {{maxLength}} characters', {
maxLength: 2147483647,
maxLength: 2000,
}),
})
.optional(),
Expand Down

0 comments on commit 586a3e6

Please sign in to comment.