From 2668c683fcda0807f34cb3c2a92f405d5ff66578 Mon Sep 17 00:00:00 2001 From: Chisom Chima <87203527+Chisomchima@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:30:11 +0100 Subject: [PATCH] feat: add indicator list type list view (#433) * 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 --- i18n/en.pot | 61 +++++++++++++++---- src/components/form/FormBase.tsx | 1 + .../listViews/sectionListViewsConfig.ts | 27 +++++++- src/pages/indicatorTypes/Edit.tsx | 48 +++++++++++++++ src/pages/indicatorTypes/List.tsx | 4 ++ src/pages/indicatorTypes/New.tsx | 24 ++++++++ .../form/IndicatorTypesFormFields.tsx | 50 +++++++++++++++ .../form/IndicatorTypesSchema.ts | 12 ++++ src/pages/indicatorTypes/form/index.ts | 1 + 9 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 src/pages/indicatorTypes/Edit.tsx create mode 100644 src/pages/indicatorTypes/List.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/i18n/en.pot b/i18n/en.pot index c0866fd0..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" @@ -909,6 +909,9 @@ msgstr "Required" msgid "Period type" msgstr "Period type" +msgid "Factor" +msgstr "Factor" + msgid "Basic information" msgstr "Basic information" @@ -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" @@ -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." @@ -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" diff --git a/src/components/form/FormBase.tsx b/src/components/form/FormBase.tsx index f5f2ae00..6a55775f 100644 --- a/src/components/form/FormBase.tsx +++ b/src/components/form/FormBase.tsx @@ -11,6 +11,7 @@ import { useCustomAttributesQuery } from './attributes' type MaybeModelWithAttributes = { id?: string + name?: string attributeValues?: PartialAttributeValue[] | undefined } diff --git a/src/lib/sectionList/listViews/sectionListViewsConfig.ts b/src/lib/sectionList/listViews/sectionListViewsConfig.ts index 277a70b1..7265f060 100644 --- a/src/lib/sectionList/listViews/sectionListViewsConfig.ts +++ b/src/lib/sectionList/listViews/sectionListViewsConfig.ts @@ -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: [ diff --git a/src/pages/indicatorTypes/Edit.tsx b/src/pages/indicatorTypes/Edit.tsx new file mode 100644 index 00000000..4b395c31 --- /dev/null +++ b/src/pages/indicatorTypes/Edit.tsx @@ -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, + }) + return ( + + + + + + ) +} 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 = () => diff --git a/src/pages/indicatorTypes/New.tsx b/src/pages/indicatorTypes/New.tsx new file mode 100644 index 00000000..91130e55 --- /dev/null +++ b/src/pages/indicatorTypes/New.tsx @@ -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 ( + + + + + + ) +} diff --git a/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx b/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx new file mode 100644 index 00000000..f1ade7d2 --- /dev/null +++ b/src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx @@ -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 ( + <> + + + {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..d9b6d1a1 --- /dev/null +++ b/src/pages/indicatorTypes/form/IndicatorTypesSchema.ts @@ -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) 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'