Skip to content

Commit

Permalink
Show edit button only in edit workflow (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
danjov authored Jun 26, 2024
2 parents 98d977a + 098dc59 commit b8f13f9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/client/src/commons/menu/detailView/detailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b8f13f9

Please sign in to comment.