Skip to content

Commit

Permalink
feat(list): add list for group and groupset (#379)
Browse files Browse the repository at this point in the history
* 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
Birkbjo authored May 14, 2024
1 parent a3aa050 commit 77f5695
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/components/sectionList/listView/ManageListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/sectionList/listView/useModelListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sectionList/listViews/sectionListViewsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,8 +93,8 @@ export const modelListViewsConfig = {
],
},
filters: {
available: [],
default: ['domainType', 'valueType', 'dataSet', 'categoryCombo'],
available: [DESCRIPTORS.publicAccess],
},
},
} satisfies SectionListViewConfig
54 changes: 54 additions & 0 deletions src/pages/DefaultSectionList.tsx
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>
)
}
3 changes: 3 additions & 0 deletions src/pages/dataElementGroupSets/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DefaultSectionList } from '../DefaultSectionList'

export const Component = DefaultSectionList
3 changes: 3 additions & 0 deletions src/pages/dataElementGroups/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DefaultSectionList } from '../DefaultSectionList'

export const Component = DefaultSectionList

0 comments on commit 77f5695

Please sign in to comment.