Skip to content

Commit ffd5f9a

Browse files
Added lock link
1 parent 0e1211d commit ffd5f9a

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/components/projects/projectId/labeling/sessionId/main-component/LabelingMainComponent.tsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { selectAllUsers, selectUser, setBricksIntegrator, setComments } from "@/src/reduxStore/states/general";
22
import { setAvailableLinks, updateRecordRequests, setSelectedLink, selectRecordRequestsRla, updateUsers, setSettings, selectSettings, setUserDisplayId, selectRecordRequestsRecord, initOnLabelPageDestruction, selectUserDisplayId, selectDisplayUserRole, setDisplayUserRole } from "@/src/reduxStore/states/pages/labeling";
33
import { selectProjectId } from "@/src/reduxStore/states/project"
4-
import { AVAILABLE_LABELING_LINKS, GET_RECORD_LABEL_ASSOCIATIONS, GET_TOKENIZED_RECORD, REQUEST_HUDDLE_DATA } from "@/src/services/gql/queries/labeling";
4+
import { AVAILABLE_LABELING_LINKS, GET_RECORD_LABEL_ASSOCIATIONS, GET_TOKENIZED_RECORD, LINK_LOCKED, REQUEST_HUDDLE_DATA } from "@/src/services/gql/queries/labeling";
55
import { LabelingLinkType } from "@/src/types/components/projects/projectId/labeling/labeling-main-component";
66
import { UserRole } from "@/src/types/shared/sidebar";
77
import { LabelingSuiteManager } from "@/src/util/classes/labeling/manager";
@@ -49,6 +49,7 @@ export default function LabelingMainComponent() {
4949

5050
const [huddleData, setHuddleData] = useState(null);
5151
const [absoluteWarning, setAbsoluteWarning] = useState(null);
52+
const [lockedLink, setLockedLink] = useState(false);
5253

5354
const [refetchHuddleData] = useLazyQuery(REQUEST_HUDDLE_DATA, { fetchPolicy: 'no-cache' });
5455
const [refetchAvailableLinks] = useLazyQuery(AVAILABLE_LABELING_LINKS, { fetchPolicy: 'no-cache' });
@@ -58,6 +59,7 @@ export default function LabelingMainComponent() {
5859
const [refetchAttributes] = useLazyQuery(GET_ATTRIBUTES_BY_PROJECT_ID, { fetchPolicy: "network-only" });
5960
const [refetchLabelingTasksByProjectId] = useLazyQuery(GET_LABELING_TASKS_BY_PROJECT_ID, { fetchPolicy: "network-only" });
6061
const [refetchComments] = useLazyQuery(REQUEST_COMMENTS, { fetchPolicy: "no-cache" });
62+
const [refetchLinkLocked] = useLazyQuery(LINK_LOCKED, { fetchPolicy: "no-cache" });
6163

6264
useEffect(unsubscribeWSOnDestroy(router, [CurrentPage.LABELING]), []);
6365

@@ -94,17 +96,29 @@ export default function LabelingMainComponent() {
9496
}, []);
9597

9698
useEffect(() => {
97-
if (!router.query.sessionId || !user) return;
98-
if (router.query.type == LabelingLinkType.HEURISTIC) {
99-
dispatch(setDisplayUserRole(UserRole.ANNOTATOR));
100-
setAbsoluteWarning(user?.role == UserRole.ENGINEER ? 'You are viewing this page as ' + UserRole.ANNOTATOR + ' you are not able to edit' : null);
101-
} else if (router.query.type == LabelingLinkType.DATA_SLICE) {
102-
dispatch(setDisplayUserRole(UserRole.EXPERT));
103-
setAbsoluteWarning(user?.role == UserRole.ENGINEER ? 'You are viewing this page as ' + UserRole.EXPERT + ' you are not able to edit' : null);
104-
} else {
99+
if (!router.query.sessionId || !user || !projectId) return;
100+
if (router.query.type == LabelingLinkType.SESSION) {
105101
dispatch(setDisplayUserRole(user.role));
102+
return;
106103
}
107-
}, [router.query, user]);
104+
refetchLinkLocked({ variables: { projectId: projectId, linkRoute: router.asPath } }).then((result) => {
105+
const lockedLink = result['data']['linkLocked'];
106+
if (lockedLink) {
107+
setAbsoluteWarning(user?.role !== UserRole.ENGINEER ? 'This link is locked, contact your supervisor to request access' : null)
108+
} else {
109+
if (router.query.type == LabelingLinkType.HEURISTIC) {
110+
dispatch(setDisplayUserRole(UserRole.ANNOTATOR));
111+
setAbsoluteWarning(user?.role == UserRole.ENGINEER ? 'You are viewing this page as ' + UserRole.ANNOTATOR + ' you are not able to edit' : null);
112+
} else if (router.query.type == LabelingLinkType.DATA_SLICE) {
113+
dispatch(setDisplayUserRole(UserRole.EXPERT));
114+
setAbsoluteWarning(user?.role == UserRole.ENGINEER ? 'You are viewing this page as ' + UserRole.EXPERT + ' you are not able to edit' : null);
115+
} else {
116+
dispatch(setDisplayUserRole(user.role));
117+
}
118+
}
119+
setLockedLink(lockedLink);
120+
});
121+
}, [router.query, user, projectId]);
108122

109123
useEffect(() => {
110124
if (!projectId) return;
@@ -327,9 +341,10 @@ export default function LabelingMainComponent() {
327341
return (<div className={`h-full bg-white flex flex-col ${LabelingSuiteManager.somethingLoading ? style.wait : ''}`}>
328342
<NavigationBarTop absoluteWarning={absoluteWarning} />
329343
<div className="flex-grow overflow-y-auto" style={{ height: 'calc(100vh - 194px)' }}>
330-
{settings.task.show && (user?.role != UserRole.ANNOTATOR && userDisplayRole != UserRole.ANNOTATOR) && <LabelingSuiteTaskHeader />}
331-
<LabelingSuiteLabeling />
332-
{settings.overviewTable.show && SessionManager.currentRecordId !== "deleted" && <LabelingSuiteOverviewTable />}
344+
{!lockedLink && <>
345+
{settings.task.show && (user?.role != UserRole.ANNOTATOR && userDisplayRole != UserRole.ANNOTATOR) && <LabelingSuiteTaskHeader />}
346+
<LabelingSuiteLabeling />
347+
{settings.overviewTable.show && SessionManager.currentRecordId !== "deleted" && <LabelingSuiteOverviewTable />}</>}
333348
</div>
334349
<NavigationBarBottom />
335350
</div>)

src/services/gql/queries/labeling.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,9 @@ query ($projectId: ID!, $recordId: ID!) {
100100
}
101101
}
102102
}
103-
`;
103+
`;
104+
105+
export const LINK_LOCKED = gql`
106+
query ($projectId: ID!, $linkRoute: String!) {
107+
linkLocked(projectId: $projectId, linkRoute: $linkRoute)
108+
}`;

0 commit comments

Comments
 (0)