Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list): add list for group and groupset #379

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading