11import LoadingIcon from "@/src/components/shared/loading/LoadingIcon"
22import { selectUser } from "@/src/reduxStore/states/general"
3- import { removeFromRlaById , selectDisplayUserRole , selectHoverGroupDict , selectRecordRequests , selectRecordRequestsRecord , selectSettings , selectTmpHighlightIds , selectUserDisplayId , setHoverGroupDict , tmpAddHighlightIds } from "@/src/reduxStore/states/pages/labeling"
3+ import { removeFromRlaById , selectDisplayUserRole , selectHoverGroupDict , selectRecordRequests , selectRecordRequestsRecord , selectSettings , selectTmpHighlightIds , selectTokenLookupSelected , selectUserDisplayId , setHoverGroupDict , setTokenLookupSelected , tmpAddHighlightIds } from "@/src/reduxStore/states/pages/labeling"
44import { selectLabelingTasksAll , selectVisibleAttributesLabeling } from "@/src/reduxStore/states/pages/settings"
55import { selectProjectId } from "@/src/reduxStore/states/project"
66import { HotkeyLookup , LabelSourceHover , LabelingVars , TokenLookup } from "@/src/types/components/projects/projectId/labeling/labeling"
@@ -10,7 +10,7 @@ import { DEFAULT_LABEL_COLOR, FULL_RECORD_ID, SWIM_LANE_SIZE_PX, buildLabelingRl
1010import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants"
1111import { Tooltip } from "@nextui-org/react"
1212import { IconAlertCircle , IconAssembly , IconBolt , IconCode , IconSparkles , IconStar , IconUsers } from "@tabler/icons-react"
13- import { Fragment , useRef , useEffect , useState } from "react"
13+ import { Fragment , useRef , useEffect , useState , useCallback } from "react"
1414import { useDispatch , useSelector } from "react-redux"
1515import ExtractionDisplay from "./ExtractionDisplay"
1616import { LineBreaksType } from "@/src/types/components/projects/projectId/data-browser/data-browser"
@@ -26,6 +26,7 @@ import LabelSelectionBox from "./LabelSelectionBox"
2626import { filterRlaDataForUser } from "@/src/util/components/projects/projectId/labeling/overview-table-helper"
2727import { LabelingPageParts } from "@/src/types/components/projects/projectId/labeling/labeling-main-component"
2828import style from '@/src/styles/components/projects/projectId/labeling.module.css' ;
29+ import { useConsoleLog } from "@/submodules/react-components/hooks/useConsoleLog"
2930
3031const L_VARS = getDefaultLabelingVars ( ) ;
3132
@@ -99,6 +100,7 @@ export default function LabelingSuiteLabeling() {
99100
100101 useEffect ( ( ) => {
101102 const handleMouseDown = ( event ) => {
103+ console . log ( "closing the box?" )
102104 if ( ! event . target . closest ( '.label-selection-box' ) ) {
103105 setActiveTasksFunc ( [ ] ) ;
104106 }
@@ -122,6 +124,7 @@ export default function LabelingSuiteLabeling() {
122124 const handleMouseUp = ( e ) => {
123125 const [ check , attributeIdStart , tokenStart , tokenEnd , startEl ] = parseSelectionData ( ) ;
124126 setSaveTokenData ( { attributeIdStart, tokenStart, tokenEnd, startEl } ) ;
127+
125128 if ( ! check ) {
126129 clearSelected ( ) ;
127130 } else {
@@ -146,6 +149,19 @@ export default function LabelingSuiteLabeling() {
146149 setCanEditLabels ( checkCanEditLabels ( user , userDisplayRole , displayUserId ) ) ;
147150 } , [ user , displayUserId , userDisplayRole ] ) ;
148151
152+ // useEffect(() => {
153+ // if (!saveTokenData) return;
154+ // if (!settings.labeling.closeLabelBoxAfterLabel) {
155+ // const tokenLookupCopy = {};
156+ // for (const token of tokenLookupCopy[saveTokenData.attributeIdStart]?.token) {
157+ // token.selected = token.idx >= saveTokenData.tokenStart && token.idx <= saveTokenData.tokenEnd;
158+ // }
159+ // dispatch(setTokenLookupSelected(tokenLookupCopy));
160+ // } else {
161+ // dispatch(setTokenLookupSelected(null))
162+ // }
163+ // }, [saveTokenData, settings.labeling.closeLabelBoxAfterLabel]);
164+
149165 function attributesChanged ( ) {
150166 if ( ! attributes ) return ;
151167 const lVarsCopy = { ...lVars } ;
@@ -474,16 +490,18 @@ export default function LabelingSuiteLabeling() {
474490 addExtractionLabelToRecordMut ( { variables : { projectId : projectId , recordId : record . id , labelingTaskId : labelingTaskId , labelId : labelId , tokenStartIndex : selectionData . startIdx , tokenEndIndex : selectionData . endIdx , value : selectionData . value , sourceId : sourceId } } ) . then ( ( res ) => { } ) ;
475491 }
476492
477- function clearSelected ( ) {
478- const tokenLookupCopy = { ...tokenLookup } ;
479- for ( const attributeId in tokenLookupCopy ) {
480- if ( ! tokenLookupCopy [ attributeId ] . token ) continue ;
481- for ( const token of tokenLookupCopy [ attributeId ] . token ) {
482- if ( 'selected' in token ) delete token . selected ;
483- }
484- }
485- setTokenLookup ( tokenLookupCopy ) ;
486- }
493+ const clearSelected = useCallback ( ( ) => {
494+ console . log ( "clearSelected called" )
495+ // const tokenLookupCopy = jsonCopy(tokenLookup);
496+ // for (const attributeId in tokenLookupCopy) {
497+ // if (!tokenLookupCopy[attributeId].token) continue;
498+ // for (const token of tokenLookupCopy[attributeId].token) {
499+ // if ('selected' in token) delete token.selected;
500+ // }
501+ // }
502+ // setTokenLookup(tokenLookupCopy);
503+ dispatch ( setTokenLookupSelected ( null ) ) ;
504+ } , [ tokenLookup ] ) ;
487505
488506 function setSelected ( attributeId : string , tokenStart : number , tokenEnd : number , e ?: any ) {
489507 if ( ! canEditLabels && user . role != UserRole . ANNOTATOR && userDisplayRole != UserRole . ANNOTATOR ) return ;
@@ -492,9 +510,9 @@ export default function LabelingSuiteLabeling() {
492510 labelBoxPosition ( e ) ;
493511 return ;
494512 }
495- for ( const token of tokenLookupCopy [ attributeId ] ?. token ) {
496- token . selected = token . idx >= tokenStart && token . idx <= tokenEnd ;
497- }
513+ // for (const token of tokenLookupCopy[attributeId]?.token) {
514+ // token.selected = token.idx >= tokenStart && token.idx <= tokenEnd;
515+ // }
498516 if ( lVars . taskLookup [ attributeId ] . lookup [ 0 ] . task . taskType == LabelingTaskTaskType . INFORMATION_EXTRACTION ) {
499517 const extractionTasks = lVars . taskLookup [ attributeId ] . lookup . filter ( t => t . task . taskType == LabelingTaskTaskType . INFORMATION_EXTRACTION ) ;
500518 setActiveTasksFunc ( extractionTasks ) ;
@@ -631,14 +649,15 @@ export default function LabelingSuiteLabeling() {
631649 </ div >
632650 { activeTasks && activeTasks . length > 0 ? (
633651 < LabelSelectionBox activeTasks = { activeTasks } position = { position } labelLookup = { labelLookup } labelAddButtonDisabledDict = { labelAddButtonDisabledDict }
652+ clearSelected = { clearSelected }
634653 addRla = { ( task , labelId ) => {
635- const tokenLookupCopy = jsonCopy ( tokenLookup ) ;
636- if ( saveTokenData && tokenLookupCopy [ saveTokenData . attributeIdStart ] ) {
637- for ( const token of tokenLookupCopy [ saveTokenData . attributeIdStart ] ?. token ) {
638- token . selected = token . idx >= saveTokenData . tokenStart && token . idx <= saveTokenData . tokenEnd ;
639- }
640- }
641- addRla ( task , labelId , tokenLookupCopy ) ;
654+ // const tokenLookupCopy = jsonCopy(tokenLookup);
655+ // if (saveTokenData && tokenLookupCopy[saveTokenData.attributeIdStart]) {
656+ // for (const token of tokenLookupCopy[saveTokenData.attributeIdStart]?.token) {
657+ // token.selected = token.idx >= saveTokenData.tokenStart && token.idx <= saveTokenData.tokenEnd;
658+ // }
659+ // }
660+ addRla ( task , labelId , tokenLookup ) ;
642661 } }
643662 addNewLabelToTask = { ( newLabel , task ) => addNewLabelToTask ( newLabel , task ) }
644663 checkLabelVisibleInSearch = { ( newLabel , task ) => checkLabelVisibleInSearch ( labelLookup , newLabel , task ) }
0 commit comments