@@ -112,7 +112,10 @@ const TermsTable = ({ setOpenEditAttributes, setAttributes, attributes, ontology
112112 } ;
113113
114114 const sortedRows = React . useMemo (
115- ( ) => stableSort ( terms || [ ] , getComparator ( order , orderBy ) ) ,
115+ ( ) => {
116+ if ( ! terms || terms . length === 0 ) return [ ] ;
117+ return stableSort ( terms , getComparator ( order , orderBy ) ) ;
118+ } ,
116119 [ order , orderBy , terms ]
117120 ) ;
118121
@@ -156,7 +159,7 @@ const TermsTable = ({ setOpenEditAttributes, setAttributes, attributes, ontology
156159 </ Box >
157160 }
158161 return (
159- terms . length > 0 ? (
162+ terms && terms . length > 0 ? (
160163 < Box sx = { { display : 'flex' , flexDirection : 'column' , height : '100%' } } >
161164 < Typography color = { gray800 } fontSize = '1.125rem' fontWeight = { 600 } mb = '2.75rem' >
162165 Edit your terms or select an header to bulk edit that property
@@ -243,11 +246,11 @@ const TermsTable = ({ setOpenEditAttributes, setAttributes, attributes, ontology
243246 attributes = { attributes }
244247 />
245248 < TableBody >
246- { sortedRows . map ( ( row , index ) => (
249+ { sortedRows && sortedRows . length > 0 ? sortedRows . map ( ( row , index ) => (
247250 < TableRow key = { index } >
248251 { filteredColumns . map ( ( column ) => {
249252 const isEditing = editingCell ?. rowIndex === index && editingCell ?. columnId === column . id ;
250- const cellValue = row [ column . id ] ;
253+ const cellValue = row && row [ column . id ] ;
251254
252255 return (
253256 < TableCell
@@ -273,27 +276,51 @@ const TermsTable = ({ setOpenEditAttributes, setAttributes, attributes, ontology
273276 fullWidth
274277 sx = { { minWidth : 0 } }
275278 />
276- ) : Array . isArray ( cellValue ) ? (
279+ ) : Array . isArray ( cellValue ) && cellValue . length > 0 ? (
277280 < Stack gap = '.25rem' direction = "row" alignItems = "center" maxWidth = '20rem' flexWrap = 'wrap' >
278- { cellValue . map ( ( chip , chipIndex ) => (
279- < Chip key = { `${ chip } -${ chipIndex } ` } label = { chip } className = 'rounded IDchip-outlined' icon = { < OpenInNewOutlinedIcon /> } onClick = { ( ) => handleChipClick ( chip ) } />
280- ) ) }
281+ { cellValue . map ( ( chip , chipIndex ) => {
282+ const chipLabel = typeof chip === 'object' && chip !== null
283+ ? chip [ '@value' ] || chip . value || chip [ '@id' ] || JSON . stringify ( chip )
284+ : chip || '' ;
285+ const chipValue = typeof chip === 'object' && chip !== null
286+ ? chip [ '@id' ] || chip . value || chip [ '@value' ]
287+ : chip ;
288+ return (
289+ < Chip
290+ key = { `${ chipLabel } -${ chipIndex } ` }
291+ label = { chipLabel }
292+ className = 'rounded IDchip-outlined'
293+ icon = { < OpenInNewOutlinedIcon /> }
294+ onClick = { ( ) => handleChipClick ( chipValue ) }
295+ />
296+ ) ;
297+ } ) }
281298 </ Stack >
282299 ) : column . id === '@id' ? (
283300 // Format the Interlex ID to show just the ID part - read-only display
284301 < span style = { { color : gray700 , fontWeight : 500 } } >
285- { cellValue ?. split ( '/' ) . pop ( ) || cellValue }
302+ { ( ( ) => {
303+ if ( ! cellValue ) return '' ;
304+ if ( typeof cellValue === 'object' ) {
305+ const idValue = cellValue [ '@id' ] || cellValue . id || cellValue [ '@value' ] || JSON . stringify ( cellValue ) ;
306+ return typeof idValue === 'string' ? idValue . split ( '/' ) . pop ( ) || idValue : idValue ;
307+ }
308+ return typeof cellValue === 'string' ? cellValue . split ( '/' ) . pop ( ) || cellValue : cellValue ;
309+ } ) ( ) }
286310 </ span >
287311 ) : (
288312 < span >
289- { cellValue }
313+ { typeof cellValue === 'object' && cellValue !== null
314+ ? cellValue [ '@value' ] || cellValue . value || JSON . stringify ( cellValue )
315+ : cellValue || ''
316+ }
290317 </ span >
291318 ) }
292319 </ TableCell >
293320 ) ;
294321 } ) }
295322 </ TableRow >
296- ) ) }
323+ ) ) : null }
297324 </ TableBody >
298325 </ Table >
299326 </ TableContainer >
0 commit comments