Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiselect values #1736

Merged
merged 23 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
106bb5f
feat: add util to create logical normal forms
wusteven815 Jan 17, 2024
38fc9e5
feat: add not empty assert
wusteven815 Jan 17, 2024
66af19f
feat: multiselect rows in grid
wusteven815 Jan 17, 2024
eff26eb
feat: add missing empty string, fix texts
wusteven815 Jan 19, 2024
119a4f3
test: add multiselect tests
wusteven815 Jan 19, 2024
c5c9bdf
test: update multiselect snapshots
wusteven815 Jan 19, 2024
f91e6e6
test: add for non empty arrays
wusteven815 Jan 19, 2024
38d1b0c
fix(multiselect): non-selected right click won't use range
wusteven815 Jan 23, 2024
3cde604
test: add more multiselect tests
wusteven815 Jan 23, 2024
cf9c519
feat: right click changes selection
wusteven815 Jan 25, 2024
5ff2849
feat: change number filter behaviour and comments
wusteven815 Jan 25, 2024
d397a4f
test(multiselect): update for new string behaviour
wusteven815 Jan 25, 2024
4d5aaae
fix: only select on right click if row exists
wusteven815 Jan 25, 2024
6073a28
style: remove commented out code
wusteven815 Jan 31, 2024
3b6f923
style: remove commented out code
wusteven815 Jan 31, 2024
dbf9083
Merge branch 'deephaven:main' into feat-1233-multiselect
wusteven815 Jan 31, 2024
22f0d6d
refactor: use map/joins instead of makeLogicalNormalForm
wusteven815 Jan 31, 2024
df9db47
refactor: use contains cell helper function instead
wusteven815 Jan 31, 2024
cae022e
refactor: remove drag bounds, simplify selection
wusteven815 Jan 31, 2024
ac17b34
refactor: simplify truncating algorithm
wusteven815 Jan 31, 2024
5e97786
test: add unit test for right click behaviour
wusteven815 Feb 2, 2024
a47b9ff
Merge branch 'deephaven:main' into feat-1233-multiselect
wusteven815 Feb 2, 2024
15bca84
feat: assertion refactors
wusteven815 Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/grid/src/Grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,34 @@ function mouseClick(
mouseUp(column, row, component, extraMouseArgs, clientX, clientY);
}

function mouseRightClick(
column: VisibleIndex,
row: VisibleIndex,
component: Grid,
extraMouseArgs?: MouseEventInit,
clientX?: number,
clientY?: number
) {
mouseEvent(
column,
row,
component.handleContextMenu,
'mousedown',
extraMouseArgs,
clientX,
clientY
);
mouseEvent(
column,
row,
component.handleContextMenu,
'mouseup',
extraMouseArgs,
clientX,
clientY
);
}

function mouseDoubleClick(
column: VisibleIndex,
row: VisibleIndex,
Expand Down Expand Up @@ -334,6 +362,34 @@ it('ctrl clicking a selected cell should deselect it', () => {
expect(component.state.selectedRanges.length).toBe(0);
});

it('right click outside the range changes the selected ranges', () => {
const component = makeGridComponent();

mouseClick(3, 5, component);
mouseClick(3, 6, component, { ctrlKey: true });
expect(component.state.cursorColumn).toBe(3);
expect(component.state.cursorRow).toBe(6);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(3, 5, 3, 6));

mouseRightClick(5, 7, component);
expect(component.state.cursorColumn).toBe(5);
expect(component.state.cursorRow).toBe(7);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(5, 7, 5, 7));
});

it('right click inside the range keeps the selected ranges', () => {
const component = makeGridComponent();

mouseClick(3, 5, component);
mouseClick(3, 6, component, { ctrlKey: true });
expect(component.state.selectedRanges.length).toBe(1);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(3, 5, 3, 6));

mouseRightClick(3, 5, component);
expect(component.state.selectedRanges.length).toBe(1);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(3, 5, 3, 6));
});

it('handles mouse drag down to update selection', () => {
const component = makeGridComponent();
mouseDown(3, 5, component);
Expand Down
7 changes: 7 additions & 0 deletions packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class Grid extends PureComponent<GridProps, GridState> {
this.handleMouseUp = this.handleMouseUp.bind(this);
this.handleResize = this.handleResize.bind(this);
this.handleWheel = this.handleWheel.bind(this);
this.getSelectedRanges = this.getSelectedRanges.bind(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding this here is not strictly necessary, as getSelectedRanges isn't passed in anywhere. Should just be able to call grid.getSelectedRanges directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting TypeError: Cannot read properties of undefined (reading 'state') when I'm not binding it. I believe it's because the function is reading selectedRanges from this.state.


const {
isStuckToBottom,
Expand Down Expand Up @@ -976,6 +977,12 @@ class Grid extends PureComponent<GridProps, GridState> {
}
}

/** Gets the selected ranges */
getSelectedRanges(): readonly GridRange[] {
const { selectedRanges } = this.state;
return selectedRanges;
}

/**
* Begin a selection operation at the provided location
* @param column Column where the selection is beginning
Expand Down
30 changes: 25 additions & 5 deletions packages/grid/src/mouse-handlers/GridSelectionMouseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventHandlerResult } from '../EventHandlerResult';
import Grid from '../Grid';
import { BoxCoordinates } from '../GridMetrics';
import GridMouseHandler, { GridMouseEvent } from '../GridMouseHandler';
import GridRange from '../GridRange';
import GridUtils, { GridPoint } from '../GridUtils';

const DEFAULT_INTERVAL_MS = 100;
Expand All @@ -16,8 +16,6 @@ class GridSelectionMouseHandler extends GridMouseHandler {

private lastTriggerTime?: number;

private dragBounds?: BoxCoordinates;

onDown(
gridPoint: GridPoint,
grid: Grid,
Expand Down Expand Up @@ -68,7 +66,6 @@ class GridSelectionMouseHandler extends GridMouseHandler {

this.startPoint = gridPoint;
this.hasExtendedFloating = false;
this.dragBounds = GridUtils.getScrollDragBounds(metrics, row, column);

return true;
}
Expand Down Expand Up @@ -210,14 +207,37 @@ class GridSelectionMouseHandler extends GridMouseHandler {
onUp(gridPoint: GridPoint, grid: Grid): EventHandlerResult {
if (this.startPoint !== undefined) {
this.startPoint = undefined;
this.dragBounds = undefined;
this.stopTimer();
grid.commitSelection();
}

return false;
}

onContextMenu(
gridPoint: GridPoint,
grid: Grid,
event: GridMouseEvent
): EventHandlerResult {
// check if the selected is already in the selected range
const selectedRanges = grid.getSelectedRanges();
const isInRange = GridRange.containsCell(
selectedRanges,
gridPoint.column,
gridPoint.row
);

// only change the selected range if the selected cell is not in the selected range
if (!isInRange && gridPoint.row !== null) {
this.startPoint = undefined;
this.stopTimer();
grid.clearSelectedRanges();
grid.moveCursorToPosition(gridPoint.column, gridPoint.row);
}

return false;
}

moveSelection(
grid: Grid,
gridPoint: GridPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ $padding-x: 2rem;
overflow: hidden;
}

.iris-grid-filter-menu-subtitle {
color: $text-muted;
font-size: small;
}

.advanced-filter-button-container {
transition: $transition opacity;
}
Expand Down
Loading
Loading