diff --git a/packages/grid/src/mouse-handlers/GridSelectionMouseHandler.ts b/packages/grid/src/mouse-handlers/GridSelectionMouseHandler.ts index f36ac3393..1a5ce5f4b 100644 --- a/packages/grid/src/mouse-handlers/GridSelectionMouseHandler.ts +++ b/packages/grid/src/mouse-handlers/GridSelectionMouseHandler.ts @@ -214,6 +214,24 @@ class GridSelectionMouseHandler extends GridMouseHandler { return false; } + // eslint-disable-next-line class-methods-use-this + onDoubleClick( + gridPoint: GridPoint, + grid: Grid, + event: GridMouseEvent + ): EventHandlerResult { + const { column, row } = gridPoint; + if (row == null || column == null) { + return false; + } + + grid.clearSelectedRanges(); + grid.moveCursorToPosition(column, row); + grid.commitSelection(); + + return true; + } + onContextMenu( gridPoint: GridPoint, grid: Grid, diff --git a/packages/iris-grid/src/IrisGrid.tsx b/packages/iris-grid/src/IrisGrid.tsx index 69c4bedbc..c0146b995 100644 --- a/packages/iris-grid/src/IrisGrid.tsx +++ b/packages/iris-grid/src/IrisGrid.tsx @@ -282,7 +282,7 @@ export interface IrisGridProps { onCreateChart: (settings: ChartBuilderSettings, model: IrisGridModel) => void; onColumnSelected: (column: DhType.Column) => void; onError: (error: unknown) => void; - onDataSelected: (index: ModelIndex, map: Record) => void; + onDataSelected: (index: ModelIndex, map: RowDataMap) => void; onStateChange: (irisGridState: IrisGridState, gridState: GridState) => void; onAdvancedSettingsChange: AdvancedSettingsMenuCallback; @@ -341,6 +341,10 @@ export interface IrisGridProps { canToggleSearch: boolean; columnHeaderGroups?: readonly ColumnHeaderGroup[]; + + // Optional key and mouse handlers + keyHandlers: readonly KeyHandler[]; + mouseHandlers: readonly GridMouseHandler[]; } export interface IrisGridState { @@ -349,8 +353,6 @@ export interface IrisGridState { focusedFilterBarColumn: number | null; metricCalculator: IrisGridMetricCalculator; metrics?: GridMetrics; - keyHandlers: readonly KeyHandler[]; - mouseHandlers: readonly GridMouseHandler[]; partitionConfig?: PartitionConfig; @@ -519,6 +521,8 @@ class IrisGrid extends Component { frozenColumns: null, theme: null, canToggleSearch: true, + mouseHandlers: EMPTY_ARRAY, + keyHandlers: EMPTY_ARRAY, }; constructor(props: IrisGridProps) { @@ -754,14 +758,15 @@ class IrisGrid extends Component { this.tableUtils = new TableUtils(dh); + this.mouseHandlers = mouseHandlers; + this.keyHandlers = keyHandlers; + this.state = { isFilterBarShown, isSelectingPartition, focusedFilterBarColumn: null, metricCalculator, metrics: undefined, - keyHandlers, - mouseHandlers, partitionConfig: partitionConfig ?? @@ -1032,6 +1037,10 @@ class IrisGrid extends Component { tableUtils: TableUtils; + keyHandlers: readonly KeyHandler[]; + + mouseHandlers: readonly GridMouseHandler[]; + get gridWrapper(): HTMLDivElement | null { return this.grid?.canvasWrapper.current ?? null; } @@ -1394,6 +1403,26 @@ class IrisGrid extends Component { { max: 1 } ); + getCachedKeyHandlers = memoize((keyHandlers: readonly KeyHandler[]) => + [...keyHandlers, ...this.keyHandlers].sort((a, b) => a.order - b.order) + ); + + getKeyHandlers(): readonly KeyHandler[] { + const { keyHandlers } = this.props; + return this.getCachedKeyHandlers(keyHandlers); + } + + getCachedMouseHandlers = memoize( + ( + mouseHandlers: readonly GridMouseHandler[] + ): readonly GridMouseHandler[] => [...mouseHandlers, ...this.mouseHandlers] + ); + + getMouseHandlers(): readonly GridMouseHandler[] { + const { mouseHandlers } = this.props; + return this.getCachedMouseHandlers(mouseHandlers); + } + getValueForCell( columnIndex: GridRangeIndex, rowIndex: GridRangeIndex, @@ -2723,9 +2752,20 @@ class IrisGrid extends Component { } /** - * Select all the data for a given row and notify listener + * Get the row data map for a given row and notifies the listener */ selectData(columnIndex: ModelIndex, rowIndex: ModelIndex): void { + const dataMap = this.getRowDataMap(rowIndex); + const { onDataSelected } = this.props; + onDataSelected(rowIndex, dataMap); + } + + /** + * Get the data map for the given row + * @param rowIndex Row to get the data map for + * @returns Data map for the row + */ + getRowDataMap(rowIndex: ModelIndex): RowDataMap { const { model } = this.props; const { columns, groupedColumns } = model; const dataMap: RowDataMap = {}; @@ -2747,8 +2787,7 @@ class IrisGrid extends Component { visibleIndex, }; } - const { onDataSelected } = this.props; - onDataSelected(rowIndex, dataMap); + return dataMap; } handleAdvancedFilterChange( @@ -4042,8 +4081,6 @@ class IrisGrid extends Component { loadingText, loadingScrimProgress, loadingSpinnerShown, - keyHandlers, - mouseHandlers, shownColumnTooltip, hoverAdvancedFilter, shownAdvancedFilter, @@ -4615,8 +4652,8 @@ class IrisGrid extends Component { isStuckToRight={isStuckToRight} metricCalculator={metricCalculator} model={model} - keyHandlers={keyHandlers} - mouseHandlers={mouseHandlers} + keyHandlers={this.getKeyHandlers()} + mouseHandlers={this.getMouseHandlers()} movedColumns={movedColumns} movedRows={movedRows} onError={this.handleGridError} diff --git a/packages/iris-grid/src/mousehandlers/IrisGridDataSelectMouseHandler.ts b/packages/iris-grid/src/mousehandlers/IrisGridDataSelectMouseHandler.ts index e23c13989..7b1f8e9b0 100644 --- a/packages/iris-grid/src/mousehandlers/IrisGridDataSelectMouseHandler.ts +++ b/packages/iris-grid/src/mousehandlers/IrisGridDataSelectMouseHandler.ts @@ -12,7 +12,7 @@ import type IrisGrid from '../IrisGrid'; */ class IrisGridDataSelectMouseHandler extends GridMouseHandler { constructor(irisGrid: IrisGrid) { - super(); + super(880); this.irisGrid = irisGrid; } @@ -27,9 +27,7 @@ class IrisGridDataSelectMouseHandler extends GridMouseHandler { this.irisGrid.selectData(column, row); - grid.moveCursorToPosition(column, row); - - return true; + return false; } }