From 50acb1050d0e16d00f6d71a24ab40ec273dda660 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Tue, 5 Nov 2024 09:32:27 +0100 Subject: [PATCH 01/10] feat: add indicator list type list view --- src/pages/indicatorTypes/List.tsx | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/pages/indicatorTypes/List.tsx diff --git a/src/pages/indicatorTypes/List.tsx b/src/pages/indicatorTypes/List.tsx new file mode 100644 index 00000000..b310e1bd --- /dev/null +++ b/src/pages/indicatorTypes/List.tsx @@ -0,0 +1,4 @@ +import React from 'react' +import { DefaultSectionList } from '../DefaultSectionList' + +export const Component = () => From 101293920af96137cae40284b40a1abd9698618b Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Thu, 7 Nov 2024 13:50:57 +0100 Subject: [PATCH 02/10] feat: add edit and new form --- src/components/form/FormBase.tsx | 10 ++-- src/pages/indicatorTypes/Edit.tsx | 47 ++++++++++++++++++ src/pages/indicatorTypes/New.tsx | 23 +++++++++ .../form/IndicatorTypesFormFields.tsx | 48 +++++++++++++++++++ .../form/IndicatorTypesSchema.ts | 16 +++++++ src/pages/indicatorTypes/form/index.ts | 1 + src/types/generated/models.ts | 2 +- 7 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 src/pages/indicatorTypes/Edit.tsx create mode 100644 src/pages/indicatorTypes/New.tsx create mode 100644 src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx create mode 100644 src/pages/indicatorTypes/form/IndicatorTypesSchema.ts create mode 100644 src/pages/indicatorTypes/form/index.ts diff --git a/src/components/form/FormBase.tsx b/src/components/form/FormBase.tsx index 55acf870..7aa41a8d 100644 --- a/src/components/form/FormBase.tsx +++ b/src/components/form/FormBase.tsx @@ -1,4 +1,4 @@ -import { NoticeBox } from '@dhis2/ui' +// import { NoticeBox } from '@dhis2/ui' import React, { useMemo } from 'react' import { FormProps, Form as ReactFinalForm } from 'react-final-form' import { @@ -10,6 +10,8 @@ import { useCustomAttributesQuery } from './attributes' type MaybeModelWithAttributes = { id?: string + name?: string + factor?: string attributeValues?: PartialAttributeValue[] | undefined } @@ -44,9 +46,9 @@ export function FormBase({ } }, [customAttributes.data, initialValues, includeAttributes]) - if (customAttributes.error) { - return - } + // if (customAttributes.error) { + // return + // } if (!initialValuesWithAttributes || customAttributes.loading) { return diff --git a/src/pages/indicatorTypes/Edit.tsx b/src/pages/indicatorTypes/Edit.tsx new file mode 100644 index 00000000..b264009c --- /dev/null +++ b/src/pages/indicatorTypes/Edit.tsx @@ -0,0 +1,47 @@ +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, + }) + return ( + + + + + + ) +} diff --git a/src/pages/indicatorTypes/New.tsx b/src/pages/indicatorTypes/New.tsx new file mode 100644 index 00000000..b1e55ac9 --- /dev/null +++ b/src/pages/indicatorTypes/New.tsx @@ -0,0 +1,23 @@ +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 ( + + + + + + ) +} diff --git a/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx b/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx new file mode 100644 index 00000000..93d855ca --- /dev/null +++ b/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx @@ -0,0 +1,48 @@ +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, +} from '../../../components' + +export const IndicatorTypesFormFields = () => { + return ( + <> + + + {i18n.t('Basic information')} + + + {i18n.t( + 'Set up the basic information for this Indicator Type.' + )} + + + + + + + + + + + + + ) +} diff --git a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts new file mode 100644 index 00000000..a52e9809 --- /dev/null +++ b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts @@ -0,0 +1,16 @@ +import { z } from 'zod' +import { getDefaults, createFormValidate, modelFormSchemas } from '../../../lib' + +const { identifiable } = modelFormSchemas + +export const IndicatorSchema = identifiable.extend({ + name: z.string().min(1, 'Name is required'), + factor: z + .string() + .min(1, 'Factor is required') + .regex(/^\d+(\.\d+)?$/, 'Factor must be a valid number'), +}) + +export const initialValues = getDefaults(IndicatorSchema) + +export const validate = createFormValidate(IndicatorSchema) diff --git a/src/pages/indicatorTypes/form/index.ts b/src/pages/indicatorTypes/form/index.ts new file mode 100644 index 00000000..cddbed8b --- /dev/null +++ b/src/pages/indicatorTypes/form/index.ts @@ -0,0 +1 @@ +export { IndicatorSchema, validate } from './IndicatorTypesSchema' diff --git a/src/types/generated/models.ts b/src/types/generated/models.ts index 42d47c20..af8fd6a7 100644 --- a/src/types/generated/models.ts +++ b/src/types/generated/models.ts @@ -4776,7 +4776,7 @@ export type IndicatorType = { created: string createdBy: User displayName: string - factor: number + factor: string favorite: boolean favorites: Array href: string From 91d58e34c032a46628bc8e70b5fb7805b6de01d3 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Tue, 12 Nov 2024 07:38:40 +0100 Subject: [PATCH 03/10] chore: update factor schema type --- src/components/form/FormBase.tsx | 6 ------ .../listViews/sectionListViewsConfig.ts | 20 ++++++++++++++++++- src/pages/indicatorTypes/Edit.tsx | 4 ++-- .../form/IndicatorTypesSchema.ts | 5 +---- src/types/generated/models.ts | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/components/form/FormBase.tsx b/src/components/form/FormBase.tsx index 7aa41a8d..93cd4f62 100644 --- a/src/components/form/FormBase.tsx +++ b/src/components/form/FormBase.tsx @@ -1,4 +1,3 @@ -// import { NoticeBox } from '@dhis2/ui' import React, { useMemo } from 'react' import { FormProps, Form as ReactFinalForm } from 'react-final-form' import { @@ -11,7 +10,6 @@ import { useCustomAttributesQuery } from './attributes' type MaybeModelWithAttributes = { id?: string name?: string - factor?: string attributeValues?: PartialAttributeValue[] | undefined } @@ -46,10 +44,6 @@ export function FormBase({ } }, [customAttributes.data, initialValues, includeAttributes]) - // if (customAttributes.error) { - // return - // } - if (!initialValuesWithAttributes || customAttributes.loading) { return } diff --git a/src/lib/sectionList/listViews/sectionListViewsConfig.ts b/src/lib/sectionList/listViews/sectionListViewsConfig.ts index 6c78bf72..6f8ff9e5 100644 --- a/src/lib/sectionList/listViews/sectionListViewsConfig.ts +++ b/src/lib/sectionList/listViews/sectionListViewsConfig.ts @@ -128,12 +128,30 @@ 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' }, + DESCRIPTORS.publicAccess, + 'lastUpdated', + ], + }, + filters: { + default: [], + }, + }, categoryOptionGroupSet: { columns: { default: [ diff --git a/src/pages/indicatorTypes/Edit.tsx b/src/pages/indicatorTypes/Edit.tsx index b264009c..da6b6f5f 100644 --- a/src/pages/indicatorTypes/Edit.tsx +++ b/src/pages/indicatorTypes/Edit.tsx @@ -28,7 +28,7 @@ export const Component = () => { fields: fieldFilters.concat(), }, } - const IndicatorTypeQuery = useQuery({ + const indicatorTypeQuery = useQuery({ queryKey: [query], queryFn: queryFn, }) @@ -36,7 +36,7 @@ export const Component = () => { diff --git a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts index a52e9809..a349d138 100644 --- a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts +++ b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts @@ -5,10 +5,7 @@ const { identifiable } = modelFormSchemas export const IndicatorSchema = identifiable.extend({ name: z.string().min(1, 'Name is required'), - factor: z - .string() - .min(1, 'Factor is required') - .regex(/^\d+(\.\d+)?$/, 'Factor must be a valid number'), + factor: z.coerce.number().int(), }) export const initialValues = getDefaults(IndicatorSchema) diff --git a/src/types/generated/models.ts b/src/types/generated/models.ts index af8fd6a7..42d47c20 100644 --- a/src/types/generated/models.ts +++ b/src/types/generated/models.ts @@ -4776,7 +4776,7 @@ export type IndicatorType = { created: string createdBy: User displayName: string - factor: string + factor: number favorite: boolean favorites: Array href: string From 6ae2c7f85aa66c604626f087c7b4a26c916a526f Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Mon, 18 Nov 2024 06:39:55 +0100 Subject: [PATCH 04/10] chore: update name field validation --- i18n/en.pot | 77 ++++++++++++------- .../listViews/sectionListViewsConfig.ts | 1 - .../form/IndicatorTypesFormFields.tsx | 11 ++- .../form/IndicatorTypesSchema.ts | 1 - 4 files changed, 54 insertions(+), 36 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index b05cae63..5c2f888d 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-05T14:43:19.245Z\n" -"PO-Revision-Date: 2024-11-05T14:43:19.245Z\n" +"POT-Creation-Date: 2024-11-18T05:31:50.557Z\n" +"PO-Revision-Date: 2024-11-18T05:31:50.557Z\n" msgid "schemas" msgstr "schemas" @@ -900,6 +900,9 @@ msgstr "Created successfully" msgid "Required" msgstr "Required" +msgid "Factor" +msgstr "Factor" + msgid "Basic information" msgstr "Basic information" @@ -964,6 +967,48 @@ msgstr "Filter selected categories" msgid "At least one category is required" msgstr "At least one category is required" +msgid "Set up the basic information for this category option group set." +msgstr "Set up the basic information for this category option group set." + +msgid "Explain the purpose of this category option group set." +msgstr "Explain the purpose of this category option group set." + +msgid "" +"Choose how this category option group set will be used to capture and " +"analyze" +msgstr "" +"Choose how this category option group set will be used to capture and " +"analyze" + +msgid "" +"Category option group set will be available to the analytics as another " +"dimension" +msgstr "" +"Category option group set will be available to the analytics as another " +"dimension" + +msgid "Category option Groups" +msgstr "Category option Groups" + +msgid "" +"Choose the category option groups to include in this category option group " +"set." +msgstr "" +"Choose the category option groups to include in this category option group " +"set." + +msgid "Available category option groups" +msgstr "Available category option groups" + +msgid "Selected category option groups" +msgstr "Selected category option groups" + +msgid "Filter available category option groups" +msgstr "Filter available category option groups" + +msgid "Filter selected category option groups" +msgstr "Filter selected category option groups" + msgid "Set up the basic information for this category option group." msgstr "Set up the basic information for this category option group." @@ -1121,26 +1166,8 @@ msgstr "" "included. PHU will still be available for the PHU level, but not included " "in the aggregations to the levels above." -msgid "Setup" -msgstr "Setup" - -msgid "Data" -msgstr "Data" - -msgid "Data Elements" -msgstr "Data Elements" - -msgid "Periods" -msgstr "Periods" - -msgid "Organisation Units" -msgstr "Organisation Units" - -msgid "Form" -msgstr "Form" - -msgid "Advanced" -msgstr "Advanced" +msgid "Set up the basic information for this Indicator Type." +msgstr "Set up the basic information for this Indicator Type." msgid "Longitude" msgstr "Longitude" @@ -1200,12 +1227,6 @@ msgstr "Set up the organisation unit location." msgid "Reference assignment" msgstr "Reference assignment" -msgid "Longitude" -msgstr "Longitude" - -msgid "Reference assignment" -msgstr "Reference assignment" - msgid "Assign the organisation unit to related objects." msgstr "Assign the organisation unit to related objects." diff --git a/src/lib/sectionList/listViews/sectionListViewsConfig.ts b/src/lib/sectionList/listViews/sectionListViewsConfig.ts index 6f8ff9e5..4aa648d8 100644 --- a/src/lib/sectionList/listViews/sectionListViewsConfig.ts +++ b/src/lib/sectionList/listViews/sectionListViewsConfig.ts @@ -144,7 +144,6 @@ export const modelListViewsConfig = { default: [ 'name', { label: i18n.t('Factor'), path: 'factor' }, - DESCRIPTORS.publicAccess, 'lastUpdated', ], }, diff --git a/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx b/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx index 93d855ca..1808845f 100644 --- a/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx +++ b/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx @@ -8,9 +8,12 @@ import { StandardFormSection, StandardFormSectionTitle, StandardFormSectionDescription, + NameField, } from '../../../components' +import { useSchemaSectionHandleOrThrow } from '../../../lib' export const IndicatorTypesFormFields = () => { + const schemaSection = useSchemaSectionHandleOrThrow() return ( <> @@ -24,18 +27,14 @@ export const IndicatorTypesFormFields = () => { - + Date: Mon, 18 Nov 2024 14:40:57 +0100 Subject: [PATCH 05/10] chore: update indicator types columns --- i18n/en.pot | 16 ++++++++-------- .../listViews/sectionListViewsConfig.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 9013acc8..cf9251c7 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,12 +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-18T05:31:50.557Z\n" -"PO-Revision-Date: 2024-11-18T05:31:50.557Z\n" -"POT-Creation-Date: 2024-11-13T12:57:12.003Z\n" -"PO-Revision-Date: 2024-11-13T12:57:12.004Z\n" -"POT-Creation-Date: 2024-11-13T08:29:01.348Z\n" -"PO-Revision-Date: 2024-11-13T08:29:01.348Z\n" +"POT-Creation-Date: 2024-11-18T13:37:21.548Z\n" +"PO-Revision-Date: 2024-11-18T13:37:21.548Z\n" msgid "schemas" msgstr "schemas" @@ -910,11 +906,12 @@ msgstr "Created successfully" msgid "Required" msgstr "Required" -msgid "Factor" -msgstr "Factor" msgid "Period type" msgstr "Period type" +msgid "Factor" +msgstr "Factor" + msgid "Basic information" msgstr "Basic information" @@ -1046,6 +1043,9 @@ msgstr "" "Choose when, and for which organisation units this category option will be " "available." +msgid "Form name should not exceed 230 characters" +msgstr "Form name should not exceed 230 characters" + msgid "End date should be after start date" msgstr "End date should be after start date" diff --git a/src/lib/sectionList/listViews/sectionListViewsConfig.ts b/src/lib/sectionList/listViews/sectionListViewsConfig.ts index 0e8d21e3..7265f060 100644 --- a/src/lib/sectionList/listViews/sectionListViewsConfig.ts +++ b/src/lib/sectionList/listViews/sectionListViewsConfig.ts @@ -172,6 +172,14 @@ export const modelListViewsConfig = { { label: i18n.t('Factor'), path: 'factor' }, 'lastUpdated', ], + available: [ + 'code', + 'created', + 'createdBy', + 'href', + 'id', + 'lastUpdatedBy', + ], }, filters: { default: [], From 6894951020d6e71cb2d5de9edc445246355a5de2 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Mon, 25 Nov 2024 09:58:20 +0100 Subject: [PATCH 06/10] fix: prevent indicator types from using attributes --- src/pages/indicatorTypes/Edit.tsx | 1 + src/pages/indicatorTypes/New.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pages/indicatorTypes/Edit.tsx b/src/pages/indicatorTypes/Edit.tsx index da6b6f5f..4b395c31 100644 --- a/src/pages/indicatorTypes/Edit.tsx +++ b/src/pages/indicatorTypes/Edit.tsx @@ -38,6 +38,7 @@ export const Component = () => { section={section} initialValues={indicatorTypeQuery.data} validate={validate} + includeAttributes={false} > diff --git a/src/pages/indicatorTypes/New.tsx b/src/pages/indicatorTypes/New.tsx index b1e55ac9..91130e55 100644 --- a/src/pages/indicatorTypes/New.tsx +++ b/src/pages/indicatorTypes/New.tsx @@ -14,6 +14,7 @@ export const Component = () => { initialValues={initialValues} onSubmit={useOnSubmitNew({ section })} validate={validate} + includeAttributes={false} > From 29d317299135e89d9ca475017c7ada4fc58c63ba Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Mon, 25 Nov 2024 11:07:53 +0100 Subject: [PATCH 07/10] chore: add notice box when custom attributes throw error --- i18n/en.pot | 55 ++++++++++++++++++++++++-------- src/components/form/FormBase.tsx | 5 +++ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 9b795723..b0ac10ae 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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" @@ -952,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" @@ -973,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." diff --git a/src/components/form/FormBase.tsx b/src/components/form/FormBase.tsx index 5bea3844..6a55775f 100644 --- a/src/components/form/FormBase.tsx +++ b/src/components/form/FormBase.tsx @@ -1,3 +1,4 @@ +import { NoticeBox } from '@dhis2/ui' import React, { useMemo } from 'react' import { FormProps, Form as ReactFinalForm } from 'react-final-form' import { defaultValueFormatter } from '../../lib/form/useOnSubmit' @@ -48,6 +49,10 @@ export function FormBase({ } }, [customAttributes.data, initialValues, includeAttributes]) + if (customAttributes.error) { + return + } + if (!initialValuesWithAttributes || customAttributes.loading) { return } From d78455af2bcb082d5e2a5e4bb6651e8f9157ab99 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Mon, 25 Nov 2024 22:37:56 +0100 Subject: [PATCH 08/10] chore: add extra validation for indicator types forms --- src/pages/indicatorTypes/form/IndicatorTypesSchema.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts index d9b6d1a1..0c20681d 100644 --- a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts +++ b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts @@ -4,7 +4,14 @@ import { getDefaults, createFormValidate, modelFormSchemas } from '../../../lib' const { identifiable } = modelFormSchemas export const IndicatorSchema = identifiable.extend({ - factor: z.coerce.number().int(), + factor: z.coerce + .number({ invalid_type_error: 'Please enter a number' }) + .int() + .min(1, 'Please enter a value above 0') + .max( + Number.MAX_SAFE_INTEGER, + `The number is too large. Please enter a valid integer.` + ), }) export const initialValues = getDefaults(IndicatorSchema) From 66da56f0716da42d189ebd67de0e0c7a17029743 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Wed, 27 Nov 2024 12:32:30 +0100 Subject: [PATCH 09/10] chore: update schema --- i18n/en.pot | 27 ++++++++++++++++--- .../form/IndicatorTypesSchema.ts | 6 +++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index b0ac10ae..ffeebd66 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-25T10:03:10.019Z\n" -"PO-Revision-Date: 2024-11-25T10:03:10.019Z\n" +"POT-Creation-Date: 2024-11-27T08:30:38.416Z\n" +"PO-Revision-Date: 2024-11-27T08:30:38.417Z\n" msgid "schemas" msgstr "schemas" @@ -891,6 +891,9 @@ msgstr "This field requires a unique value, please choose another one" msgid "{{label}} (required)" msgstr "{{label}} (required)" +msgid "Should not exceed {{maxLength}} characters" +msgstr "Should not exceed {{maxLength}} characters" + msgid "No changes to be saved" msgstr "No changes to be saved" @@ -1241,8 +1244,8 @@ msgstr "" "Choose where this new organisation unit should be placed in the existing " "hierarchy" -msgid "Set up the basic information for this organisation unit." -msgstr "Set up the basic information for this organisation unit." +msgid "Set up the basic information for this organisation unit" +msgstr "Set up the basic information for this organisation unit" msgid "Opening date" msgstr "Opening date" @@ -1311,6 +1314,22 @@ msgstr "" "This is the first organisation unit and will be created as the root of the " "hierarchy." +msgid "Must be a valid mobile number" +msgstr "Must be a valid mobile number" + +msgid "Must be a valid url" +msgstr "Must be a valid url" + +msgid "" +"Longitude should be between -90 and 90. Latitude should be between -180 and " +"180" +msgstr "" +"Longitude should be between -90 and 90. Latitude should be between -180 and " +"180" + +msgid "Parent organisation unit cannot be itself or a descendant of itself." +msgstr "Parent organisation unit cannot be itself or a descendant of itself." + msgid "No organisation units available" msgstr "No organisation units available" diff --git a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts index 0c20681d..e530b214 100644 --- a/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts +++ b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts @@ -7,11 +7,13 @@ export const IndicatorSchema = identifiable.extend({ factor: z.coerce .number({ invalid_type_error: 'Please enter a number' }) .int() - .min(1, 'Please enter a value above 0') .max( Number.MAX_SAFE_INTEGER, `The number is too large. Please enter a valid integer.` - ), + ) + .refine((value) => value !== 0, { + message: 'Zero is not a valid value for factor', + }), }) export const initialValues = getDefaults(IndicatorSchema) From 94117104030dd87c1850c6cfdbf954cf1f83f447 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Thu, 28 Nov 2024 12:30:58 +0100 Subject: [PATCH 10/10] chore: resolve merge conflict from master --- src/components/form/fields/DateField.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/form/fields/DateField.tsx b/src/components/form/fields/DateField.tsx index 05a9079d..6555a137 100644 --- a/src/components/form/fields/DateField.tsx +++ b/src/components/form/fields/DateField.tsx @@ -1,6 +1,6 @@ import i18n from '@dhis2/d2-i18n' import { CalendarInput, CalendarInputProps } from '@dhis2/ui' -import React, { useEffect, useState } from 'react' +import React, { useState } from 'react' import { useField } from 'react-final-form' import { selectedLocale, useSystemSetting } from '../../../lib'