Skip to content

Commit

Permalink
refactor: Remove row and colum indexes from table press handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrunyon committed Jun 29, 2024
1 parent 32d09e8 commit fd6a787
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 46 deletions.
14 changes: 6 additions & 8 deletions plugins/ui/src/deephaven/ui/components/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@ def table(
Args:
table: The table to wrap
on_row_press: The callback function to run when a row is clicked.
The first parameter is the row index, and the second is the visible row data provided in a dictionary where the
The callback is invoked with the visible row data provided in a dictionary where the
column names are the keys.
on_row_double_press: The callback function to run when a row is double clicked.
The first parameter is the row index, and the second is the visible row data provided in a dictionary where the
The callback is invoked with the visible row data provided in a dictionary where the
column names are the keys.
on_cell_press: The callback function to run when a cell is clicked.
The first parameter is the cell index, and the second is the cell data provided in a dictionary where the
column names are the keys.
The callback is invoked with the cell data.
on_cell_double_press: The callback function to run when a cell is double clicked.
The first parameter is the cell index, and the second is the cell data provided in a dictionary where the
column names are the keys.
The callback is invoked with the cell data.
on_column_press: The callback function to run when a column is clicked.
The first parameter is the column name.
The callback is invoked with the column name.
on_column_double_press: The callback function to run when a column is double clicked.
The first parameter is the column name.
The callback is invoked with the column name.
quick_filters: The quick filters to apply to the table. Dictionary of column name to filter value.
show_quick_filters: Whether to show the quick filter bar by default.
show_search: Whether to show the search bar by default.
Expand Down
26 changes: 2 additions & 24 deletions plugins/ui/src/deephaven/ui/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,32 +178,10 @@ class SliderChange(TypedDict):

SliderChangeCallable = Callable[[SliderChange], None]


ColumnIndex = int
"""
Index of a column in a table.
"""

RowIndex = int
"""
Index of a row in a table.
"""

CellIndex = Tuple[ColumnIndex, RowIndex]
"""
Index of a cell in a table.
"""

GridIndex = Tuple[Union[ColumnIndex, None], Union[RowIndex, None]]
"""
Index of a spot on the grid. A value of None indicates a header row or column.
"""


ColumnName = str
RowDataMap = Dict[str, Any]
RowPressCallback = Callable[[RowIndex, RowDataMap], None]
CellPressCallback = Callable[[CellIndex, CellData], None]
RowPressCallback = Callable[[RowDataMap], None]
CellPressCallback = Callable[[CellData], None]
ColumnPressCallback = Callable[[ColumnName], None]
AggregationOperation = Literal[
"COUNT",
Expand Down
3 changes: 2 additions & 1 deletion plugins/ui/src/js/src/elements/UITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { useSelector } from 'react-redux';
import {
DehydratedQuickFilter,
IrisGrid,
IrisGridType,
type IrisGridContextMenuData,
IrisGridModel,
IrisGridModelFactory,
IrisGridProps,
type IrisGridType,
IrisGridUtils,
} from '@deephaven/iris-grid';
import { useApi } from '@deephaven/jsapi-bootstrap';
Expand Down Expand Up @@ -101,6 +101,7 @@ export function UITable({
? ([
new UITableMouseHandler(
model,
irisGrid,
onCellPress,
onCellDoublePress,
onColumnPress,
Expand Down
16 changes: 11 additions & 5 deletions plugins/ui/src/js/src/elements/utils/UITableMouseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
GridPoint,
isExpandableGridModel,
} from '@deephaven/grid';
import { IrisGridModel, RowIndex } from '@deephaven/iris-grid';
import { IrisGridModel, IrisGridType, RowIndex } from '@deephaven/iris-grid';
import {
CellData,
ColumnIndex,
Expand Down Expand Up @@ -61,6 +61,8 @@ function getRowDataMap(rowIndex: RowIndex, model: IrisGridModel): RowDataMap {
class UITableMouseHandler extends GridMouseHandler {
private model: IrisGridModel;

private irisGrid: IrisGridType;

private onCellPress: UITableProps['onCellPress'];

private onCellDoublePress: UITableProps['onCellDoublePress'];
Expand All @@ -75,6 +77,7 @@ class UITableMouseHandler extends GridMouseHandler {

constructor(
model: IrisGridModel,
irisGrid: IrisGridType,
onCellPress: UITableProps['onCellPress'],
onCellDoublePress: UITableProps['onCellDoublePress'],
onColumnPress: UITableProps['onColumnPress'],
Expand All @@ -84,6 +87,7 @@ class UITableMouseHandler extends GridMouseHandler {
) {
super(890);
this.model = model;
this.irisGrid = irisGrid;
this.onCellPress = onCellPress;
this.onCellDoublePress = onCellDoublePress;
this.onColumnPress = onColumnPress;
Expand All @@ -95,13 +99,14 @@ class UITableMouseHandler extends GridMouseHandler {
onClick(gridPoint: GridPoint): EventHandlerResult {
const { column, row } = gridPoint;
const { model, onCellPress, onRowPress, onColumnPress } = this;

if (onCellPress != null && column != null && row != null) {
const cellData = getCellData(column, row, model);
onCellPress([column, row], cellData);
onCellPress(cellData);
}
if (onRowPress != null && row != null) {
const rowData = getRowDataMap(row, model);
onRowPress(row, rowData);
onRowPress(rowData);
}
if (onColumnPress && column != null) {
onColumnPress(model.columns[column].name);
Expand All @@ -113,13 +118,14 @@ class UITableMouseHandler extends GridMouseHandler {
const { column, row } = gridPoint;
const { model, onCellDoublePress, onRowDoublePress, onColumnDoublePress } =
this;

if (onCellDoublePress != null && column != null && row != null) {
const cellData = getCellData(column, row, model);
onCellDoublePress([column, row], cellData);
onCellDoublePress(cellData);
}
if (onRowDoublePress != null && row != null) {
const rowData = getRowDataMap(row, model);
onRowDoublePress(row, rowData);
onRowDoublePress(rowData);
}
if (onColumnDoublePress && column != null) {
onColumnDoublePress(model.columns[column].name);
Expand Down
12 changes: 4 additions & 8 deletions plugins/ui/src/js/src/elements/utils/UITableUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
ColumnName,
DehydratedSort,
IrisGridContextMenuData,
RowIndex,
} from '@deephaven/iris-grid';
import type {
ContextAction,
Expand Down Expand Up @@ -56,13 +55,10 @@ type ResolvableUIContextItem =

export interface UITableProps {
table: dh.WidgetExportedObject;
onCellPress?: (cellIndex: [ColumnIndex, RowIndex], data: CellData) => void;
onCellDoublePress?: (
cellIndex: [ColumnIndex, RowIndex],
data: CellData
) => void;
onRowPress?: (rowIndex: RowIndex, rowData: RowDataMap) => void;
onRowDoublePress?: (rowIndex: RowIndex, rowData: RowDataMap) => void;
onCellPress?: (data: CellData) => void;
onCellDoublePress?: (data: CellData) => void;
onRowPress?: (rowData: RowDataMap) => void;
onRowDoublePress?: (rowData: RowDataMap) => void;
onColumnPress?: (columnName: ColumnName) => void;
onColumnDoublePress?: (columnName: ColumnName) => void;
alwaysFetchColumns?: string[];
Expand Down

0 comments on commit fd6a787

Please sign in to comment.