@@ -14,6 +14,7 @@ import { EVALUATION_SETS_TABLE_CONFIG, EVALUATION_SETS_TABLE_HEADER, prepareTabl
1414import KernButton from "@/submodules/react-components/components/kern-button/KernButton" ;
1515import { selectAllUsers } from "@/src/reduxStore/states/general" ;
1616import { arrayToDict } from "@/submodules/javascript-functions/general" ;
17+ import useRefFor from "@/submodules/react-components/hooks/useRefFor" ;
1718
1819export function EvaluationSets ( ) {
1920 const dispatch = useDispatch ( ) ;
@@ -26,17 +27,18 @@ export function EvaluationSets() {
2627 const [ checked , setChecked ] = useState ( false )
2728 const [ selectedEvaluationSets , setSelectedEvaluationSets ] = useState ( new Set < string > ( ) ) ;
2829
30+ const projectIdRef = useRefFor ( projectId ) ;
2931 useEffect ( ( ) => {
30- if ( ! projectId ) return ;
31- getEvaluationSets ( projectId , ( res ) => setEvaluationSets ( res ) ) ;
32- } , [ projectId ] ) ;
32+ if ( ! projectIdRef . current ) return ;
33+ getEvaluationSets ( projectIdRef . current , ( res ) => setEvaluationSets ( res ) ) ;
34+ } , [ ] ) ;
3335
3436 const refetchEvaluationSets = useCallback ( ( ) => {
35- getEvaluationSets ( projectId , ( res ) => {
37+ getEvaluationSets ( projectIdRef . current , ( res ) => {
3638 setEvaluationSets ( res ) ;
3739 setSelectedEvaluationSets ( new Set < string > ( ) ) ;
3840 } ) ;
39- } , [ projectId ] ) ;
41+ } , [ ] ) ;
4042
4143 const toggleAll = useCallback ( ( ) => {
4244 if ( ! evaluationSets || evaluationSets . length === 0 ) return ;
@@ -47,25 +49,26 @@ export function EvaluationSets() {
4749
4850 const viewEvalSetRecordsModal = useCallback ( ( recordIds : any [ ] , question ) => {
4951 let recordsArr = [ ] ;
50- getRecordsBatch ( projectId , { recordIds : recordIds } , ( recordsBatch ) => {
52+ getRecordsBatch ( projectIdRef . current , { recordIds : recordIds } , ( recordsBatch ) => {
5153 recordsBatch . forEach ( ( record ) => {
5254 recordsArr = [ ...recordsArr , postProcessRecordByRecordId ( record ) ] ;
5355 } ) ;
5456 dispatch ( setModalStates ( ModalEnum . VIEW_EVALUATION_SET , { open : true , records : recordsArr , question : question } ) ) ;
5557 } ) ;
56- } , [ projectId ] ) ;
58+ } , [ ] ) ;
5759
5860 const preparedValues = useMemo ( ( ) => {
5961 if ( ! evaluationSets ) return null ;
6062 return prepareTableBodyEvaluationSets ( evaluationSets , selectedEvaluationSets , setSelectedEvaluationSets , usersDict , viewEvalSetRecordsModal ) ;
61- } , [ evaluationSets , selectedEvaluationSets , setSelectedEvaluationSets , usersDict ] ) ;
63+ } , [ evaluationSets , selectedEvaluationSets , setSelectedEvaluationSets , usersDict , viewEvalSetRecordsModal ] ) ;
6264
63- const finalHeaders = useMemo ( ( ) => EVALUATION_SETS_TABLE_HEADER . map ( ( set ) => {
65+ const finalHeaders = useMemo ( ( ) => {
6466 if ( ! selectedEvaluationSets || ! evaluationSets ) return ;
65- if ( set . id === "checkboxes" ) return { ...set , checked : selectedEvaluationSets . size === evaluationSets . length , onChange : toggleAll } ;
66- return set ;
67- } ) , [ selectedEvaluationSets , evaluationSets ] ) ;
68-
67+ return EVALUATION_SETS_TABLE_HEADER . map ( ( set ) => {
68+ if ( set . id === "checkboxes" ) return { ...set , checked : selectedEvaluationSets . size === evaluationSets . length , onChange : toggleAll } ;
69+ return set ;
70+ } ) ;
71+ } , [ selectedEvaluationSets , evaluationSets , toggleAll ] ) ;
6972
7073 return < >
7174 { projectId != null && < div className = "p-4 bg-gray-100 h-full flex-1 flex flex-col overflow-y-auto" >
0 commit comments