@@ -5,7 +5,7 @@ import { useDispatch, useSelector } from "react-redux";
55import { selectProjectId } from "@/src/reduxStore/states/project" ;
66import KernTable from "@/submodules/react-components/components/kern-table/KernTable" ;
77import { EVALUATION_RUN_TABLE_CONFIG , EVALUATION_RUN_TABLE_HEADER , prepareTableBodyEvaluationRun } from "@/src/util/table-preparations/evaluation-runs" ;
8- import { useCallback , useEffect , useLayoutEffect , useRef , useState } from "react" ;
8+ import { useCallback , useEffect , useMemo , useState } from "react" ;
99import { getEvaluationGroups , getEvaluationRuns } from "@/src/services/base/playground" ;
1010import { selectAllUsers } from "@/src/reduxStore/states/general" ;
1111import { arrayToDict } from "@/submodules/javascript-functions/general" ;
@@ -23,17 +23,13 @@ export default function EvaluationRuns() {
2323 const usersDict = arrayToDict ( users , 'id' ) ;
2424 const onAttributeEmbeddings = useSelector ( selectOnAttributeEmbeddings ) ;
2525
26- const [ preparedValues , setPreparedValues ] = useState ( null ) ;
2726 const [ evaluationRuns , setEvaluationRuns ] = useState ( null ) ;
2827 const [ evaluationGroups , setEvaluationGroups ] = useState ( [ ] ) ;
2928 const [ evaluationDict , setEvaluationDict ] = useState ( null ) ;
3029 const [ embeddingsDict , setEmbeddingsDict ] = useState ( null ) ;
3130 const [ refetchTrigger , setRefetchTrigger ] = useState ( false )
32- const [ preparedHeaders , setPreparedHeaders ] = useState ( EVALUATION_RUN_TABLE_HEADER ) ;
3331 const [ selectedEvaluationRuns , setSelectedEvaluationRuns ] = useState ( new Set < string > ( ) ) ;
3432 const [ checked , setChecked ] = useState ( false ) ;
35- const [ indeterminate , setIndeterminate ] = useState ( false ) ;
36- const checkbox = useRef < any > ( null ) ;
3733
3834 useEffect ( ( ) => {
3935 if ( ! projectId ) return ;
@@ -51,48 +47,35 @@ export default function EvaluationRuns() {
5147 setEmbeddingsDict ( arrayToDict ( onAttributeEmbeddings , 'id' ) ) ;
5248 } , [ onAttributeEmbeddings ] ) ;
5349
54- useLayoutEffect ( ( ) => {
55- if ( ! selectedEvaluationRuns || ! evaluationRuns ) return ;
56- const isIndeterminate = selectedEvaluationRuns . size > 0 && selectedEvaluationRuns . size < evaluationRuns . length ;
57- setChecked ( selectedEvaluationRuns . size > 0 && selectedEvaluationRuns . size === evaluationRuns . length ) ;
58- setIndeterminate ( isIndeterminate ) ;
59-
60- if ( checkbox . current !== null ) {
61- checkbox . current . indeterminate = isIndeterminate ;
62- }
63- } , [ selectedEvaluationRuns , evaluationRuns ] ) ;
64-
65- useEffect ( ( ) => {
66- if ( ! evaluationRuns || ! evaluationDict || ! embeddingsDict ) return ;
67- setPreparedValues ( prepareTableBodyEvaluationRun ( evaluationRuns , usersDict , embeddingsDict , evaluationDict , navigateToDetails , selectedEvaluationRuns , setSelectedEvaluationRuns ) ) ;
68- } , [ evaluationRuns , evaluationDict , embeddingsDict , selectedEvaluationRuns , setSelectedEvaluationRuns ] ) ;
69-
70- useEffect ( ( ) => {
71- setPreparedHeaders ( preparedHeaders . map ( ( header ) => {
72- if ( header . id === "checkboxes" ) {
73- return { ...header , hasCheckboxes : true , checked : checked , onChange : toggleAll } ;
74- }
75- return header ;
76- } ) )
77- } , [ checked , evaluationGroups , selectedEvaluationRuns ] )
78-
7950 const refetchEvaluationRuns = useCallback ( ( ) => {
8051 getEvaluationRuns ( projectId , ( res ) => {
8152 setEvaluationRuns ( res ) ;
8253 setSelectedEvaluationRuns ( new Set < string > ( ) ) ;
8354 } ) ;
8455 } , [ projectId ] ) ;
8556
86- function toggleAll ( ) {
87- if ( checked || indeterminate ) setSelectedEvaluationRuns ( new Set < string > ( ) ) ;
57+ const navigateToDetails = useCallback ( ( evaluationRunId : string ) => {
58+ router . push ( `/projects/${ projectId } /playground/${ evaluationRunId } ` ) ;
59+ } , [ projectId ] ) ;
60+
61+ const toggleAll = useCallback ( ( ) => {
62+ if ( ! evaluationRuns || evaluationRuns . length === 0 ) return ;
63+ if ( checked ) setSelectedEvaluationRuns ( new Set < string > ( ) ) ;
8864 else setSelectedEvaluationRuns ( new Set < string > ( evaluationRuns . map ( x => x . id ) ) ) ;
89- setChecked ( ! checked && ! indeterminate )
90- setIndeterminate ( false )
91- }
65+ setChecked ( ! checked ) ;
66+ } , [ checked , evaluationRuns ] ) ;
9267
93- function navigateToDetails ( evaluationRunId : string ) {
94- router . push ( `/projects/${ projectId } /playground/${ evaluationRunId } ` ) ;
95- }
68+
69+ const preparedValues = useMemo ( ( ) => {
70+ if ( ! evaluationRuns ) return null ;
71+ return prepareTableBodyEvaluationRun ( evaluationRuns , usersDict , embeddingsDict , evaluationDict , navigateToDetails , selectedEvaluationRuns , setSelectedEvaluationRuns ) ;
72+ } , [ evaluationRuns , usersDict , embeddingsDict , evaluationDict , selectedEvaluationRuns , setSelectedEvaluationRuns ] ) ;
73+
74+ const finalHeaders = useMemo ( ( ) => EVALUATION_RUN_TABLE_HEADER . map ( ( run ) => {
75+ if ( ! selectedEvaluationRuns || ! evaluationRuns ) return ;
76+ if ( run . id === "checkboxes" ) return { ...run , checked : selectedEvaluationRuns . size === evaluationRuns . length , onChange : toggleAll } ;
77+ return run ;
78+ } ) , [ selectedEvaluationRuns , evaluationRuns ] ) ;
9679
9780 return < >
9881 { projectId != null && < div className = "p-4 bg-gray-100 h-full flex-1 flex flex-col overflow-y-auto" >
@@ -121,9 +104,9 @@ export default function EvaluationRuns() {
121104 </ div >
122105 }
123106 </ div >
124- { preparedHeaders && preparedValues && ( evaluationRuns . length > 0 ?
107+ { finalHeaders && preparedValues && ( evaluationRuns . length > 0 ?
125108 < KernTable
126- headers = { preparedHeaders }
109+ headers = { finalHeaders }
127110 values = { preparedValues }
128111 config = { EVALUATION_RUN_TABLE_CONFIG }
129112 /> :
0 commit comments