Skip to content

Commit

Permalink
fix(list): disable edit buttons when no access
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Nov 14, 2024
1 parent 88e5785 commit bcbb438
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/components/sectionList/listActions/DefaultListActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { BaseListModel, useSchemaFromHandle } from '../../../lib'
import { BaseListModel, TOOLTIPS, useSchemaFromHandle } from '../../../lib'
import { canEditModel, canDeleteModel } from '../../../lib/models/access'
import { TooltipWrapper } from '../../tooltip'
import { ListActions, ActionEdit, ActionMore } from './SectionListActions'

type DefaultListActionProps = {
Expand All @@ -26,7 +27,12 @@ export const DefaultListActions = ({

return (
<ListActions>
<ActionEdit modelId={model.id} />
<TooltipWrapper
condition={!editable}
content={TOOLTIPS.noEditAccess}
>
<ActionEdit disabled={!editable} modelId={model.id} />
</TooltipWrapper>
<ActionMore
deletable={deletable}
editable={editable}
Expand Down
10 changes: 9 additions & 1 deletion src/components/sectionList/listActions/SectionListActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ export const ListActions = ({ children }: React.PropsWithChildren) => {
)
}

export const ActionEdit = ({ modelId }: { modelId: string }) => {
export const ActionEdit = ({
modelId,
disabled,
}: {
modelId: string
disabled?: boolean
}) => {
const preservedSearchState = useLocationSearchState()
return (
<LinkButton
small
disabled={disabled}
secondary
to={{ pathname: modelId }}
state={preservedSearchState}
Expand Down Expand Up @@ -110,6 +117,7 @@ export const ActionMore = ({
>
<MenuItem
dense
disabled={!editable}
label={i18n.t('Edit')}
icon={<IconEdit16 />}
onClick={(_, e) => {
Expand Down

0 comments on commit bcbb438

Please sign in to comment.