-
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(list): add list for group and groupset (#379)
* feat(list): add generic list component, use for de group/set * refactor: rename to GenericSectionList * refactor(list): use component files instead of array of enabled routes * fix(list): revert dataelement list refactor due to failing tests * refactor: minor cleanup
- Loading branch information
Showing
6 changed files
with
63 additions
and
6 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,54 @@ | ||
import { FetchError, useDataEngine } from '@dhis2/app-runtime' | ||
import React from 'react' | ||
import { useQuery } from 'react-query' | ||
import { SectionListWrapper } from '../components' | ||
import { useModelListView } from '../components/sectionList/listView' | ||
import { | ||
useSchemaFromHandle, | ||
useParamsForDataQuery, | ||
BaseListModel, | ||
DEFAULT_FIELD_FILTERS, | ||
} from '../lib' | ||
import { getFieldFilter } from '../lib/models/path' | ||
import { WrapQueryResponse } from '../types' | ||
import { PagedResponse } from '../types/models' | ||
|
||
type ModelListResponse = WrapQueryResponse<PagedResponse<BaseListModel, string>> | ||
|
||
export const DefaultSectionList = () => { | ||
const { columns } = useModelListView() | ||
const schema = useSchemaFromHandle() | ||
const engine = useDataEngine() | ||
const modelListName = schema.plural | ||
|
||
const initialParams = useParamsForDataQuery() | ||
|
||
const query = { | ||
result: { | ||
resource: modelListName, | ||
params: { | ||
...initialParams, | ||
fields: columns | ||
.map((column) => getFieldFilter(schema, column.path)) | ||
.concat(DEFAULT_FIELD_FILTERS), | ||
}, | ||
}, | ||
} | ||
const { error, data } = useQuery({ | ||
queryKey: [query], | ||
queryFn: ({ queryKey: [query], signal }) => { | ||
return engine.query(query, { signal }) as Promise<ModelListResponse> | ||
}, | ||
}) | ||
const modelList = data?.result[modelListName] | ||
|
||
return ( | ||
<div> | ||
<SectionListWrapper | ||
error={error as FetchError | undefined} | ||
data={modelList} | ||
pager={data?.result.pager} | ||
/> | ||
</div> | ||
) | ||
} |
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,3 @@ | ||
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,3 @@ | ||
import { DefaultSectionList } from '../DefaultSectionList' | ||
|
||
export const Component = DefaultSectionList |