-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
ba73ad8
commit 2668c68
Showing
9 changed files
with
214 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
src/pages/indicatorTypes/form/IndicatorTypesFormFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { IndicatorSchema, validate } from './IndicatorTypesSchema' |