Skip to content

Commit 422a898

Browse files
User roles different display
1 parent fc63570 commit 422a898

File tree

14 files changed

+132
-80
lines changed

14 files changed

+132
-80
lines changed

src/components/projects/projectId/data-browser/modals/DataSliceInfoModal.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import Modal from "@/src/components/shared/modal/Modal";
22
import { selectIsManaged } from "@/src/reduxStore/states/general";
3-
import { selectModal } from "@/src/reduxStore/states/modal";
3+
import { closeModal, selectModal } from "@/src/reduxStore/states/modal";
4+
import { setDisplayUserRole } from "@/src/reduxStore/states/pages/labeling";
45
import { ModalEnum } from "@/src/types/shared/modal";
6+
import { UserRole } from "@/src/types/shared/sidebar";
57
import { parseLinkFromText } from "@/src/util/shared/link-parser-helper";
68
import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants";
79
import { copyToClipboard } from "@/submodules/javascript-functions/general";
810
import { Tooltip } from "@nextui-org/react";
911
import { useRouter } from "next/router";
1012
import { Fragment } from "react";
11-
import { useSelector } from "react-redux";
13+
import { useDispatch, useSelector } from "react-redux";
1214

1315
export default function DataSliceInfoModal() {
1416
const router = useRouter();
15-
17+
const dispatch = useDispatch();
1618

1719
const isManaged = useSelector(selectIsManaged);
1820
const modalSliceInfo = useSelector(selectModal(ModalEnum.DATA_SLICE_INFO));
1921

2022
function testLink(link) {
23+
dispatch(setDisplayUserRole(UserRole.EXPERT));
2124
const linkData = parseLinkFromText(link);
2225
router.push(linkData.fullUrl);
26+
dispatch(closeModal(ModalEnum.DATA_SLICE_INFO));
2327
}
2428

2529
return (<Modal modalName={ModalEnum.DATA_SLICE_INFO}>

src/components/projects/projectId/heuristics/heuristicId/crowd-labeler/CrowdLabelerSettings.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { selectAnnotators, selectAnnotatorsDict } from "@/src/reduxStore/states/general";
22
import { selectDataSlicesAll, selectDataSlicesDict } from "@/src/reduxStore/states/pages/data-browser";
33
import { selectHeuristic, updateHeuristicsState } from "@/src/reduxStore/states/pages/heuristics";
4+
import { setDisplayUserRole } from "@/src/reduxStore/states/pages/labeling";
45
import { selectLabelingTasksAll } from "@/src/reduxStore/states/pages/settings";
56
import { selectProjectId } from "@/src/reduxStore/states/project";
67
import { CREATE_ACCESS_LINK, LOCK_ACCESS_LINK, REMOVE_ACCESS_LINK, UPDATE_INFORMATION_SOURCE } from "@/src/services/gql/mutations/heuristics";
8+
import { UserRole } from "@/src/types/shared/sidebar";
79
import { parseToSettingsJson } from "@/src/util/components/projects/projectId/heuristics/heuristicId/crowd-labeler-helper";
810
import { buildFullLink, parseLinkFromText } from "@/src/util/shared/link-parser-helper";
911
import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants";
@@ -73,6 +75,7 @@ export default function CrowdLabelerSettings() {
7375

7476

7577
function testLink() {
78+
dispatch(setDisplayUserRole(UserRole.ANNOTATOR));
7679
const linkData = parseLinkFromText(currentHeuristic.crowdLabelerSettings.accessLink);
7780
router.push(linkData.fullUrl);
7881
}

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { selectAllUsers, selectUser, setBricksIntegrator, setComments } from "@/src/reduxStore/states/general";
2-
import { setAvailableLinks, updateRecordRequests, setSelectedLink, selectRecordRequestsRla, updateUsers, setSettings, selectSettings, setUserDisplayId, selectRecordRequestsRecord, initOnLabelPageDestruction, selectUserDisplayId } from "@/src/reduxStore/states/pages/labeling";
2+
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"
44
import { AVAILABLE_LABELING_LINKS, GET_RECORD_LABEL_ASSOCIATIONS, GET_TOKENIZED_RECORD, REQUEST_HUDDLE_DATA } from "@/src/services/gql/queries/labeling";
55
import { LabelingLinkType } from "@/src/types/components/projects/projectId/labeling/labeling-main-component";
@@ -45,8 +45,10 @@ export default function LabelingMainComponent() {
4545
const record = useSelector(selectRecordRequestsRecord);
4646
const allUsers = useSelector(selectAllUsers);
4747
const userDisplayId = useSelector(selectUserDisplayId);
48+
const userDisplayRole = useSelector(selectDisplayUserRole);
4849

4950
const [huddleData, setHuddleData] = useState(null);
51+
const [absoluteWarning, setAbsoluteWarning] = useState(null);
5052

5153
const [refetchHuddleData] = useLazyQuery(REQUEST_HUDDLE_DATA, { fetchPolicy: 'no-cache' });
5254
const [refetchAvailableLinks] = useLazyQuery(AVAILABLE_LABELING_LINKS, { fetchPolicy: 'no-cache' });
@@ -89,7 +91,20 @@ export default function LabelingMainComponent() {
8991
useEffect(() => () => {
9092
SessionManager.initMeOnDestruction();
9193
dispatch(initOnLabelPageDestruction());
92-
}, [])
94+
}, []);
95+
96+
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 {
105+
dispatch(setDisplayUserRole(user.role));
106+
}
107+
}, [router.query, user]);
93108

94109
useEffect(() => {
95110
if (!projectId) return;
@@ -222,7 +237,10 @@ export default function LabelingMainComponent() {
222237
if (SessionManager.labelingLinkData) SessionManager.changeLinkLockState(true);
223238
return;
224239
}
225-
if (huddleData.startPos != -1) SessionManager.labelingLinkData.requestedPos = huddleData.startPos;
240+
if (huddleData.startPos != -1) {
241+
if (userDisplayRole != UserRole.ENGINEER) SessionManager.labelingLinkData.requestedPos = 0;
242+
else SessionManager.labelingLinkData.requestedPos = huddleData.startPos;
243+
}
226244
SessionManager.huddleData = {
227245
recordIds: huddleData.recordIds ? huddleData.recordIds as string[] : [],
228246
partial: false,
@@ -236,12 +254,13 @@ export default function LabelingMainComponent() {
236254
let pos = SessionManager.labelingLinkData.requestedPos;
237255
if (huddleData.startPos != -1) pos++; //zero based in backend
238256
SessionManager.jumpToPosition(pos);
257+
dispatch(setDisplayUserRole(user.role));
239258
router.push(`/projects/${projectId}/labeling/${SessionManager.huddleData.linkData.huddleId}?pos=${SessionManager.huddleData.linkData.requestedPos}&type=${SessionManager.huddleData.linkData.linkType}`);
240259
});
241260
}
242261

243262
function collectAvailableLinks() {
244-
if (user?.role == UserRole.ENGINEER) return;
263+
if (userDisplayRole?.role == UserRole.ENGINEER) return;
245264
const heuristicId = SessionManager.labelingLinkData.linkType == LabelingLinkType.HEURISTIC ? SessionManager.labelingLinkData.huddleId : null;
246265
refetchAvailableLinks({ variables: { projectId: projectId, assumedRole: user?.role, assumedHeuristicId: heuristicId } }).then((result) => {
247266
const availableLinks = result['data']['availableLinks'];
@@ -261,13 +280,13 @@ export default function LabelingMainComponent() {
261280
refetchLabelingTasksByProjectId({ variables: { projectId: projectId } }).then((res) => {
262281
const labelingTasks = postProcessLabelingTasks(res['data']['projectByProjectId']['labelingTasks']['edges']);
263282
const labelingTasksProcessed = postProcessLabelingTasksSchema(labelingTasks);
264-
dispatch(setLabelingTasksAll(prepareTasksForRole(labelingTasksProcessed)));
283+
dispatch(setLabelingTasksAll(prepareTasksForRole(labelingTasksProcessed, userDisplayRole)));
265284
});
266285
}
267286

268-
function prepareTasksForRole(taskData: LabelingTask[]): LabelingTask[] {
269-
if (user?.role != UserRole.ANNOTATOR) return taskData;
270-
const taskId = JSON.parse(localStorage.getItem('huddleData')).allowedTask;
287+
function prepareTasksForRole(taskData: LabelingTask[], userDisplayRole): LabelingTask[] {
288+
if (user?.role != UserRole.ANNOTATOR && userDisplayRole != UserRole.ANNOTATOR) return taskData;
289+
const taskId = JSON.parse(localStorage.getItem('huddleData'))?.allowedTask;
271290
if (!taskId) return null;
272291
else return taskData.filter(t => t.id == taskId);
273292
}
@@ -306,12 +325,9 @@ export default function LabelingMainComponent() {
306325
}, [handleWebsocketNotification, projectId]);
307326

308327
return (<div className={`h-full bg-white flex flex-col ${LabelingSuiteManager.somethingLoading ? style.wait : ''}`}>
309-
{LabelingSuiteManager.absoluteWarning && <div className="absolute left-0 right-0 flex items-center justify-center pointer-events-none top-4 z-100">
310-
<span className="inline-flex items-center px-2 py-0.5 rounded font-medium bg-red-100 text-red-800">{LabelingSuiteManager.absoluteWarning}</span>
311-
</div>}
312-
<NavigationBarTop />
328+
<NavigationBarTop absoluteWarning={absoluteWarning} />
313329
<div className="flex-grow overflow-y-auto" style={{ height: 'calc(100vh - 194px)' }}>
314-
{settings.task.show && user?.role != UserRole.ANNOTATOR && <LabelingSuiteTaskHeader />}
330+
{settings.task.show && (user?.role != UserRole.ANNOTATOR && userDisplayRole != UserRole.ANNOTATOR) && <LabelingSuiteTaskHeader />}
315331
<LabelingSuiteLabeling />
316332
{settings.overviewTable.show && SessionManager.currentRecordId !== "deleted" && <LabelingSuiteOverviewTable />}
317333
</div>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Tooltip } from "@nextui-org/react";
77
import { IconSettings, IconTrash } from "@tabler/icons-react";
88
import { useDispatch, useSelector } from "react-redux";
99
import DeleteRecordModal from "./DeleteRecordModal";
10-
import { selectRecordRequestsRecord, selectSettings, updateSettings } from "@/src/reduxStore/states/pages/labeling";
10+
import { selectDisplayUserRole, selectRecordRequestsRecord, selectSettings, updateSettings } from "@/src/reduxStore/states/pages/labeling";
1111
import { ComponentType } from "@/src/types/components/projects/projectId/labeling/settings";
1212
import LabelingSettingsModal from "./LabelingSettingsModal";
1313

@@ -17,6 +17,7 @@ export default function NavigationBarBottom() {
1717
const settings = useSelector(selectSettings);
1818
const user = useSelector(selectUser);
1919
const record = useSelector(selectRecordRequestsRecord);
20+
const userDisplayRole = useSelector(selectDisplayUserRole);
2021

2122
function toggleAutoNextRecord() {
2223
dispatch(updateSettings(ComponentType.MAIN, 'autoNextRecord'));
@@ -40,7 +41,7 @@ export default function NavigationBarBottom() {
4041
<div className="relative flex-shrink-0 bg-white shadow-sm flex justify-between items-center h-full">
4142
<div className="flex flex-row flex-nowrap items-center">
4243
<div className="flex justify-center overflow-visible">
43-
{user.role == UserRole.ENGINEER && <Tooltip content={TOOLTIPS_DICT.LABELING.DELETE_CURRENT_RECORD} color="invert" placement="top">
44+
{user.role == UserRole.ENGINEER && userDisplayRole == UserRole.ENGINEER && <Tooltip content={TOOLTIPS_DICT.LABELING.DELETE_CURRENT_RECORD} color="invert" placement="top">
4445
<button onClick={() => dispatch(openModal(ModalEnum.DELETE_RECORD))} disabled={record == null}
4546
className="bg-red-100 text-red-700 border border-red-400 text-xs font-semibold mr-3 px-4 py-2 rounded-md flex hover:bg-red-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 disabled:opacity-50 disabled:cursor-not-allowed">
4647
<IconTrash className="mr-2" size={16} />
@@ -75,7 +76,7 @@ export default function NavigationBarBottom() {
7576
</>}
7677
</div>
7778
</div>
78-
{user.role !== UserRole.ANNOTATOR && <Tooltip onClick={() => dispatch(openModal(ModalEnum.LABELING_SETTINGS))}
79+
{user.role !== UserRole.ANNOTATOR && userDisplayRole != UserRole.ANNOTATOR && <Tooltip onClick={() => dispatch(openModal(ModalEnum.LABELING_SETTINGS))}
7980
content={<div className="w-32">Open Labeling Suite settings</div>} color="invert" placement="left">
8081
<div className="p-2 border border-gray-300 rounded-md">
8182
<IconSettings className="h-6 w-6" />

0 commit comments

Comments
 (0)