Skip to content

Commit

Permalink
feat: add indicator list type list view (#433)
Browse files Browse the repository at this point in the history
* feat: add indicator list type list view

* feat: add edit and new form

* chore: update factor schema type

* chore: update name field validation

* chore: update indicator types columns

* fix: prevent indicator types from using attributes

* chore: add notice box when custom attributes throw error
  • Loading branch information
Chisomchima authored Nov 25, 2024
1 parent ba73ad8 commit 2668c68
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 14 deletions.
61 changes: 48 additions & 13 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-11-21T14:53:27.430Z\n"
"PO-Revision-Date: 2024-11-21T14:53:27.430Z\n"
"POT-Creation-Date: 2024-11-25T10:03:10.019Z\n"
"PO-Revision-Date: 2024-11-25T10:03:10.019Z\n"

msgid "schemas"
msgstr "schemas"
Expand Down Expand Up @@ -909,6 +909,9 @@ msgstr "Required"
msgid "Period type"
msgstr "Period type"

msgid "Factor"
msgstr "Factor"

msgid "Basic information"
msgstr "Basic information"

Expand Down Expand Up @@ -949,15 +952,6 @@ msgstr "Filter available category options"
msgid "Filter selected category options"
msgstr "Filter selected category options"

msgid "Choose how this category combo will be used to capture and analyze data."
msgstr "Choose how this category combo will be used to capture and analyze data."

msgid "Skip category total in reports"
msgstr "Skip category total in reports"

msgid "Choose the categories to include in this category combo."
msgstr "Choose the categories to include in this category combo."

msgid "Available categories"
msgstr "Available categories"

Expand All @@ -970,8 +964,46 @@ msgstr "Filter available categories"
msgid "Filter selected categories"
msgstr "Filter selected categories"

msgid "At least one category is required"
msgstr "At least one category is required"
msgid "{{count}} category option combinations will be generated."
msgid_plural "{{count}} category option combinations will be generated."
msgstr[0] "{{count}} category option combinations will be generated."
msgstr[1] "{{count}} category option combinations will be generated."

msgid "More than 4 Categories"
msgstr "More than 4 Categories"

msgid "A Category combination with more than 4 categories is not recommended."
msgstr "A Category combination with more than 4 categories is not recommended."

msgid "Identical Category Combination"
msgstr "Identical Category Combination"

msgid ""
"One or more Category combinations with the same categories already exist in "
"the system. \n"
" It is strongly discouraged to have more than one Category "
"combination with the same categories."
msgstr ""
"One or more Category combinations with the same categories already exist in "
"the system. \n"
" It is strongly discouraged to have more than one Category "
"combination with the same categories."

msgid "Choose how this category combo will be used to capture and analyze data."
msgstr "Choose how this category combo will be used to capture and analyze data."

msgid "Skip category total in reports"
msgstr "Skip category total in reports"

msgid "Choose the categories to include in this category combo."
msgstr "Choose the categories to include in this category combo."

msgid ""
"The number of generated category option combinations exceeds the limit of "
"{{limit}}"
msgstr ""
"The number of generated category option combinations exceeds the limit of "
"{{limit}}"

msgid "Set up the basic information for this category option group set."
msgstr "Set up the basic information for this category option group set."
Expand Down Expand Up @@ -1178,6 +1210,9 @@ msgstr ""
"included. PHU will still be available for the PHU level, but not included "
"in the aggregations to the levels above."

msgid "Set up the basic information for this Indicator Type."
msgstr "Set up the basic information for this Indicator Type."

msgid "Longitude"
msgstr "Longitude"

Expand Down
1 change: 1 addition & 0 deletions src/components/form/FormBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useCustomAttributesQuery } from './attributes'

type MaybeModelWithAttributes = {
id?: string
name?: string
attributeValues?: PartialAttributeValue[] | undefined
}

