Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Jan 29, 2024
1 parent a7e5d2f commit 5c06c37
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Input, InputEventPayload } from '@dhis2/ui'
import React, { useEffect, useState } from 'react'
import {
useDebounce,
IDENTIFIABLE_KEY,
IDENTIFIABLE_FILTER_KEY,
useSectionListFilter,
} from '../../../../lib'
import css from './Filters.module.css'

export const IdentifiableFilter = () => {
const [filter, setFilter] = useSectionListFilter(IDENTIFIABLE_KEY)
const [filter, setFilter] = useSectionListFilter(IDENTIFIABLE_FILTER_KEY)
const [value, setValue] = useState(filter || '')
const debouncedValue = useDebounce<typeof filter>(value, 200)

Expand Down
13 changes: 2 additions & 11 deletions src/components/sectionList/filters/useFilterKeys.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { useMemo } from 'react'
import {
useSectionListFilters,
ParsedFilterParams,
ConfigurableFilterKey,
IDENTIFIABLE_KEY,
IDENTIFIABLE_FILTER_KEY,
} from '../../../lib'
import { useModelListView } from '../listView'

export type FiltersWithValue = {
[FilterKey in ConfigurableFilterKey]: {
value: ParsedFilterParams[FilterKey]
label: string
filterKey: FilterKey
}
}

export const useFilterKeys = () => {
const [filters] = useSectionListFilters()
const { filters: viewFilters } = useModelListView()
Expand All @@ -26,7 +17,7 @@ export const useFilterKeys = () => {
.filter(
([filterKey, value]) =>
value !== undefined &&
filterKey !== IDENTIFIABLE_KEY &&
filterKey !== IDENTIFIABLE_FILTER_KEY &&
!viewFilterKeys.includes(filterKey as ConfigurableFilterKey)
)
.map(([filterKey]) => filterKey) as ConfigurableFilterKey[]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './sections'
export * from './translatedModelConstants'
export * from './translatedModelProperties'

export const IDENTIFIABLE_KEY = 'identifiable'
export const IDENTIFIABLE_FILTER_KEY = 'identifiable'
174 changes: 0 additions & 174 deletions src/lib/constants/sectionListViewsConfig.ts

This file was deleted.

11 changes: 7 additions & 4 deletions src/lib/sectionList/filters/filterConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StringParam } from 'use-query-params'
import { z } from 'zod'
import { DataElement } from '../../../types/generated'
import { IDENTIFIABLE_KEY } from '../../constants'
import { IDENTIFIABLE_FILTER_KEY } from '../../constants'
import { isValidUid, parsePublicAccessString } from '../../models'
import { CustomDelimitedArrayParam } from './customParams'

Expand All @@ -10,7 +10,7 @@ const zodArrayIds = z.array(z.string().refine((val) => isValidUid(val)))
/* Zod schema for validation of the decoded params */
export const filterParamsSchema = z
.object({
[IDENTIFIABLE_KEY]: z.string(),
[IDENTIFIABLE_FILTER_KEY]: z.string(),
aggregationType: z.array(z.nativeEnum(DataElement.aggregationType)),
categoryCombo: zodArrayIds,
dataSet: zodArrayIds,
Expand All @@ -25,7 +25,7 @@ export const filterParamsSchema = z
/* useQueryParams config-map object
Mapping each filter to a config object that handles encoding/decoding */
export const filterQueryParamType = {
[IDENTIFIABLE_KEY]: StringParam,
[IDENTIFIABLE_FILTER_KEY]: StringParam,
aggregationType: CustomDelimitedArrayParam,
domainType: CustomDelimitedArrayParam,
valueType: CustomDelimitedArrayParam,
Expand Down Expand Up @@ -53,5 +53,8 @@ type QueryParamsConfigMap = {

export type FilterKey = keyof ParsedFilterParams
// Identifiable is not configurable, and is always shown in the list
export type ConfigurableFilterKey = Exclude<FilterKey, typeof IDENTIFIABLE_KEY>
export type ConfigurableFilterKey = Exclude<
FilterKey,
typeof IDENTIFIABLE_FILTER_KEY
>
export type FilterKeys = FilterKey[]

0 comments on commit 5c06c37

Please sign in to comment.