Skip to content

Commit c37ef6b

Browse files
committed
PivotFilterMouseHandler
1 parent 8fd6ace commit c37ef6b

File tree

5 files changed

+71
-100
lines changed

5 files changed

+71
-100
lines changed

plugins/pivot/src/js/src/PivotFilterMouseHandler.ts

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import {
66
} from '@deephaven/grid';
77
import { IrisGridType as IrisGrid } from '@deephaven/iris-grid';
88
import Log from '@deephaven/log';
9+
import { getColumnSourceHeaderFromGridPoint } from './PivotMouseHandlerUtils';
910

1011
const log = Log.module('@deephaven/js-plugin-pivot/PivotFilterMouseHandler');
1112

1213
/**
13-
* Trigger quick filters and advanced filters
14+
* Trigger quick filters on pivot columnBy source headers
1415
*/
1516
class PivotFilterMouseHandler extends GridMouseHandler {
1617
constructor(irisGrid: IrisGrid) {
@@ -22,30 +23,23 @@ class PivotFilterMouseHandler extends GridMouseHandler {
2223
irisGrid: IrisGrid;
2324

2425
onDown(gridPoint: GridPoint): EventHandlerResult {
25-
const { x, y, column, row, columnHeaderDepth } = gridPoint;
26-
if (column != null && columnHeaderDepth != null && row === null) {
27-
const { isFilterBarShown, metrics } = this.irisGrid.state;
26+
const { model } = this.irisGrid.props;
27+
const { isFilterBarShown, metrics } = this.irisGrid.state;
28+
29+
const sourceIndex = getColumnSourceHeaderFromGridPoint(model, gridPoint);
30+
31+
log.debug('onDown', gridPoint, sourceIndex);
32+
33+
if (sourceIndex != null) {
2834
if (!metrics) throw new Error('Metrics not set');
2935

30-
const { columnHeaderMaxDepth } = metrics;
3136
const theme = this.irisGrid.getTheme();
32-
// TODO: check X
33-
const sourceIndex = -columnHeaderDepth;
34-
log.debug('onDown', {
35-
x,
36-
y,
37-
column,
38-
row,
39-
sourceIndex,
40-
columnHeaderMaxDepth,
41-
});
37+
4238
if (
4339
isFilterBarShown &&
4440
theme.columnHeaderHeight != null &&
45-
theme.filterBarHeight != null &&
46-
y > 0 &&
47-
y <= theme.columnHeaderHeight * columnHeaderMaxDepth &&
48-
column <= 3 // TODO: temporary limit until filter UI is done
41+
theme.filterBarHeight != null
42+
// TODO: check X and Y within the filter input box based on metrics
4943
) {
5044
this.irisGrid.focusFilterBar(sourceIndex);
5145
return true;
@@ -54,47 +48,6 @@ class PivotFilterMouseHandler extends GridMouseHandler {
5448

5549
return false;
5650
}
57-
58-
// onMove(gridPoint: GridPoint): EventHandlerResult {
59-
// const { y, column } = gridPoint;
60-
// const { isFilterBarShown, hoverAdvancedFilter, metrics } =
61-
// this.irisGrid.state;
62-
// if (!metrics) throw new Error('Metrics not set');
63-
// const { columnHeaderMaxDepth } = metrics;
64-
// const theme = this.irisGrid.getTheme();
65-
66-
// let newHoverAdvancedFilter = null;
67-
// if (
68-
// isFilterBarShown &&
69-
// theme.columnHeaderHeight != null &&
70-
// theme.filterBarHeight != null &&
71-
// column !== null &&
72-
// y > 0 &&
73-
// y <= theme.columnHeaderHeight * (columnHeaderMaxDepth - 1) &&
74-
// column <= 3 // TODO: temporary limit until filter UI is done
75-
// ) {
76-
// newHoverAdvancedFilter = column;
77-
// }
78-
79-
// console.log('[plugins] newHoverAdvancedFilter', newHoverAdvancedFilter);
80-
81-
// if (newHoverAdvancedFilter !== hoverAdvancedFilter) {
82-
// this.irisGrid.setState({ hoverAdvancedFilter: newHoverAdvancedFilter });
83-
// }
84-
85-
// // Stop propagation to block original onMove behavior
86-
// return true;
87-
// }
88-
89-
// onLeave(gridPoint: GridPoint): EventHandlerResult {
90-
// const { column } = gridPoint;
91-
// const { hoverAdvancedFilter } = this.irisGrid.state;
92-
// if (hoverAdvancedFilter !== null && column !== hoverAdvancedFilter) {
93-
// this.irisGrid.setState({ hoverAdvancedFilter: null });
94-
// }
95-
96-
// return false;
97-
// }
9851
}
9952

10053
export default PivotFilterMouseHandler;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-disable import/prefer-default-export */
2+
import type { GridPoint } from '@deephaven/grid';
3+
import type { IrisGridModel } from '@deephaven/iris-grid';
4+
import { isIrisGridPivotModel } from './IrisGridPivotModel';
5+
import { isPivotColumnHeaderGroup } from './PivotColumnHeaderGroup';
6+
7+
/**
8+
* Get the column source from a grid point
9+
* @param gridPoint The grid point to check
10+
* @returns The column source index if the grid point is in a column source header, else null
11+
*/
12+
export function getColumnSourceHeaderFromGridPoint(
13+
model: IrisGridModel,
14+
gridPoint: GridPoint
15+
): number | null {
16+
const { column, row, columnHeaderDepth } = gridPoint;
17+
const sourceIndex = columnHeaderDepth != null ? -columnHeaderDepth : null;
18+
19+
if (column == null || row !== null || columnHeaderDepth == null) {
20+
return null;
21+
}
22+
23+
const group = model.getColumnHeaderGroup(column, columnHeaderDepth);
24+
25+
if (
26+
sourceIndex != null &&
27+
sourceIndex < 0 &&
28+
isIrisGridPivotModel(model) &&
29+
model.isColumnSortable(sourceIndex) &&
30+
isPivotColumnHeaderGroup(group) &&
31+
group.isKeyColumnGroup
32+
) {
33+
// Clicked on a sortable column header that is a key column group
34+
return sourceIndex;
35+
}
36+
37+
return null;
38+
}

plugins/pivot/src/js/src/PivotSortMouseHandler.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
} from '@deephaven/grid';
99
import { IrisGridType as IrisGrid } from '@deephaven/iris-grid';
1010
import { assertNotNull } from '@deephaven/utils';
11-
import { isIrisGridPivotModel } from './IrisGridPivotModel';
12-
import { isPivotColumnHeaderGroup } from './PivotColumnHeaderGroup';
11+
import Log from '@deephaven/log';
12+
import { getColumnSourceHeaderFromGridPoint } from './PivotMouseHandlerUtils';
13+
14+
const log = Log.module('@deephaven/js-plugin-pivot/PivotSortMouseHandler');
1315

1416
/**
1517
* Trigger sorting on column source click.
@@ -27,47 +29,16 @@ class PivotSortMouseHandler extends GridMouseHandler {
2729

2830
irisGrid: IrisGrid;
2931

30-
/**
31-
* Get the column source from a grid point
32-
* @param gridPoint The grid point to check
33-
* @returns The column source index if the grid point is in a column source header, else null
34-
*/
35-
private getColumnSourceHeaderFromGridPoint(
36-
gridPoint: GridPoint
37-
): number | null {
38-
const { column, row, columnHeaderDepth } = gridPoint;
39-
const { model } = this.irisGrid.props;
40-
assertNotNull(model);
41-
const sourceIndex = columnHeaderDepth != null ? -columnHeaderDepth : null;
42-
43-
if (column == null || row !== null || columnHeaderDepth == null) {
44-
return null;
45-
}
46-
47-
const group = model.getColumnHeaderGroup(column, columnHeaderDepth);
48-
49-
if (
50-
sourceIndex != null &&
51-
sourceIndex < 0 &&
52-
isIrisGridPivotModel(model) &&
53-
model.isColumnSortable(sourceIndex) &&
54-
isPivotColumnHeaderGroup(group) &&
55-
group.isKeyColumnGroup
56-
) {
57-
// Clicked on a sortable column header that is a key column group
58-
return sourceIndex;
59-
}
60-
61-
return null;
62-
}
63-
6432
// We need to remember where the down started, because the canvas element will trigger a click where mouseUp is
6533
onDown(
6634
gridPoint: GridPoint,
6735
grid: Grid,
6836
event: GridMouseEvent
6937
): EventHandlerResult {
70-
this.columnSource = this.getColumnSourceHeaderFromGridPoint(gridPoint);
38+
const { model } = this.irisGrid.props;
39+
assertNotNull(model);
40+
this.columnSource = getColumnSourceHeaderFromGridPoint(model, gridPoint);
41+
log.debug('onDown', gridPoint, this.columnSource);
7142
return false;
7243
}
7344

@@ -76,7 +47,9 @@ class PivotSortMouseHandler extends GridMouseHandler {
7647
grid: Grid,
7748
event: GridMouseEvent
7849
): EventHandlerResult {
79-
const columnSource = this.getColumnSourceHeaderFromGridPoint(gridPoint);
50+
const { model } = this.irisGrid.props;
51+
assertNotNull(model);
52+
const columnSource = getColumnSourceHeaderFromGridPoint(model, gridPoint);
8053

8154
if (columnSource != null && columnSource === this.columnSource) {
8255
const addToExisting = ContextActionUtils.isModifierKeyDown(event);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { DisplayColumn } from '@deephaven/iris-grid';
1+
import { DisplayColumn, type IrisGridModel } from '@deephaven/iris-grid';
22
import { type dh as DhType } from '@deephaven/jsapi-types';
33
import { type dh as CorePlusDhType } from '@deephaven-enterprise/jsapi-coreplus-types';
4-
import PivotColumnHeaderGroup from './PivotColumnHeaderGroup';
4+
import PivotColumnHeaderGroup, {
5+
isPivotColumnHeaderGroup,
6+
} from './PivotColumnHeaderGroup';
7+
import type { GridPoint } from '@deephaven/grid';
8+
import { isIrisGridPivotModel } from './IrisGridPivotModel';
59

610
export function isCorePlusDh(
711
dh: typeof DhType | typeof CorePlusDhType

plugins/pivot/src/js/src/hooks/usePivotMouseHandlers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useMemo } from 'react';
22
import type { MouseHandlersProp } from '@deephaven/iris-grid';
33
import PivotColumnGroupMouseHandler from '../PivotColumnGroupMouseHandler';
44
import PivotSortMouseHandler from '../PivotSortMouseHandler';
5+
import PivotFilterMouseHandler from '../PivotFilterMouseHandler';
56

67
/**
78
* Hook that creates mouse handlers for pivot grids
@@ -11,6 +12,8 @@ export function usePivotMouseHandlers(): MouseHandlersProp {
1112
return useMemo(
1213
() => [
1314
irisGrid => new PivotColumnGroupMouseHandler(irisGrid),
15+
// Filter handler should consume events before sort
16+
irisGrid => new PivotFilterMouseHandler(irisGrid),
1417
irisGrid => new PivotSortMouseHandler(irisGrid),
1518
],
1619
[]

0 commit comments

Comments
 (0)