11import { openModal , setModalStates } from "@/src/reduxStore/states/modal" ;
22import { selectLabelingTasksAll , setLabelingTasksAll } from "@/src/reduxStore/states/pages/settings" ;
33import { selectProjectId } from "@/src/reduxStore/states/project" ;
4- import { LabelType , LabelingTask , LabelingTaskTaskType } from "@/src/types/components/projects/projectId/settings/labeling-tasks" ;
4+ import { LabelType , LabelTypeWithOnClick , LabelingTask , LabelingTaskTaskType , LabelingTaskWithOnClick } from "@/src/types/components/projects/projectId/settings/labeling-tasks" ;
55import { ModalEnum } from "@/src/types/shared/modal" ;
66import { LabelHelper } from "@/src/util/classes/label-helper" ;
77import { isTaskNameUnique , labelingTaskFromString , labelingTaskToString } from "@/src/util/components/projects/projectId/settings/labeling-tasks-helper" ;
88import { jsonCopy } from "@/submodules/javascript-functions/general" ;
9- import { useEffect , useState } from "react"
9+ import { useCallback , useEffect , useMemo , useState } from "react"
1010import { useDispatch , useSelector } from "react-redux" ;
1111import RenameLabelModal from "./RenameLabelModal" ;
1212import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants" ;
@@ -20,6 +20,7 @@ import { updateLabelingTask } from "@/src/services/base/labeling-tasks";
2020import IconButton from "@/submodules/react-components/components/kern-button/IconButton" ;
2121import KernButton from "@/submodules/react-components/components/kern-button/KernButton" ;
2222import { MemoIconColorPicker , MemoIconPlus , MemoIconTrash } from "@/submodules/react-components/components/kern-icons/icons" ;
23+ import { useConsoleLog } from "@/submodules/react-components/hooks/useConsoleLog" ;
2324
2425export default function LabelingTasks ( ) {
2526 const dispatch = useDispatch ( ) ;
@@ -87,6 +88,28 @@ export default function LabelingTasks() {
8788 return prepareNewArray ;
8889 }
8990
91+ const deleteLabelingTask = useCallback ( ( task ) => ( ) => dispatch ( setModalStates ( ModalEnum . DELETE_LABELING_TASK , { taskId : task . id , open : true } ) ) , [ ] )
92+
93+ const deleteLabel = useCallback ( ( task : LabelingTask , label : LabelType ) => ( ) => {
94+ dispatch ( setModalStates ( ModalEnum . DELETE_LABEL , { taskId : task . id , label : label , open : true } ) ) ;
95+ } , [ ] ) ;
96+
97+ const changeColorLabel = useCallback ( ( task : LabelingTask , label : LabelType ) => ( ) => {
98+ dispatch ( setModalStates ( ModalEnum . CHANGE_COLOR , { taskId : task . id , label : label , open : true } ) ) ;
99+ } , [ ] ) ;
100+
101+ const labelingTasksFinal = useMemo ( ( ) => {
102+ if ( ! labelingTasksSchema ) return null ;
103+ return labelingTasksSchema . map ( ( labelingTask ) => (
104+ {
105+ ...labelingTask ,
106+ onDelete : deleteLabelingTask ( labelingTask ) ,
107+ labels : labelingTask . labels . map ( ( label ) => ( { ...label , onDelete : deleteLabel ( labelingTask , label ) , onChangeColor : changeColorLabel ( labelingTask , label ) } ) ) ,
108+ }
109+ ) )
110+ } , [ labelingTasksSchema ] ) ;
111+
112+
90113 return ( < div className = "mt-8" >
91114 < div className = "text-lg leading-6 text-gray-900 font-medium inline-block" >
92115 Labeling tasks
@@ -119,7 +142,7 @@ export default function LabelingTasks() {
119142 </ tr >
120143 </ thead >
121144 < tbody className = "divide-y divide-gray-200" >
122- { labelingTasksSchema && labelingTasksSchema . map ( ( task : LabelingTask , index : number ) => (
145+ { labelingTasksFinal && labelingTasksFinal . map ( ( task : LabelingTaskWithOnClick , index : number ) => (
123146 < tr key = { task . id } className = { `${ index % 2 != 0 ? 'bg-gray-50' : 'bg-white' } ` } >
124147 < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" > { task . targetName } </ td >
125148 < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" >
@@ -136,12 +159,12 @@ export default function LabelingTasks() {
136159 selectedOption = { ( option : any ) => updateLabelingTaskType ( task , index , labelingTaskFromString ( option . name ) ) } />
137160 </ td >
138161 < td className = "flex flex-wrap justify-center items-center px-3 py-2 text-sm text-gray-500" >
139- { task . labels . map ( ( label : LabelType ) => (
162+ { task . labels . map ( ( label : LabelTypeWithOnClick ) => (
140163 < div key = { label . id } className = { `inline-flex border items-center m-1 px-1.5 py-0.5 rounded-md text-sm font-medium ${ label . color . backgroundColor } ${ label . color . textColor } ${ label . color . borderColor } ${ label . color . hoverColor } ` } >
141- < MemoIconColorPicker className = "h-4 w-4 mr-1 cursor-pointer" onClick = { ( ) => dispatch ( setModalStates ( ModalEnum . CHANGE_COLOR , { taskId : task . id , label : label , open : true } ) ) } />
164+ < MemoIconColorPicker className = "h-4 w-4 mr-1 cursor-pointer" onClick = { label . onChangeColor } />
142165 < span > { label . name } </ span >
143166 { label . hotkey && < kbd className = "ml-2 uppercase inline-flex items-center border bg-white border-gray-200 rounded px-2 text-sm font-sans font-medium text-gray-400" > { label . hotkey } </ kbd > }
144- < MemoIconTrash className = "h-4 w-4 ml-1 cursor-pointer" onClick = { ( ) => dispatch ( setModalStates ( ModalEnum . DELETE_LABEL , { taskId : task . id , label : label , open : true } ) ) } />
167+ < MemoIconTrash className = "h-4 w-4 ml-1 cursor-pointer" onClick = { label . onDelete } />
145168 </ div >
146169 ) ) }
147170 < IconButton
@@ -151,8 +174,7 @@ export default function LabelingTasks() {
151174 />
152175 </ td >
153176 < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" >
154- < MemoIconTrash onClick = { ( ) => dispatch ( setModalStates ( ModalEnum . DELETE_LABELING_TASK , { taskId : task . id , open : true } ) ) }
155- className = "h-6 w-6 text-red-700 cursor-pointer" />
177+ < MemoIconTrash onClick = { task . onDelete } className = "h-6 w-6 text-red-700 cursor-pointer" />
156178 </ td >
157179 </ tr >
158180 ) ) }
0 commit comments