Skip to content

Commit

Permalink
chore: update factor schema type
Browse files Browse the repository at this point in the history
  • Loading branch information
Chisomchima committed Nov 12, 2024
1 parent 1f63709 commit 91d58e3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/components/form/FormBase.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { NoticeBox } from '@dhis2/ui'
import React, { useMemo } from 'react'
import { FormProps, Form as ReactFinalForm } from 'react-final-form'
import {
Expand All @@ -11,7 +10,6 @@ import { useCustomAttributesQuery } from './attributes'
type MaybeModelWithAttributes = {
id?: string
name?: string
factor?: string
attributeValues?: PartialAttributeValue[] | undefined
}

Expand Down Expand Up @@ -46,10 +44,6 @@ export function FormBase<TInitialValues extends MaybeModelWithAttributes>({
}
}, [customAttributes.data, initialValues, includeAttributes])

// if (customAttributes.error) {
// return <NoticeBox error title="Failed to load custom attributes" />
// }

if (!initialValuesWithAttributes || customAttributes.loading) {
return <LoadingSpinner />
}
Expand Down
20 changes: 19 additions & 1 deletion src/lib/sectionList/listViews/sectionListViewsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions src/pages/indicatorTypes/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export const Component = () => {
fields: fieldFilters.concat(),
},
}
const IndicatorTypeQuery = useQuery({
const indicatorTypeQuery = useQuery({
queryKey: [query],
queryFn: queryFn<IndicatorTypesFormValues>,
})
return (
<FormBase
onSubmit={useOnSubmitEdit({ section, modelId })}
section={section}
initialValues={IndicatorTypeQuery.data as IndicatorTypesFormValues}
initialValues={indicatorTypeQuery.data}
validate={validate}
>
<DefaultNewFormContents section={section}>
Expand Down
5 changes: 1 addition & 4 deletions src/pages/indicatorTypes/form/IndicatorTypesSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/types/generated/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4776,7 +4776,7 @@ export type IndicatorType = {
created: string
createdBy: User
displayName: string
factor: string
factor: number
favorite: boolean
favorites: Array<string>
href: string
Expand Down

0 comments on commit 91d58e3

Please sign in to comment.