From 77f569550a85ca221a59a839a90d3bd9c2f77df2 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Tue, 14 May 2024 10:48:23 +0200 Subject: [PATCH] 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 --- .../sectionList/listView/ManageListView.tsx | 3 -- .../sectionList/listView/useModelListView.tsx | 2 +- .../listViews/sectionListViewsConfig.ts | 4 +- src/pages/DefaultSectionList.tsx | 54 +++++++++++++++++++ src/pages/dataElementGroupSets/List.tsx | 3 ++ src/pages/dataElementGroups/List.tsx | 3 ++ 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/pages/DefaultSectionList.tsx create mode 100644 src/pages/dataElementGroupSets/List.tsx create mode 100644 src/pages/dataElementGroups/List.tsx diff --git a/src/components/sectionList/listView/ManageListView.tsx b/src/components/sectionList/listView/ManageListView.tsx index 7267f2fc..e78269c7 100644 --- a/src/components/sectionList/listView/ManageListView.tsx +++ b/src/components/sectionList/listView/ManageListView.tsx @@ -44,9 +44,6 @@ const validate = (values: FormValues) => { if (values.columns.length < 1) { errors.columns = i18n.t('At least one column must be selected') } - if (values.filters.length < 1) { - errors.filters = i18n.t('At least one filter must be selected') - } return errors } export const ManageListView = ({ diff --git a/src/components/sectionList/listView/useModelListView.tsx b/src/components/sectionList/listView/useModelListView.tsx index 6f89f414..189901b4 100644 --- a/src/components/sectionList/listView/useModelListView.tsx +++ b/src/components/sectionList/listView/useModelListView.tsx @@ -114,7 +114,7 @@ const createValidViewSelect = (sectionName: string) => { return getDefaultViewForSection(sectionName) } - const viewForSection = modelListViews.data[sectionName][0] + const viewForSection = modelListViews.data[sectionName]?.[0] if (!viewForSection) { return getDefaultViewForSection(sectionName) } diff --git a/src/lib/sectionList/listViews/sectionListViewsConfig.ts b/src/lib/sectionList/listViews/sectionListViewsConfig.ts index 0a72a568..c83141c5 100644 --- a/src/lib/sectionList/listViews/sectionListViewsConfig.ts +++ b/src/lib/sectionList/listViews/sectionListViewsConfig.ts @@ -64,7 +64,7 @@ export const defaultModelViewConfig = { default: ['name', DESCRIPTORS.publicAccess, 'lastUpdated'], }, filters: { - available: [], + available: [DESCRIPTORS.publicAccess], default: [ // NOTE: Identifiable is special, and is always included in the default filters // It should not be handled the same way as "configurable" filters @@ -93,8 +93,8 @@ export const modelListViewsConfig = { ], }, filters: { + available: [], default: ['domainType', 'valueType', 'dataSet', 'categoryCombo'], - available: [DESCRIPTORS.publicAccess], }, }, } satisfies SectionListViewConfig diff --git a/src/pages/DefaultSectionList.tsx b/src/pages/DefaultSectionList.tsx new file mode 100644 index 00000000..fcfdfa62 --- /dev/null +++ b/src/pages/DefaultSectionList.tsx @@ -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> + +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 + }, + }) + const modelList = data?.result[modelListName] + + return ( +
+ +
+ ) +} diff --git a/src/pages/dataElementGroupSets/List.tsx b/src/pages/dataElementGroupSets/List.tsx new file mode 100644 index 00000000..e03292f8 --- /dev/null +++ b/src/pages/dataElementGroupSets/List.tsx @@ -0,0 +1,3 @@ +import { DefaultSectionList } from '../DefaultSectionList' + +export const Component = DefaultSectionList diff --git a/src/pages/dataElementGroups/List.tsx b/src/pages/dataElementGroups/List.tsx new file mode 100644 index 00000000..e03292f8 --- /dev/null +++ b/src/pages/dataElementGroups/List.tsx @@ -0,0 +1,3 @@ +import { DefaultSectionList } from '../DefaultSectionList' + +export const Component = DefaultSectionList