Skip to content

Commit

Permalink
Merge branch 'master' of github-chisom:dhis2/maintenance-app-beta int…
Browse files Browse the repository at this point in the history
…o DHIS2-18143/category-option-group-set
  • Loading branch information
Chisomchima committed Nov 5, 2024
2 parents af8daec + 3607f67 commit a6c808f
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [0.10.2](https://github.com/dhis2/maintenance-app-beta/compare/v0.10.1...v0.10.2) (2024-10-30)


### Bug Fixes

* **categoryOptionCombo:** add ignore approval field ([#423](https://github.com/dhis2/maintenance-app-beta/issues/423)) ([a5c7ac5](https://github.com/dhis2/maintenance-app-beta/commit/a5c7ac5613fa87afb4100aff26b0901c4262509c))
* **manageView:** stable initialValues for form ([#424](https://github.com/dhis2/maintenance-app-beta/issues/424)) ([2c5066a](https://github.com/dhis2/maintenance-app-beta/commit/2c5066aa28c2cea30117a24d6cca1d6f31dde358))

## [0.10.1](https://github.com/dhis2/maintenance-app-beta/compare/v0.10.0...v0.10.1) (2024-10-24)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maintenance-app",
"version": "0.10.1",
"version": "0.10.2",
"description": "",
"license": "BSD-3-Clause",
"private": true,
Expand Down
12 changes: 8 additions & 4 deletions src/components/sectionList/filters/DynamicFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import { ConfigurableFilterKey } from './../../../lib'
import {
AggregationTypeFilter,
CategoryComboFilter,
Categoryfilter,
CategoryOptionFilter,
CategoryOptionGroupFilter,
DataDimensionTypeFilter,
DataSetFilter,
DomainTypeSelectionFilter,
ValueTypeSelectionFilter,
IgnoreApprovalFilter,
PublicAccessFilter,
DataDimensionTypeFilter,
Categoryfilter,
CategoryOptionGroupFilter,
ValueTypeSelectionFilter,
} from './filterSelectors'
import { useFilterKeys } from './useFilterKeys'

type FilterKeyToComponentMap = Partial<Record<ConfigurableFilterKey, React.FC>>

const filterKeyToComponentMap: FilterKeyToComponentMap = {
category: Categoryfilter,
categoryOption: CategoryOptionFilter,
categoryCombo: CategoryComboFilter,
categoryOptionGroup: CategoryOptionGroupFilter,
dataSet: DataSetFilter,
Expand All @@ -25,6 +28,7 @@ const filterKeyToComponentMap: FilterKeyToComponentMap = {
aggregationType: AggregationTypeFilter,
publicAccess: PublicAccessFilter,
dataDimensionType: DataDimensionTypeFilter,
ignoreApproval: IgnoreApprovalFilter,
}

export const DynamicFilters = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import i18n from '@dhis2/d2-i18n'
import { CheckboxField } from '@dhis2/ui'
import React from 'react'
import {
BooleanFilterKey,
getTranslatedProperty,
useSectionListFilter,
} from '../../../../lib'

type BooleanFilterProps = {
label: string
filterKey: BooleanFilterKey
}

export const BooleanFilter = ({ filterKey, label }: BooleanFilterProps) => {
const [filter, setFilter] = useSectionListFilter(filterKey)

return (
<CheckboxField
checked={filter}
name={filterKey}
label={label}
onChange={(payload) => setFilter(payload.checked)}
/>
)
}

export const IgnoreApprovalFilter = () => {
return (
<BooleanFilter
filterKey="ignoreApproval"
label={getTranslatedProperty('ignoreApproval')}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import i18n from '@dhis2/d2-i18n'
import React from 'react'
import { useSectionListFilter } from '../../../../lib'
import { createFilterDataQuery } from './createFilterDataQuery'
import { ModelFilterSelect } from './ModelFilter'

const query = createFilterDataQuery('categoryOptions')

export const CategoryOptionFilter = () => {
const [filter, setFilter] = useSectionListFilter('categoryOption')

const selected = filter?.[0]

return (
<ModelFilterSelect
placeholder={i18n.t('Category option')}
query={query}
selected={selected}
onChange={({ selected }) =>
setFilter(selected ? [selected] : undefined)
}
/>
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import i18n from '@dhis2/d2-i18n'
import { SingleSelect, SingleSelectOption } from '@dhis2/ui'
import React from 'react'
import { FilterKey, useSectionListFilter } from '../../../../lib'
import { StringFilterKey, useSectionListFilter } from '../../../../lib'
import { SelectOnChangeObject } from '../../../../types'
import css from './Filters.module.css'

type ConstantSelectionFilterProps = {
label: string
constants: Record<string, string>
filterKey: FilterKey
filterKey: StringFilterKey
filterable?: boolean
formatFilter?: (filter: string | undefined) => string | undefined
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/sectionList/filters/filterSelectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export * from './ConstantSelectionFilter'
export * from './PublicAccessFilter'
export * from './CategoryFilter'
export * from './CategoryOptionGroupFilter'
export * from './BooleanFilters'
export * from './CategoryOptionFilter'
17 changes: 13 additions & 4 deletions src/components/sectionList/listView/ManageListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ export const ManageListView = ({
const section = useModelSectionHandleOrThrow()
const { saveView } = useMutateModelListViews()

const columnsConfig = getColumnsForSection(section.name)
const filtersConfig = getFiltersForSection(section.name)
const { defaultColumns, defaultFilters, columnsConfig, filtersConfig } =
useMemo(() => {
const columnsConfig = getColumnsForSection(section.name)
const filtersConfig = getFiltersForSection(section.name)

const defaultColumns = columnsConfig.default.map(toPath)
const defaultFilters = filtersConfig.default.map(toFilterKey)
const defaultColumns = columnsConfig.default.map(toPath)
const defaultFilters = filtersConfig.default.map(toFilterKey)
return {
defaultColumns,
defaultFilters,
columnsConfig,
filtersConfig,
}
}, [section.name])

const handleSave = async (values: FormValues) => {
const isDefault = (arr: string[], def: string[]) =>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/constants/translatedModelProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import i18n from '@dhis2/d2-i18n'
const TRANSLATED_PROPERTY: Record<string, string> = {
aggregationType: i18n.t('Aggregation type'),
categoryCombo: i18n.t('Category combination'),
categoryOption: i18n.t('Category option'),
code: i18n.t('Code'),
createdBy: i18n.t('Created by'),
description: i18n.t('Description'),
Expand All @@ -22,6 +23,7 @@ const TRANSLATED_PROPERTY: Record<string, string> = {
user: i18n.t('Owner'), // user refers to the owner of the object
zeroIsSignificant: i18n.t('Zero is significant'),
dataDimensionType: i18n.t('Data dimension type'),
ignoreApproval: i18n.t('Ignore data approval'),
}

const camelCaseToSentenceCase = (camelCase: string) =>
Expand Down
19 changes: 18 additions & 1 deletion src/lib/sectionList/filters/filterConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StringParam } from 'use-query-params'
import { BooleanParam, StringParam } from 'use-query-params'
import { z } from 'zod'
import { Category, DataElement } from '../../../types/generated'
import { KeysOfValue } from '../../../types/utility'
import { IDENTIFIABLE_FILTER_KEY } from '../../constants'
import { isValidUid, parseAccessString } from '../../models'
import { CustomDelimitedArrayParam } from './customParams'
Expand All @@ -14,6 +15,7 @@ export const filterParamsSchema = z
aggregationType: z.array(z.nativeEnum(DataElement.aggregationType)),
categoryCombo: zodArrayIds,
category: zodArrayIds,
categoryOption: zodArrayIds,
categoryOptionGroup: zodArrayIds,
dataSet: zodArrayIds,
domainType: z.array(z.nativeEnum(DataElement.domainType)),
Expand All @@ -22,6 +24,7 @@ export const filterParamsSchema = z
),
valueType: z.array(z.nativeEnum(DataElement.valueType)),
dataDimensionType: z.nativeEnum(Category.dataDimensionType),
ignoreApproval: z.boolean(),
})
.partial()

Expand All @@ -34,10 +37,12 @@ export const filterQueryParamType = {
valueType: CustomDelimitedArrayParam,
dataSet: CustomDelimitedArrayParam,
category: CustomDelimitedArrayParam,
categoryOption: CustomDelimitedArrayParam,
categoryCombo: CustomDelimitedArrayParam,
categoryOptionGroup: CustomDelimitedArrayParam,
publicAccess: CustomDelimitedArrayParam,
dataDimensionType: StringParam,
ignoreApproval: BooleanParam,
} as const satisfies QueryParamsConfigMap

export const validFilterKeys = Object.keys(filterQueryParamType)
Expand All @@ -47,6 +52,8 @@ export type ParsedFilterParams = z.infer<typeof filterParamsSchema>
type MapZodTypeToQueryParamConfig<TZodResultType> =
TZodResultType extends string
? typeof StringParam
: TZodResultType extends boolean
? typeof BooleanParam
: typeof CustomDelimitedArrayParam

/* Type is just used to verify that the ParamType-config matches the zod schema
Expand All @@ -64,4 +71,14 @@ export type ConfigurableFilterKey = Exclude<
typeof IDENTIFIABLE_FILTER_KEY
>

export type BooleanFilterKey = KeysOfValue<
ParsedFilterParams,
boolean | undefined
>

export type StringFilterKey = KeysOfValue<
ParsedFilterParams,
string[] | string | undefined
>

export type FilterKeys = FilterKey[]
1 change: 1 addition & 0 deletions src/lib/sectionList/filters/parseFiltersToQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultFilter = (
const filterToQueryParamMap: FilterToQueryParamsMap = {
identifiable: (value) => `identifiable:token:${value}`,
category: (value) => inFilter('categories.id', value),
categoryOption: (value) => inFilter('categoryOptions.id', value),
categoryCombo: (value, section) => {
if (section.name === 'category') {
return inFilter('categoryCombos.id', value)
Expand Down
15 changes: 15 additions & 0 deletions src/lib/sectionList/listViews/sectionListViewsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ export const modelListViewsConfig = {
},
filters: {
default: ['dataDimensionType', 'category'],
available: ['ignoreApproval'],
},
},
categoryOptionCombo: {
columns: {
default: ['name', 'code', 'lastUpdated'],
available: ['categoryCombo', 'ignoreApproval'],
// categoryOptionCombo does not have publicAccess
overrideDefaultAvailable: true,
},
filters: {
default: ['categoryOption', 'categoryCombo'],
available: ['ignoreApproval'],
// categoryOptionCombo does not have publicAccess
overrideDefaultAvailable: true,
},
},
} satisfies SectionListViewConfig<SectionName>
1 change: 1 addition & 0 deletions src/pages/categoryOptionCombos/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const fieldFilters = [
...ATTRIBUTE_VALUES_FIELD_FILTERS,
'name',
'code',
'ignoreApproval',
] as const

export type CategoryOptionComboFormValues = PickWithFieldFilters<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF } from '@dhis2/ui'
import { CheckboxFieldFF, InputFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field } from 'react-final-form'
import {
Expand Down Expand Up @@ -39,6 +39,15 @@ export const CategoryOptionComboFormFields = () => {
<StandardFormField>
<CodeField schemaSection={section} />
</StandardFormField>
<StandardFormField>
<Field
component={CheckboxFieldFF}
name="ignoreApproval"
label={i18n.t('Ignore data approval')}
validateFields={[]}
type="checkbox"
/>
</StandardFormField>
</StandardFormSection>
<CustomAttributesSection />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { withAttributeValues } = modelFormSchemas
export const categoryOptionComboSchema = withAttributeValues.extend({
id: z.string(),
code: z.string().trim().optional(),
ignoreApproval: z.boolean().optional().default(false),
})

export const initialValues = getDefaults(categoryOptionComboSchema)
Expand Down
4 changes: 4 additions & 0 deletions src/types/utility.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export type * from './generated/utility'

export type KeysOfValue<T, TCondition> = keyof {
[K in keyof T as T[K] extends TCondition ? K : never]: K
}

0 comments on commit a6c808f

Please sign in to comment.