Skip to content

Commit e748cd7

Browse files
authored
fix: Use isSortable flag to determine if colBy and rowBy sources are sortable (#1275)
Use isSortable flag to determine if colBy or rowBy source is sortable. Tested by running this query and clicking on rowBy/columnBy headers to sort - ``` from deephaven_enterprise.pivot.pivot_table import make_pivot from deephaven import agg t = db.historical_table("LearnDeephaven","StockQuotes") \ .where("Date=`2017-08-25`") # AskExchange and BidExchange are StringSet columns, not sortable pivot = make_pivot( t, [agg.avg(["Bid"])], ["USym", "AskExchange"], ["Exchange", "BidExchange"], ) ``` Split out the hooks file into separate files, based on a review comment from another PR.
1 parent acc3eb9 commit e748cd7

File tree

8 files changed

+96
-92
lines changed

8 files changed

+96
-92
lines changed

plugins/pivot/src/js/src/PivotUtils.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,12 @@ export function makeColumnFromSource(
245245
source: CorePlusDhType.coreplus.pivot.PivotSource,
246246
index: number
247247
): PivotDisplayColumn {
248-
const {
249-
name,
250-
type,
251-
// TODO: DH-21047
252-
// isSortable,
253-
description,
254-
} = source;
248+
const { name, type, isSortable, description } = source;
255249
return makeColumn({
256250
name,
257251
type,
258252
index,
259-
isSortable: true,
253+
isSortable,
260254
description,
261255
filter: source.filter.bind(source),
262256
sort: source.sort.bind(source),

plugins/pivot/src/js/src/PivotWidget.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import { IrisGrid } from '@deephaven/iris-grid';
44
import { LoadingOverlay } from '@deephaven/components';
55
import { getErrorMessage } from '@deephaven/utils';
66
import { 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

1412
export function PivotWidget({
1513
fetch,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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;

plugins/pivot/src/js/src/useHydratePivotGrid.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import { assertNotNull } from '@deephaven/utils';
88
import Log from '@deephaven/log';
99
import IrisGridPivotModel from './IrisGridPivotModel';
1010
import { 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

1715
const log = Log.module('@deephaven/js-plugin-pivot/useHydratePivotGrid');
1816

plugins/pivot/src/js/src/usePivotTableUtils.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)