From 1df066f6fc061e2d07744c77b187a285f4c472f1 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Thu, 14 Nov 2024 14:55:31 +0100 Subject: [PATCH] fix(detailspanel): disable edit when no access --- .../detailsPanel/DefaultDetailsPanel.tsx | 6 ++++-- .../sectionList/detailsPanel/DetailsPanel.tsx | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/sectionList/detailsPanel/DefaultDetailsPanel.tsx b/src/components/sectionList/detailsPanel/DefaultDetailsPanel.tsx index ac055159..3da4abfb 100644 --- a/src/components/sectionList/detailsPanel/DefaultDetailsPanel.tsx +++ b/src/components/sectionList/detailsPanel/DefaultDetailsPanel.tsx @@ -1,7 +1,7 @@ import { useDataQuery } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import React, { useRef } from 'react' -import { Schema, useSchemaFromHandle } from '../../../lib' +import { canEditModel, Schema, useSchemaFromHandle } from '../../../lib' import { Query, WrapQueryResponse } from '../../../types' import { BaseIdentifiableObject } from '../../../types/models' import { ClientDateTime } from '../../date' @@ -18,6 +18,7 @@ type DetailsPanelProps = { } const defaultQueryFields = [ + 'access', 'code', 'created', 'lastUpdated', @@ -78,9 +79,10 @@ export const DefaultDetailsPanelContent = ({ modelId }: DetailsPanelProps) => { } const DetailsContent = ({ data }: { data: DetailsResponse }) => { + const canEdit = canEditModel(data) return ( - + {data.shortName && ( diff --git a/src/components/sectionList/detailsPanel/DetailsPanel.tsx b/src/components/sectionList/detailsPanel/DetailsPanel.tsx index e5937a11..545d4b04 100644 --- a/src/components/sectionList/detailsPanel/DetailsPanel.tsx +++ b/src/components/sectionList/detailsPanel/DetailsPanel.tsx @@ -3,6 +3,9 @@ import { Card, IconCross24, Button, ButtonStrip, NoticeBox } from '@dhis2/ui' import React, { PropsWithChildren } from 'react' import { ErrorBoundary } from 'react-error-boundary' import { Link } from 'react-router-dom' +import { TOOLTIPS } from '../../../lib' +import { LinkButton } from '../../LinkButton' +import { TooltipWrapper } from '../../tooltip' import css from './DetailsPanel.module.css' type DetailsPanelProps = { @@ -42,13 +45,19 @@ export const DetailsPanelContent = ({ ) } -export const DetailsPanelButtons = ({ modelId }: { modelId: string }) => ( +export const DetailsPanelButtons = ({ + modelId, + editable, +}: { + modelId: string + editable?: boolean +}) => ( - - - + + )