@@ -8,18 +8,45 @@ import { Tooltip } from "@nextui-org/react";
88import MultilineTooltipAutoContent from "@/submodules/react-components/components/MultilineTooltipAuto" ;
99import { NoTableEntriesYet } from "../NoTableEntriesYet" ;
1010import { MemoIconCell , MemoIconEdit } from "../kern-icons/icons" ;
11+ import SortArrowsIdx from "./SortArrowsIdx" ;
1112
1213export default function KernTable ( props : KernTableProps ) {
1314 const length = useMemo ( ( ) => props . headers ?. length || 5 , [ props . headers ?. length ] ) ;
15+
16+
17+ const onClickSortLookup = useMemo ( ( ) => {
18+ if ( ! props . headers ) return undefined ;
19+ const x = props . headers . map ( ( header , idx ) => {
20+ if ( ! header . hasSort ) return undefined ;
21+ if ( ! props . config ) return undefined ;
22+ if ( props . config . sortKey && props . config . onClickSort ) return ( ) => props . config . onClickSort ( header . id ) ;
23+ if ( props . config . sortKeyIdx && props . config . onClickSortIdx ) return ( ) => props . config . onClickSortIdx ( idx ) ;
24+ throw new Error ( "KernTable: No onClickSort or onClickSortIdx provided in config for sortable header: " + header . id ) ;
25+ return undefined ;
26+ } )
27+ return x ;
28+ } , [ props . headers , props . config ] ) ;
29+
30+ const sortArrowLookup = useMemo ( ( ) => {
31+ if ( ! props . headers ) return undefined ;
32+ return props . headers . map ( ( header , idx ) => {
33+ if ( ! props . config || ! ( props . config . sortKeyIdx || props . config . sortKey ) ) return undefined ;
34+ if ( ! header . hasSort ) return undefined ;
35+ if ( props . config . sortKey ) return < SortArrows sortKey = { props . config . sortKey } property = { header . id } /> ;
36+ if ( props . config . sortKeyIdx ) return < SortArrowsIdx sortKey = { props . config . sortKeyIdx } idx = { idx } /> ;
37+ return undefined ;
38+ } )
39+ } , [ props . config , props . headers ] )
40+
1441 return (
1542 < table className = { `min-w-full divide-y divide-gray-300 rounded-b-lg ${ props . config && props . config ?. addBorder ? 'border border-gray-300' : '' } ` } >
1643 < thead className = "bg-gray-50" >
1744 < tr >
18- { props . headers . map ( ( header ) => (
45+ { props . headers . map ( ( header , idx ) => (
1946 < th scope = "col"
2047 className = { `px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500 ${ header . hasSort ? 'hover:text-gray-700 cursor-pointer' : '' } ` }
2148 id = { header . id } key = { header . id }
22- onClick = { header . hasSort ? ( ) => props . config . onClickSort ( header . id ) : undefined }
49+ onClick = { onClickSortLookup [ idx ] }
2350 >
2451 { header . hasCheckboxes ? < >
2552 < input
@@ -36,7 +63,7 @@ export default function KernTable(props: KernTableProps) {
3663 color = "invert"
3764 placement = "top" > Est. Precision</ Tooltip >
3865 </ div > }
39- { header . hasSort && < SortArrows sortKey = { props . config . sortKey } property = { header . id } /> }
66+ { sortArrowLookup [ idx ] }
4067 </ div > }
4168 </ th > ) ) }
4269 </ tr >
@@ -88,7 +115,7 @@ function ComponentMapper(cell: any) {
88115 case 'CancelTaskCell' :
89116 return < CancelTaskCell { ...cell } /> ;
90117 case 'IconCell' :
91- return < MemoIconCell { ...cell } /> ;
118+ return < IconCell { ...cell } /> ;
92119 case 'ConfigCell' :
93120 return < ConfigCell { ...cell } /> ;
94121 case 'EditDeleteOrgButtonCell' :
@@ -131,7 +158,7 @@ function ComponentMapper(cell: any) {
131158 case 'text' :
132159 return < span > { cell . value ?? < NotApplicableBadge /> } </ span >
133160 case 'number' :
134- return < span > { cell . value [ 1 ] } </ span >
161+ return < span > { cell . value [ 1 ] ?? < NotApplicableBadge /> } </ span >
135162 case 'boolean' :
136163 return < input type = "checkbox" value = { cell . value } checked = { cell . checked } onClick = { cell . valueChange ? cell . valueChange : undefined } readOnly />
137164 case 'dateInput' :
0 commit comments