From 098dc596a8b2e14a528aedcb5b45f517a97571c7 Mon Sep 17 00:00:00 2001 From: danjov Date: Wed, 26 Jun 2024 10:57:44 +0200 Subject: [PATCH] Show edit button only in edit workflow Except for the publication UI --- .../commons/menu/detailView/detailHeader.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/client/src/commons/menu/detailView/detailHeader.tsx b/src/client/src/commons/menu/detailView/detailHeader.tsx index 277667160..0b65c15f4 100644 --- a/src/client/src/commons/menu/detailView/detailHeader.tsx +++ b/src/client/src/commons/menu/detailView/detailHeader.tsx @@ -48,20 +48,21 @@ const DetailHeader = () => { }, [borehole.data.lock]); useEffect(() => { - const isStatusPage = location.pathname.endsWith("/status"); - const isBoreholeWorkflowFinished = borehole?.data.workflow?.finished !== null; - - if ( - (borehole.data.lock !== null && borehole.data.lock.id !== user.data.id) || - (isBoreholeWorkflowFinished && !isStatusPage) - ) { + if (borehole.data.lock !== null && borehole.data.lock.id !== user.data.id) { setEditableByCurrentUser(false); return; } - const matchingWorkgroup = user.data.workgroups.find(workgroup => workgroup.id === borehole.data.workgroup?.id); - if (matchingWorkgroup && Object.prototype.hasOwnProperty.call(matchingWorkgroup, "roles")) { - setEditableByCurrentUser(matchingWorkgroup.roles.includes(borehole.data.role)); - } + + const matchingWorkgroup = + user.data.workgroups.find(workgroup => workgroup.id === borehole.data.workgroup?.id) ?? false; + const userRoleMatches = + matchingWorkgroup && + Object.prototype.hasOwnProperty.call(matchingWorkgroup, "roles") && + matchingWorkgroup.roles.includes(borehole.data.role); + const isStatusPage = location.pathname.endsWith("/status"); + const isBoreholeInEditWorkflow = borehole?.data.workflow?.role === "EDIT"; + + setEditableByCurrentUser(userRoleMatches && (isStatusPage || isBoreholeInEditWorkflow)); }, [editingEnabled, user, borehole, location]); if (borehole.isFetching) {