Expand Down
27 changes: 26 additions & 1 deletion src/lib/sectionList/listViews/sectionListViewsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,37 @@ export const modelListViewsConfig = {
},
indicator: {
columns: {
default: ['name', DESCRIPTORS.publicAccess, 'lastUpdated'],
default: [
'name',
{ label: i18n.t('Indicator Type'), path: 'indicatorType' },
DESCRIPTORS.publicAccess,
'lastUpdated',
],
},
filters: {
default: ['indicatorType'],
},
},
indicatorType: {
columns: {
default: [
'name',
{ label: i18n.t('Factor'), path: 'factor' },
'lastUpdated',
],
available: [
'code',
'created',
'createdBy',
'href',
'id',
'lastUpdatedBy',
],
},
filters: {
default: [],
},
},
categoryOptionGroupSet: {
columns: {
default: [
Expand Down
48 changes: 48 additions & 0 deletions src/pages/indicatorTypes/Edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import { useQuery } from 'react-query'
import { useParams } from 'react-router-dom'
import { DefaultNewFormContents } from '../../components/form/DefaultFormContents'
import { FormBase } from '../../components/form/FormBase'
import { SECTIONS_MAP, useOnSubmitEdit } from '../../lib'
import { useBoundResourceQueryFn } from '../../lib/query/useBoundQueryFn'
import { IndicatorType, PickWithFieldFilters } from '../../types/models'
import { validate } from './form'
import { IndicatorTypesFormFields } from './form/IndicatorTypesFormFields'

const fieldFilters = ['name', 'factor'] as const

export type IndicatorTypesFormValues = PickWithFieldFilters<
IndicatorType,
typeof fieldFilters
> & { id: string }

export const Component = () => {
const section = SECTIONS_MAP.indicatorType
const queryFn = useBoundResourceQueryFn()
const modelId = useParams().id as string

const query = {
resource: 'indicatorTypes',
id: modelId,
params: {
fields: fieldFilters.concat(),
},
}
const indicatorTypeQuery = useQuery({
queryKey: [query],
queryFn: queryFn<IndicatorTypesFormValues>,
})
return (
<FormBase
onSubmit={useOnSubmitEdit({ section, modelId })}
section={section}
initialValues={indicatorTypeQuery.data}
validate={validate}
includeAttributes={false}
>
<DefaultNewFormContents section={section}>
<IndicatorTypesFormFields />
</DefaultNewFormContents>
</FormBase>
)
}
4 changes: 4 additions & 0 deletions src/pages/indicatorTypes/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from 'react'
import { DefaultSectionList } from '../DefaultSectionList'

export const Component = () => <DefaultSectionList />
24 changes: 24 additions & 0 deletions src/pages/indicatorTypes/New.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import { DefaultNewFormContents } from '../../components/form/DefaultFormContents'
import { FormBase } from '../../components/form/FormBase'
import { SECTIONS_MAP, useOnSubmitNew } from '../../lib'
import { validate } from './form'
import { IndicatorTypesFormFields } from './form/IndicatorTypesFormFields'
import { initialValues } from './form/IndicatorTypesSchema'

const section = SECTIONS_MAP.indicatorType

export const Component = () => {
return (
<FormBase
initialValues={initialValues}
onSubmit={useOnSubmitNew({ section })}
validate={validate}
includeAttributes={false}
>
<DefaultNewFormContents section={section}>
<IndicatorTypesFormFields />
</DefaultNewFormContents>
</FormBase>
)
}
50 changes: 50 additions & 0 deletions src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field } from 'react-final-form'
import {
CustomAttributesSection,
StandardFormField,
StandardFormSection,
StandardFormSectionTitle,
StandardFormSectionDescription,
NameField,
} from '../../../components'
import { SECTIONS_MAP, useSchemaSectionHandleOrThrow } from '../../../lib'

export const IndicatorTypesFormFields = () => {
const section = SECTIONS_MAP.indicatorType
const schemaSection = useSchemaSectionHandleOrThrow()

return (
<>
<StandardFormSection>
<StandardFormSectionTitle>
{i18n.t('Basic information')}
</StandardFormSectionTitle>
<StandardFormSectionDescription>
{i18n.t(
'Set up the basic information for this Indicator Type.'
)}
</StandardFormSectionDescription>

<StandardFormField>
<NameField schemaSection={schemaSection} />
</StandardFormField>

<StandardFormField>
<Field
name="factor"
type="number"
inputWidth="400px"
component={InputFieldFF}
label={i18n.t('Factor')}
required
/>
</StandardFormField>
</StandardFormSection>

<CustomAttributesSection schemaSection={section} />
</>
)
}
12 changes: 12 additions & 0 deletions src/pages/indicatorTypes/form/IndicatorTypesSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { z } from 'zod'
import { getDefaults, createFormValidate, modelFormSchemas } from '../../../lib'

const { identifiable } = modelFormSchemas

export const IndicatorSchema = identifiable.extend({
factor: z.coerce.number().int(),
})

export const initialValues = getDefaults(IndicatorSchema)

export const validate = createFormValidate(IndicatorSchema)
1 change: 1 addition & 0 deletions src/pages/indicatorTypes/form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { IndicatorSchema, validate } from './IndicatorTypesSchema'

0 comments on commit 2668c68

Please sign in to comment.