File tree Expand file tree Collapse file tree 7 files changed +94
-84
lines changed
Expand file tree Collapse file tree 7 files changed +94
-84
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,10 @@ import { IrisGrid } from '@deephaven/iris-grid';
44import { LoadingOverlay } from '@deephaven/components' ;
55import { getErrorMessage } from '@deephaven/utils' ;
66import { useIrisGridPivotModel } from './useIrisGridPivotModel' ;
7- import {
8- usePivotTableFetch ,
9- usePivotMouseHandlers ,
10- usePivotRenderer ,
11- usePivotTheme ,
12- } from './usePivotTableUtils' ;
7+ import { usePivotTableFetch } from './hooks/usePivotTableFetch' ;
8+ import { usePivotMouseHandlers } from './hooks/usePivotMouseHandlers' ;
9+ import { usePivotRenderer } from './hooks/usePivotRenderer' ;
10+ import { usePivotTheme } from './hooks/usePivotTheme' ;
1311
1412export function PivotWidget ( {
1513 fetch,
Original file line number Diff line number Diff line change 1+ import { useMemo } from 'react' ;
2+ import type { MouseHandlersProp } from '@deephaven/iris-grid' ;
3+ import PivotColumnGroupMouseHandler from '../PivotColumnGroupMouseHandler' ;
4+ import PivotSortMouseHandler from '../PivotSortMouseHandler' ;
5+
6+ /**
7+ * Hook that creates mouse handlers for pivot grids
8+ * @returns Mouse handlers array
9+ */
10+ export function usePivotMouseHandlers ( ) : MouseHandlersProp {
11+ return useMemo (
12+ ( ) => [
13+ irisGrid => new PivotColumnGroupMouseHandler ( irisGrid ) ,
14+ irisGrid => new PivotSortMouseHandler ( irisGrid ) ,
15+ ] ,
16+ [ ]
17+ ) ;
18+ }
19+
20+ export default usePivotMouseHandlers ;
Original file line number Diff line number Diff line change 1+ import { useMemo } from 'react' ;
2+ import IrisGridPivotRenderer from '../IrisGridPivotRenderer' ;
3+
4+ /**
5+ * Hook that creates a pivot grid renderer
6+ * @returns Pivot grid renderer
7+ */
8+ export function usePivotRenderer ( ) : IrisGridPivotRenderer {
9+ return useMemo ( ( ) => new IrisGridPivotRenderer ( ) , [ ] ) ;
10+ }
11+
12+ export default usePivotRenderer ;
Original file line number Diff line number Diff line change 1+ import { useCallback } from 'react' ;
2+ import { useApi } from '@deephaven/jsapi-bootstrap' ;
3+ import type { dh } from '@deephaven-enterprise/jsapi-coreplus-types' ;
4+ import Log from '@deephaven/log' ;
5+ import { isCorePlusDh } from '../PivotUtils' ;
6+
7+ const log = Log . module ( '@deephaven/js-plugin-pivot/usePivotTableFetch' ) ;
8+
9+ /**
10+ * Hook that creates a pivot table from a widget fetch function
11+ * @param fetch Function to fetch the widget
12+ * @returns Function that fetches and creates the pivot table
13+ */
14+ export function usePivotTableFetch (
15+ fetch : ( ) => Promise < dh . Widget >
16+ ) : ( ) => Promise < dh . coreplus . pivot . PivotTable > {
17+ const api = useApi ( ) ;
18+
19+ return useCallback (
20+ ( ) =>
21+ fetch ( ) . then ( widget => {
22+ log . debug ( 'Pivot fetch result:' , widget ) ;
23+ if ( ! isCorePlusDh ( api ) ) {
24+ throw new Error ( 'CorePlus is not available' ) ;
25+ }
26+ const pivotTable = new api . coreplus . pivot . PivotTable ( widget ) ;
27+ log . debug ( 'Created pivot table:' , pivotTable ) ;
28+ return pivotTable ;
29+ } ) ,
30+ [ api , fetch ]
31+ ) ;
32+ }
33+
34+ export default usePivotTableFetch ;
Original file line number Diff line number Diff line change 1+ import { useMemo } from 'react' ;
2+ import { useTheme } from '@deephaven/components' ;
3+ import Log from '@deephaven/log' ;
4+ import { getIrisGridPivotTheme } from '../IrisGridPivotTheme' ;
5+
6+ const log = Log . module ( '@deephaven/js-plugin-pivot/usePivotTheme' ) ;
7+
8+ /**
9+ * Hook that gets the pivot theme based on current theme
10+ * @returns Pivot theme
11+ */
12+ export function usePivotTheme ( ) : ReturnType < typeof getIrisGridPivotTheme > {
13+ const theme = useTheme ( ) ;
14+
15+ return useMemo ( ( ) => {
16+ log . debug ( 'Theme changed, updating pivot theme' , theme ) ;
17+ return getIrisGridPivotTheme ( ) ;
18+ } , [ theme ] ) ;
19+ }
20+
21+ export default usePivotTheme ;
Original file line number Diff line number Diff line change @@ -8,11 +8,9 @@ import { assertNotNull } from '@deephaven/utils';
88import Log from '@deephaven/log' ;
99import IrisGridPivotModel from './IrisGridPivotModel' ;
1010import { isCorePlusDh } from './PivotUtils' ;
11- import {
12- usePivotMouseHandlers ,
13- usePivotRenderer ,
14- usePivotTheme ,
15- } from './usePivotTableUtils' ;
11+ import { usePivotMouseHandlers } from './hooks/usePivotMouseHandlers' ;
12+ import { usePivotRenderer } from './hooks/usePivotRenderer' ;
13+ import { usePivotTheme } from './hooks/usePivotTheme' ;
1614
1715const log = Log . module ( '@deephaven/js-plugin-pivot/useHydratePivotGrid' ) ;
1816
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments