From c1cdb1454e6379deda948a9060b7cc0b9bd799af Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sat, 29 Jun 2024 00:53:56 -0500 Subject: [PATCH] fix: ui.table row press --- .../ui/src/deephaven/ui/components/table.py | 14 ++--- plugins/ui/src/deephaven/ui/types/types.py | 26 +------- plugins/ui/src/js/src/elements/UITable.tsx | 3 +- .../src/elements/utils/UITableMouseHandler.ts | 61 ++++++++++++------- .../js/src/elements/utils/UITableUtils.tsx | 12 ++-- 5 files changed, 53 insertions(+), 63 deletions(-) diff --git a/plugins/ui/src/deephaven/ui/components/table.py b/plugins/ui/src/deephaven/ui/components/table.py index f0dc911c9..41517079e 100644 --- a/plugins/ui/src/deephaven/ui/components/table.py +++ b/plugins/ui/src/deephaven/ui/components/table.py @@ -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. diff --git a/plugins/ui/src/deephaven/ui/types/types.py b/plugins/ui/src/deephaven/ui/types/types.py index d6c09967e..df60d2d04 100644 --- a/plugins/ui/src/deephaven/ui/types/types.py +++ b/plugins/ui/src/deephaven/ui/types/types.py @@ -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", diff --git a/plugins/ui/src/js/src/elements/UITable.tsx b/plugins/ui/src/js/src/elements/UITable.tsx index 89f0e397a..b351d0b17 100644 --- a/plugins/ui/src/js/src/elements/UITable.tsx +++ b/plugins/ui/src/js/src/elements/UITable.tsx @@ -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'; @@ -101,6 +101,7 @@ export function UITable({ ? ([ new UITableMouseHandler( model, + irisGrid, onCellPress, onCellDoublePress, onColumnPress, diff --git a/plugins/ui/src/js/src/elements/utils/UITableMouseHandler.ts b/plugins/ui/src/js/src/elements/utils/UITableMouseHandler.ts index f4a4d14cc..8212a3e5a 100644 --- a/plugins/ui/src/js/src/elements/utils/UITableMouseHandler.ts +++ b/plugins/ui/src/js/src/elements/utils/UITableMouseHandler.ts @@ -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, @@ -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']; @@ -75,6 +77,7 @@ class UITableMouseHandler extends GridMouseHandler { constructor( model: IrisGridModel, + irisGrid: IrisGridType, onCellPress: UITableProps['onCellPress'], onCellDoublePress: UITableProps['onCellDoublePress'], onColumnPress: UITableProps['onColumnPress'], @@ -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; @@ -93,36 +97,49 @@ 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); + const { column: visibleColumn, row: visibleRow } = gridPoint; + const { model, irisGrid, onCellPress, onRowPress, onColumnPress } = this; + + const modelColumn = irisGrid.getModelColumn(visibleColumn); + const modelRow = irisGrid.getModelRow(visibleRow); + + if (onCellPress != null && modelColumn != null && modelRow != null) { + const cellData = getCellData(modelColumn, modelRow, model); + onCellPress(cellData); } - if (onRowPress != null && row != null) { - const rowData = getRowDataMap(row, model); - onRowPress(row, rowData); + if (onRowPress != null && modelRow != null) { + const rowData = getRowDataMap(modelRow, model); + onRowPress(rowData); } - if (onColumnPress && column != null) { - onColumnPress(model.columns[column].name); + if (onColumnPress && modelColumn != null) { + onColumnPress(model.columns[modelColumn].name); } return false; } onDoubleClick(gridPoint: GridPoint): EventHandlerResult { - 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); + const { column: visibleColumn, row: visibleRow } = gridPoint; + const { + model, + irisGrid, + onCellDoublePress, + onRowDoublePress, + onColumnDoublePress, + } = this; + + const modelColumn = irisGrid.getModelColumn(visibleColumn); + const modelRow = irisGrid.getModelRow(visibleRow); + + if (onCellDoublePress != null && modelColumn != null && modelRow != null) { + const cellData = getCellData(modelColumn, modelRow, model); + onCellDoublePress(cellData); } - if (onRowDoublePress != null && row != null) { - const rowData = getRowDataMap(row, model); - onRowDoublePress(row, rowData); + if (onRowDoublePress != null && modelRow != null) { + const rowData = getRowDataMap(modelRow, model); + onRowDoublePress(rowData); } - if (onColumnDoublePress && column != null) { - onColumnDoublePress(model.columns[column].name); + if (onColumnDoublePress && modelColumn != null) { + onColumnDoublePress(model.columns[modelColumn].name); } return false; } diff --git a/plugins/ui/src/js/src/elements/utils/UITableUtils.tsx b/plugins/ui/src/js/src/elements/utils/UITableUtils.tsx index 45a18095b..3eb873357 100644 --- a/plugins/ui/src/js/src/elements/utils/UITableUtils.tsx +++ b/plugins/ui/src/js/src/elements/utils/UITableUtils.tsx @@ -3,7 +3,6 @@ import type { ColumnName, DehydratedSort, IrisGridContextMenuData, - RowIndex, } from '@deephaven/iris-grid'; import type { ContextAction, @@ -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[];