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

fix: keep manually entered value in GoToRow when changing to same column type #1743

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions packages/iris-grid/src/GotoRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ const GotoRow = forwardRef<GotoRowElement, GotoRowProps>(
}}
value={gotoValueSelectedColumnName}
aria-label="column-name-select"
id="column-name-select"
>
{columns.map(column => (
<option key={column.name} value={column.name}>
Expand Down
33 changes: 27 additions & 6 deletions packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export interface IrisGridState {

gotoValueSelectedColumnName: ColumnName;
gotoValueSelectedFilter: FilterTypeValue;
goToValueManuallyChanged: boolean;
wusteven815 marked this conversation as resolved.
Show resolved Hide resolved
gotoValue: string;

columnHeaderGroups: readonly ColumnHeaderGroup[];
Expand Down Expand Up @@ -851,6 +852,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
gotoValueSelectedColumnName: model.columns[0]?.name ?? '',
gotoValueSelectedFilter: FilterType.eqIgnoreCase,
gotoValue: '',
goToValueManuallyChanged: false,
columnHeaderGroups: columnHeaderGroups ?? model.initialColumnHeaderGroups,
};
}
Expand Down Expand Up @@ -3935,20 +3937,39 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
handleGotoValueSelectedColumnNameChanged(columnName: ColumnName): void {
const { model } = this.props;
const cursorRow = this.grid?.state.cursorRow;
const {
gotoValueSelectedColumnName: prevColumnName,
goToValueManuallyChanged,
} = this.state;

if (cursorRow != null) {
const index = model.getColumnIndexByName(columnName);
const column = IrisGridUtils.getColumnByName(model.columns, columnName);
const prevColumn = IrisGridUtils.getColumnByName(
model.columns,
prevColumnName
);
if (index == null || column == null) {
return;
}
const value = model.valueForCell(index, cursorRow);
const text = IrisGridUtils.convertValueToText(value, column.type);
this.setState({
gotoValueSelectedColumnName: columnName,
gotoValue: text,
gotoValueError: '',
});

// do NOT update value if user manually changed value AND column type remains the same
if (goToValueManuallyChanged && column.type === prevColumn?.type) {
this.setState({
gotoValueSelectedColumnName: columnName,
gotoValueError: '',
});
} else {
// do update, and set goToValueManuallyChanged to false because value was automatically changed
this.setState({
gotoValueSelectedColumnName: columnName,
gotoValue: text,
gotoValueError: '',
goToValueManuallyChanged: false,
});
}
}
this.setState({
gotoValueSelectedColumnName: columnName,
Expand All @@ -3961,7 +3982,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
}

handleGotoValueChanged = (input: string): void => {
this.setState({ gotoValue: input });
this.setState({ gotoValue: input, goToValueManuallyChanged: true });
this.debouncedSeekRow(input);
};

Expand Down
150 changes: 150 additions & 0 deletions tests/table-gotorow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { test, expect, Page } from '@playwright/test';
import { pasteInMonaco } from './utils';

const customTableCommand = `
from deephaven import empty_table

size = 20

ordered_int_and_offset = empty_table(20).update([
"MyString=(\`str\`+i)",
"MyInt1=(i+100)",
"MyInt2=(i+200)",
])`;

async function setColumnAndExpectInputValue({
page,
setInputValueTo,
setColumnNameTo,
expectInputValueToBe,
}: {
page: Page;
setInputValueTo?: string;
setColumnNameTo: string;
expectInputValueToBe: string;
}) {
if (setInputValueTo !== undefined) {
const inputValue = page.locator('input[aria-label="Value Input"]');
await expect(inputValue).toHaveCount(1);
await inputValue.fill(setInputValueTo);
await page.waitForTimeout(300);
}

const columnSelect = page.locator('#column-name-select');
await expect(columnSelect).toHaveCount(1);
await columnSelect.selectOption(setColumnNameTo);

const inputValue = page.locator('input[aria-label="Value Input"]');
await expect(inputValue).toHaveCount(1);
await expect(inputValue).toHaveValue(expectInputValueToBe);
}

async function waitForLoadingDone(page: Page) {
await expect(
page.locator('.iris-grid .iris-grid-loading-status')
).toHaveCount(0);
}

test.describe.configure({ mode: 'serial' });

test.describe('GoToRow change column', () => {
let page: Page;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await page.goto('');
await waitForLoadingDone(page);

// create the table
const consoleInput = page.locator('.console-input');
await pasteInMonaco(consoleInput, customTableCommand);
await page.keyboard.press('Enter');

// wait for panel to show and finish loading
await expect(page.locator('.iris-grid-panel')).toHaveCount(1);
await expect(page.locator('.iris-grid-panel .loading-spinner')).toHaveCount(
0
);

// get the grid
const grid = await page.locator('.iris-grid-panel .iris-grid');
await waitForLoadingDone(page);
const gridLocation = await grid.boundingBox();
expect(gridLocation).not.toBeNull();
if (gridLocation === null) return;
// activate GoToRow
const columnHeaderHeight = 30;
await page.mouse.click(
gridLocation.x + 1,
gridLocation.y + 1 + columnHeaderHeight
);
await page.keyboard.down('Control');
await page.keyboard.press('g');
await page.keyboard.up('Control');

// wait for GoToRow bar to show
await expect(page.locator('.iris-grid-bottom-bar')).toHaveCount(1);
});

test('unmodified value, different column type', async () => {
await setColumnAndExpectInputValue({
page,
setColumnNameTo: 'MyInt1',
expectInputValueToBe: '100',
});
await setColumnAndExpectInputValue({
page,
setColumnNameTo: 'MyString',
expectInputValueToBe: 'str0',
});
});

test('modified set value, different column type', async () => {
await setColumnAndExpectInputValue({
page,
setInputValueTo: 'str5',
setColumnNameTo: 'MyInt1',
expectInputValueToBe: '105',
});
await setColumnAndExpectInputValue({
page,
setInputValueTo: '110',
setColumnNameTo: 'MyString',
expectInputValueToBe: 'str10',
});
});

test('unmodified set value, same column type', async () => {
// set to int1 first (from string)
await setColumnAndExpectInputValue({
page,
setColumnNameTo: 'MyInt1',
expectInputValueToBe: '110',
});
await setColumnAndExpectInputValue({
page,
setColumnNameTo: 'MyInt2',
expectInputValueToBe: '210',
});
await setColumnAndExpectInputValue({
page,
setColumnNameTo: 'MyInt1',
expectInputValueToBe: '110',
});
});

test('modified set value, same column type', async () => {
await setColumnAndExpectInputValue({
page,
setInputValueTo: '115',
setColumnNameTo: 'MyInt2',
expectInputValueToBe: '115',
});
await setColumnAndExpectInputValue({
page,
setInputValueTo: '216',
setColumnNameTo: 'MyInt1',
expectInputValueToBe: '216',
});
});
});
Loading