1- import React , { useState , useContext , useEffect } from "react" ;
1+ import React , {
2+ useState ,
3+ useContext ,
4+ useEffect ,
5+ useCallback ,
6+ useMemo ,
7+ } from "react" ;
28import { useParams } from "react-router-dom" ;
39import {
410 EuiCallOut ,
@@ -7,7 +13,6 @@ import {
713 EuiFlexItem ,
814 EuiButton ,
915 EuiPanel ,
10- EuiTitle ,
1116 EuiText ,
1217 EuiLoadingSpinner ,
1318 EuiBasicTable ,
@@ -45,17 +50,23 @@ const ClassificationMethod = () => {
4550 const [ pageSize , setPageSize ] = useState ( 25 ) ;
4651
4752 const spec = data ?. object ?. spec || data ?. spec || { } ;
48- const labelFields : { name : string ; valueType ?: string } [ ] =
49- spec . features || [ ] ;
50- const entities : string [ ] = spec . entityColumns ?. length
51- ? spec . entityColumns . map ( ( ec : { name : string } ) => ec . name )
52- : spec . entities || [ ] ;
53+ const labelFields : { name : string ; valueType ?: string } [ ] = useMemo (
54+ ( ) => spec . features || [ ] ,
55+ [ spec . features ] ,
56+ ) ;
57+ const entities : string [ ] = useMemo (
58+ ( ) =>
59+ spec . entityColumns ?. length
60+ ? spec . entityColumns . map ( ( ec : { name : string } ) => ec . name )
61+ : spec . entities || [ ] ,
62+ [ spec . entityColumns , spec . entities ] ,
63+ ) ;
5364
5465 const configuredValues = annotationConfig ?. label_values || { } ;
5566 const fieldRoles = annotationConfig ?. field_roles || { } ;
5667 const labelWidgets = annotationConfig ?. label_widgets || { } ;
5768
58- const fetchLabels = async ( ) => {
69+ const fetchLabels = useCallback ( async ( ) => {
5970 setIsLoading ( true ) ;
6071 setError ( null ) ;
6172 try {
@@ -84,13 +95,13 @@ const ClassificationMethod = () => {
8495 } finally {
8596 setIsLoading ( false ) ;
8697 }
87- } ;
98+ } , [ labelViewName , registryUrl ] ) ;
8899
89100 useEffect ( ( ) => {
90101 if ( labelViewName ) {
91102 fetchLabels ( ) ;
92103 }
93- } , [ labelViewName ] ) ;
104+ } , [ labelViewName , fetchLabels ] ) ;
94105
95106 const handleFieldChange = ( rowId : string , field : string , value : string ) => {
96107 setRows ( ( prev ) =>
@@ -186,7 +197,7 @@ const ClassificationMethod = () => {
186197 URL . revokeObjectURL ( url ) ;
187198 } ;
188199
189- const filteredRows = React . useMemo ( ( ) => {
200+ const filteredRows = useMemo ( ( ) => {
190201 if ( ! searchQuery . trim ( ) ) return rows ;
191202 const q = searchQuery . toLowerCase ( ) ;
192203 return rows . filter ( ( row ) =>
@@ -198,12 +209,12 @@ const ClassificationMethod = () => {
198209 ) ;
199210 } , [ rows , searchQuery ] ) ;
200211
201- const paginatedRows = React . useMemo ( ( ) => {
212+ const paginatedRows = useMemo ( ( ) => {
202213 const start = pageIndex * pageSize ;
203214 return filteredRows . slice ( start , start + pageSize ) ;
204215 } , [ filteredRows , pageIndex , pageSize ] ) ;
205216
206- const uniqueValuesForField = React . useMemo ( ( ) => {
217+ const uniqueValuesForField = useMemo ( ( ) => {
207218 const result : Record < string , string [ ] > = { } ;
208219 labelFields . forEach ( ( field ) => {
209220 const values = new Set < string > ( ) ;
0 commit comments