-
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.
fix(list): add additional list filters to dataElementGroup/Set
- Loading branch information
Showing
12 changed files
with
166 additions
and
96 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
24 changes: 24 additions & 0 deletions
24
src/components/sectionList/filters/filterSelectors/DataElementFilter.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,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('dataElements') | ||
|
||
export const DataElementFilter = () => { | ||
const [filter, setFilter] = useSectionListFilter('dataElement') | ||
|
||
const selected = filter?.[0] | ||
|
||
return ( | ||
<ModelFilterSelect | ||
placeholder={i18n.t('Data element')} | ||
query={query} | ||
selected={selected} | ||
onChange={({ selected }) => | ||
setFilter(selected ? [selected] : undefined) | ||
} | ||
/> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
src/components/sectionList/filters/filterSelectors/DataElementGroup.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,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('dataElementGroups') | ||
|
||
export const DataElementGroupFilter = () => { | ||
const [filter, setFilter] = useSectionListFilter('dataElementGroup') | ||
|
||
const selected = filter?.[0] | ||
|
||
return ( | ||
<ModelFilterSelect | ||
placeholder={i18n.t('Data element group')} | ||
query={query} | ||
selected={selected} | ||
onChange={({ selected }) => | ||
setFilter(selected ? [selected] : undefined) | ||
} | ||
/> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
src/components/sectionList/filters/filterSelectors/DataElementGroupSet.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,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('dataElementGroupSets') | ||
|
||
export const DataElementGroupSetFilter = () => { | ||
const [filter, setFilter] = useSectionListFilter('dataElementGroupSet') | ||
|
||
const selected = filter?.[0] | ||
|
||
return ( | ||
<ModelFilterSelect | ||
placeholder={i18n.t('Data element group set')} | ||
query={query} | ||
selected={selected} | ||
onChange={({ selected }) => | ||
setFilter(selected ? [selected] : undefined) | ||
} | ||
/> | ||
) | ||
} |
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
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 |
---|---|---|
@@ -1,64 +1,3 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import { SharingDialog } from '@dhis2/ui' | ||
import React, { useEffect } from 'react' | ||
import { SectionListWrapper } from '../../components' | ||
import { useModelListView } from '../../components/sectionList/listView' | ||
import { | ||
useSchemaFromHandle, | ||
useParamsForDataQuery, | ||
DEFAULT_FIELD_FILTERS, | ||
DefaultFields, | ||
} from '../../lib/' | ||
import { getFieldFilter } from '../../lib/models/path' | ||
import { Query, WrapQueryResponse } from '../../types' | ||
import { DataElement, ModelCollectionResponse } from '../../types/models' | ||
import { DefaultSectionList } from '../DefaultSectionList' | ||
|
||
type FilteredDataElement = Pick<DataElement, DefaultFields> & | ||
Partial<DataElement> | ||
|
||
type DataElements = ModelCollectionResponse<FilteredDataElement, 'dataElements'> | ||
|
||
type DataElementsResponse = WrapQueryResponse<DataElements> | ||
|
||
const query: Query = { | ||
result: { | ||
resource: 'dataElements', | ||
params: (params) => params, | ||
}, | ||
} | ||
|
||
export const Component = () => { | ||
const { columns, query: listViewQuery } = useModelListView() | ||
const initialParams = useParamsForDataQuery() | ||
const schema = useSchemaFromHandle() | ||
const { refetch, error, data } = useDataQuery<DataElementsResponse>( | ||
query, | ||
// refetched on mount by effect below | ||
{ lazy: true } | ||
) | ||
|
||
useEffect(() => { | ||
// wait to fetch until selected-columns are loaded | ||
// so we dont fetch data multiple times | ||
if (listViewQuery.isLoading) { | ||
return | ||
} | ||
refetch({ | ||
...initialParams, | ||
fields: columns | ||
.map((column) => getFieldFilter(schema, column.path)) | ||
.concat(DEFAULT_FIELD_FILTERS), | ||
}) | ||
}, [refetch, initialParams, columns, listViewQuery.isLoading, schema]) | ||
|
||
return ( | ||
<div> | ||
<SectionListWrapper | ||
error={error} | ||
data={data?.result.dataElements} | ||
pager={data?.result.pager} | ||
refetch={refetch} | ||
/> | ||
</div> | ||
) | ||
} | ||
export const Component = DefaultSectionList |