Skip to content

Commit

Permalink
fix(detailspanel): disable edit when no access
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Nov 14, 2024
1 parent 48571f1 commit 518ab82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -18,6 +18,7 @@ type DetailsPanelProps = {
}

const defaultQueryFields = [
'access',
'code',
'created',
'lastUpdated',
Expand Down Expand Up @@ -78,9 +79,10 @@ export const DefaultDetailsPanelContent = ({ modelId }: DetailsPanelProps) => {
}

const DetailsContent = ({ data }: { data: DetailsResponse }) => {
const canEdit = canEditModel(data)
return (
<DetailsPanelContent displayName={data.displayName}>
<DetailsPanelButtons modelId={data.id} />
<DetailsPanelButtons modelId={data.id} canEdit={canEdit} />
<DetailsList>
{data.shortName && (
<DetailItem label={i18n.t('Short name')}>
Expand Down
19 changes: 14 additions & 5 deletions src/components/sectionList/detailsPanel/DetailsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import React, { PropsWithChildren } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { Link } from 'react-router-dom'
import css from './DetailsPanel.module.css'

Check failure on line 6 in src/components/sectionList/detailsPanel/DetailsPanel.tsx

View workflow job for this annotation

GitHub Actions / lint

`./DetailsPanel.module.css` import should occur after import of `../../LinkButton`
import { TooltipWrapper } from '../../tooltip'

Check failure on line 7 in src/components/sectionList/detailsPanel/DetailsPanel.tsx

View workflow job for this annotation

GitHub Actions / lint

`../../tooltip` import should occur after import of `../../LinkButton`
import { TOOLTIPS } from '../../../lib'
import { LinkButton } from '../../LinkButton'

type DetailsPanelProps = {
children: React.ReactNode
Expand Down Expand Up @@ -42,13 +45,19 @@ export const DetailsPanelContent = ({
)
}

export const DetailsPanelButtons = ({ modelId }: { modelId: string }) => (
export const DetailsPanelButtons = ({
modelId,
canEdit,
}: {
modelId: string
canEdit?: boolean
}) => (
<ButtonStrip>
<Link to={modelId}>
<Button secondary small>
<TooltipWrapper condition={!canEdit} content={TOOLTIPS.noEditAccess}>
<LinkButton small secondary to={modelId} disabled={!canEdit}>
{i18n.t('Edit')}
</Button>
</Link>
</LinkButton>
</TooltipWrapper>
</ButtonStrip>
)

Expand Down

0 comments on commit 518ab82

Please sign in to comment.