11import { 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" ;
33import { selectProjectId } from "@/src/reduxStore/states/project"
44import { AVAILABLE_LABELING_LINKS , GET_RECORD_LABEL_ASSOCIATIONS , GET_TOKENIZED_RECORD , REQUEST_HUDDLE_DATA } from "@/src/services/gql/queries/labeling" ;
55import { 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 >
0 commit comments