Skip to content

Commit

Permalink
fix: ui.table cell and row press event data can be wrong (#593)
Browse files Browse the repository at this point in the history
Fixes #529 

Based on refactor PR which drops the index from the callback #592. Need
to rebase and drop the 1st 2 commits after that merges
  • Loading branch information
mattrunyon authored Jul 5, 2024
1 parent be97ad8 commit c4a2fe7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions plugins/ui/src/js/src/elements/UITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function UITable({
? ([
new UITableMouseHandler(
model,
irisGrid,
onCellPress,
onCellDoublePress,
onColumnPress,
Expand Down
55 changes: 37 additions & 18 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,11 @@ import {
GridPoint,
isExpandableGridModel,
} from '@deephaven/grid';
import { IrisGridModel, RowIndex } from '@deephaven/iris-grid';
import {
IrisGridModel,
type IrisGridType,
RowIndex,
} from '@deephaven/iris-grid';
import {
CellData,
ColumnIndex,
Expand Down Expand Up @@ -61,6 +65,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 +81,7 @@ class UITableMouseHandler extends GridMouseHandler {

constructor(
model: IrisGridModel,
irisGrid: IrisGridType,
onCellPress: UITableProps['onCellPress'],
onCellDoublePress: UITableProps['onCellDoublePress'],
onColumnPress: UITableProps['onColumnPress'],
Expand All @@ -84,6 +91,7 @@ class UITableMouseHandler extends GridMouseHandler {
) {
super(890);
this.model = model;
this.irisGrid = irisGrid;
this.onCellPress = onCellPress;
this.onCellDoublePress = onCellDoublePress;
this.onColumnPress = onColumnPress;
Expand All @@ -93,38 +101,49 @@ class UITableMouseHandler extends GridMouseHandler {
}

onClick(gridPoint: GridPoint): EventHandlerResult {
const { column, row } = gridPoint;
const { model, onCellPress, onRowPress, onColumnPress } = this;
const { column: visibleColumn, row: visibleRow } = gridPoint;
const { model, irisGrid, onCellPress, onRowPress, onColumnPress } = this;

if (onCellPress != null && column != null && row != null) {
const cellData = getCellData(column, row, model);
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);
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;
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 && column != null && row != null) {
const cellData = getCellData(column, row, model);
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);
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;
}
Expand Down

0 comments on commit c4a2fe7

Please sign in to comment.