11import ObjectItemEditComponent from "@/entities/nodes/object-item-edit/object-item-edit-paginated" ;
22import { DissociateRelationshipsModal } from "@/entities/nodes/relationships/ui/dissociate-relationships-modal" ;
33import { RelationshipProperties } from "@/entities/nodes/relationships/ui/relationship-properties" ;
4+ import { canDissociateRelationship } from "@/entities/nodes/relationships/utils/can-dissociate-relationship" ;
45import { Permission } from "@/entities/permission/types" ;
56import { useSchema } from "@/entities/schema/ui/hooks/useSchema" ;
67import { queryClient } from "@/shared/api/rest/client" ;
@@ -27,6 +28,7 @@ export interface ActionsCellProps {
2728 relationshipKind : string ;
2829 relationshipLabel : string ;
2930 relationshipName : string ;
31+ relationshipsCount : number ;
3032}
3133
3234export function RelationshipActionsCell ( {
@@ -37,14 +39,24 @@ export function RelationshipActionsCell({
3739 relationshipLabel,
3840 relationshipKind,
3941 relationshipName,
42+ relationshipsCount,
4043} : ActionsCellProps ) {
4144 const [ showPropertiesModal , setShowPropertiesModal ] = useState ( false ) ;
4245 const [ showEditForm , setShowEditForm ] = useState ( false ) ;
4346 const [ showDissociateModal , setShowDissociateModal ] = useState ( false ) ;
44- const { schema } = useSchema ( relationshipKind ) ;
45- const isEditAllowed = permission . update . isAllowed ;
4647
47- if ( ! schema ) return < ErrorScreen message = { `Schema not found for ${ relationshipKind } ` } /> ;
48+ const { schema : parentSchema } = useSchema ( parentKind ) ;
49+
50+ if ( ! parentSchema ) {
51+ return < ErrorScreen message = { `Schema not found for ${ relationshipKind } ` } /> ;
52+ }
53+
54+ const isEditAllowed = permission . update . isAllowed ;
55+ const isDissociateAllowed = canDissociateRelationship ( {
56+ parentSchema,
57+ relationshipName,
58+ relationshipsCount,
59+ } ) ;
4860
4961 return (
5062 < Popover open = { showPropertiesModal } onOpenChange = { setShowPropertiesModal } >
@@ -82,17 +94,19 @@ export function RelationshipActionsCell({
8294 </ div >
8395 </ Tooltip >
8496
85- < Tooltip enabled = { ! isEditAllowed } content = { permission . update . message } side = "left" >
86- < div >
87- < DropdownMenuItem
88- disabled = { ! isEditAllowed }
89- onClick = { ( ) => isEditAllowed && setShowDissociateModal ( true ) }
90- >
91- < Icon icon = "mdi:link-variant-remove" className = "text-base" />
92- Dissociate
93- </ DropdownMenuItem >
94- </ div >
95- </ Tooltip >
97+ { isDissociateAllowed && (
98+ < Tooltip enabled = { ! isEditAllowed } content = { permission . update . message } side = "left" >
99+ < div >
100+ < DropdownMenuItem
101+ disabled = { ! isEditAllowed }
102+ onClick = { ( ) => isEditAllowed && setShowDissociateModal ( true ) }
103+ >
104+ < Icon icon = "mdi:link-variant-remove" className = "text-base" />
105+ Dissociate
106+ </ DropdownMenuItem >
107+ </ div >
108+ </ Tooltip >
109+ ) }
96110 </ DropdownMenuContent >
97111 </ DropdownMenu >
98112 </ TableCell >
@@ -110,7 +124,7 @@ export function RelationshipActionsCell({
110124 < SlideOver
111125 title = {
112126 < SlideOverTitle
113- schema = { schema }
127+ schema = { parentSchema }
114128 currentObjectLabel = { relationshipLabel }
115129 title = { `Edit ${ relationshipLabel } ` }
116130 />
0 commit comments