diff --git a/src/components/sectionList/SectionListWrapper.tsx b/src/components/sectionList/SectionListWrapper.tsx index c0dfe3ae..c4e91a58 100644 --- a/src/components/sectionList/SectionListWrapper.tsx +++ b/src/components/sectionList/SectionListWrapper.tsx @@ -95,12 +95,7 @@ export const SectionListWrapper = ({ c.path === path - )?.component - } - model={model} + sectionModel={model} /> ) }} diff --git a/src/components/sectionList/listView/types.ts b/src/components/sectionList/listView/types.ts index 124b2d81..49b4a1e4 100644 --- a/src/components/sectionList/listView/types.ts +++ b/src/components/sectionList/listView/types.ts @@ -4,8 +4,8 @@ import type { ModelPropertyDescriptor } from '../../../lib' export interface ModelListView { name: string sectionModel: string - columns: Array - filters: Array + columns: ReadonlyArray + filters: ReadonlyArray } export type ModelListViews = { diff --git a/src/components/sectionList/listView/useModelListView.tsx b/src/components/sectionList/listView/useModelListView.tsx index ae72c4ac..f942fdd7 100644 --- a/src/components/sectionList/listView/useModelListView.tsx +++ b/src/components/sectionList/listView/useModelListView.tsx @@ -132,7 +132,8 @@ export const useModelListView = () => { select, }) - if (query.error) { + // 404 errors are expected when user havent saved any views + if (query.error && (query.error as any).details?.httpStatusCode !== 404) { console.error(query.error) } diff --git a/src/components/sectionList/modelValue/ModelValue.tsx b/src/components/sectionList/modelValue/ModelValue.tsx index f5748d88..89444906 100644 --- a/src/components/sectionList/modelValue/ModelValue.tsx +++ b/src/components/sectionList/modelValue/ModelValue.tsx @@ -11,12 +11,7 @@ import { ModelValueRenderer } from './ModelValueRenderer' type ModelValueProps = { schema: Schema path: string - model: unknown - // override renderer - component?: React.ComponentType<{ - value: unknown - schemaProperty: SchemaFieldProperty - }> + sectionModel: unknown } const ModelValueError = () => { @@ -39,27 +34,23 @@ const getSchemaProperty = ( return schemaProperty } -export const ModelValue = ({ - component, - schema, - path, - model, -}: ModelValueProps) => { +export const ModelValue = ({ schema, path, sectionModel }: ModelValueProps) => { const schemaProperty = getSchemaProperty(schema, path) - const value = getIn(model, path) + const value = getIn(sectionModel, path) if (!schemaProperty || value == undefined) { - console.warn( - `Property ${path} not found in schema, value not rendered: ${value}` - ) + console.warn(`Property ${path} not found, value not rendered: ${value}`) return null } - const Component = component || ModelValueRenderer return ( - + ) } diff --git a/src/components/sectionList/modelValue/ModelValueRenderer.tsx b/src/components/sectionList/modelValue/ModelValueRenderer.tsx index a691cc4a..4339077a 100644 --- a/src/components/sectionList/modelValue/ModelValueRenderer.tsx +++ b/src/components/sectionList/modelValue/ModelValueRenderer.tsx @@ -3,14 +3,24 @@ import { SchemaFieldProperty } from '../../../lib' import { BooleanValue } from './BooleanValue' import { ConstantValue } from './ConstantValue' import { DateValue } from './DateValue' +import { PublicAccessValue } from './PublicAccess' import { TextValue } from './TextValue' export type ValueDetails = { schemaProperty: SchemaFieldProperty value: unknown + path: string } -export const ModelValueRenderer = ({ value, schemaProperty }: ValueDetails) => { +export const ModelValueRenderer = ({ + path, + value, + schemaProperty, +}: ValueDetails) => { + if (path === 'sharing.public' && typeof value === 'string') { + return + } + if (schemaProperty.propertyType === 'CONSTANT') { return } diff --git a/src/components/sectionList/types.ts b/src/components/sectionList/types.ts index 8f4e5100..e776e422 100644 --- a/src/components/sectionList/types.ts +++ b/src/components/sectionList/types.ts @@ -5,7 +5,7 @@ export type SelectedColumn = { path: string } -export type SelectedColumns = SelectedColumn[] +export type SelectedColumns = ReadonlyArray export type CheckBoxOnChangeObject = { checked: boolean diff --git a/src/lib/constants/index.ts b/src/lib/constants/index.ts index b547d8fa..369de77f 100644 --- a/src/lib/constants/index.ts +++ b/src/lib/constants/index.ts @@ -1,4 +1,4 @@ -export * from './sectionListViews' +export * from './sectionListViewsConfig' export * from './sections' export * from './translatedModelConstants' export * from './translatedModelProperties' diff --git a/src/lib/constants/sectionListViews.ts b/src/lib/constants/sectionListViewsConfig.ts similarity index 92% rename from src/lib/constants/sectionListViews.ts rename to src/lib/constants/sectionListViewsConfig.ts index 2bccc457..f20ad6e0 100644 --- a/src/lib/constants/sectionListViews.ts +++ b/src/lib/constants/sectionListViewsConfig.ts @@ -1,5 +1,4 @@ import i18n from '@dhis2/d2-i18n' -// import { PublicAccessValue } from '../../components/sectionList/modelValue/PublicAccess' import { uniqueBy } from '../utils' import type { SectionName } from './sections' import { getTranslatedProperty } from './translatedModelProperties' @@ -7,15 +6,13 @@ import { getTranslatedProperty } from './translatedModelProperties' export interface ModelPropertyDescriptor { label: string path: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - component?: React.FC<{ value: any }> } type ModelPropertyConfig = string | ModelPropertyDescriptor interface ViewConfigPart { - available?: ModelPropertyConfig[] + available?: ReadonlyArray overrideDefaultAvailable?: boolean - default?: ModelPropertyConfig[] + default?: ReadonlyArray } interface ViewConfig { @@ -24,8 +21,8 @@ interface ViewConfig { } interface ResolvedViewConfigPart { - available: ModelPropertyDescriptor[] - default: ModelPropertyDescriptor[] + available: ReadonlyArray + default: ReadonlyArray } interface ResolvedViewConfig { columns: ResolvedViewConfigPart @@ -52,7 +49,6 @@ const defaultModelViewConfig = { { label: i18n.t('Public access'), path: 'sharing.public', - // component: PublicAccessValue, }, ], default: ['name', 'sharing.public', 'lastUpdated'],