11import { useCallback } from 'react' ;
22import { type WidgetComponentProps } from '@deephaven/plugin' ;
3- import { type dh as DhType , type Iterator } from '@deephaven/jsapi-types' ;
4- import IrisGrid from '@deephaven/iris-grid' ;
5- import Log from '@deephaven/log' ;
3+ import { type dh as DhType } from '@deephaven/jsapi-types' ;
4+ import IrisGrid , {
5+ getSimplePivotColumnMap ,
6+ KEY_TABLE_PIVOT_COLUMN ,
7+ type KeyColumnArray ,
8+ type KeyTableSubscriptionData ,
9+ } from '@deephaven/iris-grid' ;
610import { useApi } from '@deephaven/jsapi-bootstrap' ;
711import { LoadingOverlay } from '@deephaven/components' ;
812import { getErrorMessage } from '@deephaven/utils' ;
@@ -11,44 +15,25 @@ import {
1115 type SimplePivotFetchResult ,
1216} from './useIrisGridSimplePivotModel' ;
1317
14- const log = Log . module ( 'SimplePivotWidgetPlugin' ) ;
15-
1618export function SimplePivotWidgetPlugin ( {
1719 fetch,
1820} : WidgetComponentProps < DhType . Widget > ) : JSX . Element | null {
1921 const dh = useApi ( ) ;
2022 const loadKeys = useCallback (
21- ( keyTable : DhType . Table ) : Promise < ( readonly [ string , string ] ) [ ] > =>
23+ ( keyTable : DhType . Table ) : Promise < KeyColumnArray > =>
2224 new Promise ( ( resolve , reject ) => {
23- // TODO: use a util method to get the map
24- const pivotIdColumn = keyTable . findColumn ( '__PIVOT_COLUMN' ) ;
25+ const pivotIdColumn = keyTable . findColumn ( KEY_TABLE_PIVOT_COLUMN ) ;
2526 const columns = keyTable . columns . filter (
26- c => c . name !== '__PIVOT_COLUMN'
27+ c => c . name !== KEY_TABLE_PIVOT_COLUMN
2728 ) ;
2829 const subscription = keyTable . subscribe ( keyTable . columns ) ;
29- subscription . addEventListener < {
30- fullIndex : { iterator : ( ) => Iterator < DhType . Row > } ;
31- getData : ( rowKey : DhType . Row , column : DhType . Column ) => string ;
32- } > ( dh . Table . EVENT_UPDATED , e => {
33- const columnMap : ( readonly [ string , string ] ) [ ] = [ ] ;
34- const data = e . detail ;
35- const rowIter = data . fullIndex . iterator ( ) ;
36- while ( rowIter . hasNext ( ) ) {
37- const rowKey = rowIter . next ( ) . value ;
38- const value = [ ] ;
39- for ( let i = 0 ; i < columns . length ; i += 1 ) {
40- value . push ( data . getData ( rowKey , columns [ i ] ) ) ;
41- }
42- columnMap . push ( [
43- `PIVOT_C_${ data . getData ( rowKey , pivotIdColumn ) } ` ,
44- value . join ( ', ' ) ,
45- ] ) ;
30+ subscription . addEventListener < KeyTableSubscriptionData > (
31+ dh . Table . EVENT_UPDATED ,
32+ e => {
33+ subscription . close ( ) ;
34+ resolve ( getSimplePivotColumnMap ( e . detail , columns , pivotIdColumn ) ) ;
4635 }
47- log . debug ( 'Column map' , columnMap ) ;
48- subscription . close ( ) ;
49- // TODO: set column map in the model
50- resolve ( columnMap ) ;
51- } ) ;
36+ ) ;
5237 } ) ,
5338 [ dh ]
5439 ) ;
0 commit comments