From eaa3ee92dc00f451437ae5ae21261fa29d274709 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Tue, 5 Mar 2024 23:06:48 +0100 Subject: [PATCH] fix: disable checkbox with no access --- src/components/sectionList/SectionListRow.tsx | 31 ++++++++++++------- .../sectionList/SectionListWrapper.tsx | 25 +++++---------- .../listActions/SectionListActions.tsx | 2 +- .../sectionList/listActions/index.ts | 2 ++ src/lib/sectionList/fieldFilters.ts | 6 ++++ src/lib/sectionList/index.ts | 1 + src/pages/dataElements/List.tsx | 12 +++++-- 7 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 src/components/sectionList/listActions/index.ts create mode 100644 src/lib/sectionList/fieldFilters.ts diff --git a/src/components/sectionList/SectionListRow.tsx b/src/components/sectionList/SectionListRow.tsx index 23e2edd8..8bbf35d4 100644 --- a/src/components/sectionList/SectionListRow.tsx +++ b/src/components/sectionList/SectionListRow.tsx @@ -1,23 +1,24 @@ import { DataTableRow, DataTableCell, Checkbox } from '@dhis2/ui' import cx from 'classnames' import React from 'react' +import { BaseListModel } from '../../lib' import { CheckBoxOnChangeObject } from '../../types' -import { IdentifiableObject, GistModel } from '../../types/models' +import { WrapWithTooltip } from '../tooltip' import css from './SectionList.module.css' import { SelectedColumns, SelectedColumn } from './types' -export type SectionListRowProps = { - modelData: GistModel | Model +export type SectionListRowProps = { + modelData: Model selectedColumns: SelectedColumns onSelect: (modelId: string, checked: boolean) => void selected: boolean renderActions: (modelId: string) => React.ReactNode renderColumnValue: (column: SelectedColumn) => React.ReactNode - onClick?: (modelData: GistModel | Model) => void + onClick?: (modelData: Model) => void active?: boolean } -export function SectionListRow({ +export function SectionListRow({ active, selectedColumns, modelData, @@ -34,13 +35,19 @@ export function SectionListRow({ selected={selected} > - { - onSelect(modelData.id, checked) - }} - /> + + { + onSelect(modelData.id, checked) + }} + /> + {selectedColumns.map((selectedColumn) => ( | undefined pager: Pager | undefined error: FetchError | undefined } @@ -114,16 +110,11 @@ export const SectionListWrapper = ({ /> ) }} - renderActions={(id) => ( - - - - handleShowDetails(id) - } - /> - + renderActions={() => ( + )} /> ))} diff --git a/src/components/sectionList/listActions/SectionListActions.tsx b/src/components/sectionList/listActions/SectionListActions.tsx index 8c71ec99..065aafdb 100644 --- a/src/components/sectionList/listActions/SectionListActions.tsx +++ b/src/components/sectionList/listActions/SectionListActions.tsx @@ -10,7 +10,7 @@ import { Popover, } from '@dhis2/ui' import React, { useRef, useState } from 'react' -import { Link, useHref, useLinkClickHandler } from 'react-router-dom' +import { useHref, useLinkClickHandler } from 'react-router-dom' import { LinkButton } from '../../LinkButton' import css from './SectionListActions.module.css' diff --git a/src/components/sectionList/listActions/index.ts b/src/components/sectionList/listActions/index.ts new file mode 100644 index 00000000..1124b59f --- /dev/null +++ b/src/components/sectionList/listActions/index.ts @@ -0,0 +1,2 @@ +export { DefaultListActions } from './DefaultListActions' +export * from './SectionListActions' diff --git a/src/lib/sectionList/fieldFilters.ts b/src/lib/sectionList/fieldFilters.ts new file mode 100644 index 00000000..5e996b00 --- /dev/null +++ b/src/lib/sectionList/fieldFilters.ts @@ -0,0 +1,6 @@ +import { BaseIdentifiableObject } from '../../types/generated' + +export const DEFAULT_FIELD_FILTERS = ['id', 'access'] as const +export type DefaultFields = (typeof DEFAULT_FIELD_FILTERS)[number] + +export type BaseListModel = Pick diff --git a/src/lib/sectionList/index.ts b/src/lib/sectionList/index.ts index 180856e0..25b75bba 100644 --- a/src/lib/sectionList/index.ts +++ b/src/lib/sectionList/index.ts @@ -6,3 +6,4 @@ export { } from './usePaginationParams' export * from './useParamsForDataQuery' export * from './listViews' +export * from './fieldFilters' diff --git a/src/pages/dataElements/List.tsx b/src/pages/dataElements/List.tsx index 2226a255..a09100d8 100644 --- a/src/pages/dataElements/List.tsx +++ b/src/pages/dataElements/List.tsx @@ -2,12 +2,18 @@ import { useDataQuery } from '@dhis2/app-runtime' import React, { useEffect } from 'react' import { SectionListWrapper } from '../../components' import { useModelListView } from '../../components/sectionList/listView' -import { useSchemaFromHandle, useParamsForDataQuery } from '../../lib/' +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' -type FilteredDataElement = Pick & Partial +type FilteredDataElement = Pick & + Partial type DataElements = ModelCollectionResponse @@ -40,7 +46,7 @@ export const Component = () => { ...initialParams, fields: columns .map((column) => getFieldFilter(schema, column.path)) - .concat('id'), + .concat(DEFAULT_FIELD_FILTERS), }) }, [refetch, initialParams, columns, listViewQuery.isLoading, schema])