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: Goto Value Skips Rows on String Column, Displays Incorrect Filter, and shift+enter Doesn't go to Previous #1162

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 21 additions & 1 deletion packages/components/src/DateTimeInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ const F = '\u2007';
function makeDateTimeInput({
value = DEFAULT_DATE_TIME,
onChange = jest.fn(),
onSubmit = jest.fn(),
} = {}) {
return render(<DateTimeInput defaultValue={value} onChange={onChange} />);
return render(
<DateTimeInput
defaultValue={value}
onChange={onChange}
onSubmit={onSubmit}
/>
);
}

it('mounts and unmounts properly', () => {
Expand Down Expand Up @@ -139,3 +146,16 @@ describe('addSeparators', () => {
expect(addSeparators('2022-02-22')).toBe(`2022-02-22`);
});
});

it('onSubmit works correctly', async () => {
const onSubmit = jest.fn();
const { unmount } = makeDateTimeInput({
value: '2022-02-22 00:00:00.000',
onSubmit,
});
const input: HTMLInputElement = screen.getByRole('textbox');
const user = userEvent.setup();
await user.type(input, '{enter}');
expect(onSubmit).toBeCalledTimes(1);
unmount();
});
11 changes: 10 additions & 1 deletion packages/components/src/DateTimeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react';
import React, { KeyboardEvent, useCallback, useState } from 'react';
import classNames from 'classnames';
import Log from '@deephaven/log';
import MaskedInput, { SelectionSegment } from './MaskedInput';
Expand All @@ -24,6 +24,7 @@ type DateTimeInputProps = {
defaultValue?: string;
onFocus?(): void;
onBlur?(): void;
onSubmit?(event?: KeyboardEvent<HTMLInputElement>): void;
'data-testid'?: string;
};

Expand All @@ -50,13 +51,20 @@ const DateTimeInput = React.forwardRef<HTMLInputElement, DateTimeInputProps>(
defaultValue = '',
onFocus = () => undefined,
onBlur = () => undefined,
onSubmit,
'data-testid': dataTestId,
} = props;
const [value, setValue] = useState(
defaultValue.length > 0 ? addSeparators(defaultValue) : ''
);
const [selection, setSelection] = useState<SelectionSegment>();

const handleSubmit = useCallback(
Zhou-Ziheng marked this conversation as resolved.
Show resolved Hide resolved
(event: KeyboardEvent<HTMLInputElement>): void => {
onSubmit?.(event);
},
[onSubmit]
);
const handleChange = useCallback(
(newValue: string): void => {
log.debug('handleChange', newValue);
Expand Down Expand Up @@ -86,6 +94,7 @@ const DateTimeInput = React.forwardRef<HTMLInputElement, DateTimeInputProps>(
getNextSegmentValue={getNextSegmentValue}
onChange={handleChange}
onSelect={setSelection}
onSubmit={handleSubmit}
pattern={FULL_DATE_PATTERN}
placeholder={FULL_DATE_FORMAT}
selection={selection}
Expand Down
21 changes: 19 additions & 2 deletions packages/components/src/MaskedInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MaskedInput from './MaskedInput';
import { fillToLength, trimTrailingMask } from './MaskedInputUtils';

Expand All @@ -9,12 +10,28 @@ function makeMaskedInput({
value = '00:00:00',
pattern = TIME_PATTERN,
example = '12:34:56',
onSubmit = jest.fn(),
} = {}) {
return render(
<MaskedInput value={value} pattern={pattern} example={example} />
<MaskedInput
value={value}
pattern={pattern}
example={example}
onSubmit={onSubmit}
/>
);
}

it('mounts and unmounts properly', async () => {
Zhou-Ziheng marked this conversation as resolved.
Show resolved Hide resolved
const onSubmit = jest.fn();
const { unmount } = makeMaskedInput({ onSubmit });
const input: HTMLInputElement = screen.getByRole('textbox');
const user = userEvent.setup();
await user.type(input, '{enter}');
expect(onSubmit).toBeCalledTimes(1);
unmount();
});

it('mounts and unmounts properly', () => {
const { unmount } = makeMaskedInput();
unmount();
Expand Down
9 changes: 7 additions & 2 deletions packages/components/src/MaskedInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useEffect, useCallback } from 'react';
import React, { useMemo, useEffect, useCallback, KeyboardEvent } from 'react';
import classNames from 'classnames';
import Log from '@deephaven/log';
import { useForwardedRef } from '@deephaven/react-hooks';
Expand Down Expand Up @@ -46,6 +46,8 @@ type MaskedInputProps = {
onChange?(value: string): void;
/** Called when selection changes */
onSelect?(segment: SelectionSegment): void;
/** Called when enter is pressed */
onSubmit?(event?: KeyboardEvent<HTMLInputElement>): void;
/** Retrieve the next value for a provided segment */
getNextSegmentValue?(
segment: SelectionSegment,
Expand Down Expand Up @@ -82,6 +84,7 @@ const MaskedInput = React.forwardRef<HTMLInputElement, MaskedInputProps>(
getPreferredReplacementString = DEFAULT_GET_PREFERRED_REPLACEMENT_STRING,
onChange = () => false,
onSelect = () => false,
onSubmit,
pattern,
placeholder,
selection,
Expand Down Expand Up @@ -386,7 +389,9 @@ const MaskedInput = React.forwardRef<HTMLInputElement, MaskedInputProps>(
);
return;
}

if (key === 'Enter') {
onSubmit?.(event);
Zhou-Ziheng marked this conversation as resolved.
Show resolved Hide resolved
}
if (key.startsWith('Arrow')) {
handleArrowKey(event);
return;
Expand Down
5 changes: 5 additions & 0 deletions packages/iris-grid/src/GotoRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface GotoRowProps {

gotoValueSelectedColumnName: ColumnName;
gotoValue: string;
gotoValueFilter: FilterTypeValue;
onGotoValueSelectedColumnNameChanged: (columnName: ColumnName) => void;
onGotoValueSelectedFilterChanged: (filter: FilterTypeValue) => void;
onGotoValueChanged: (input: string) => void;
Expand All @@ -67,6 +68,7 @@ function GotoRow({
onClose,
gotoValueSelectedColumnName,
gotoValue,
gotoValueFilter,
onGotoValueSelectedColumnNameChanged,
onGotoValueSelectedFilterChanged,
onGotoValueChanged,
Expand Down Expand Up @@ -163,6 +165,7 @@ function GotoRow({
return (
<div className="goto-value-date-time-input">
<DateTimeInput
ref={gotoValueInputRef}
className={classNames(
'form-control',
'goto-value-date-time-input',
Expand All @@ -172,6 +175,7 @@ function GotoRow({
)}
defaultValue={gotoValue}
onChange={onGotoValueInputChanged}
onSubmit={handleGotoValueKeyDown}
/>
</div>
);
Expand All @@ -186,6 +190,7 @@ function GotoRow({
event.target.value as FilterTypeValue
);
}}
value={gotoValueFilter}
>
<option key={FilterType.eq} value={FilterType.eq}>
Equals
Expand Down
6 changes: 4 additions & 2 deletions packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3336,7 +3336,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
case TableUtils.dataType.CHAR:
case TableUtils.dataType.STRING: {
rowIndex = await model.seekRow(
isBackwards === true ? searchFromRow - 1 : searchFromRow + 1,
searchFromRow,
selectedColumn,
dh.ValueType.STRING,
inputString,
Expand All @@ -3352,7 +3352,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
formatter.timeZone
);
rowIndex = await model.seekRow(
isBackwards === true ? searchFromRow - 1 : searchFromRow + 1,
searchFromRow,
selectedColumn,
dh.ValueType.DATETIME,
startDate,
Expand Down Expand Up @@ -3930,6 +3930,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
gotoValueError,
gotoValueSelectedColumnName,
gotoValue,
gotoValueSelectedFilter,
} = this.state;
if (!isReady) {
return null;
Expand Down Expand Up @@ -4557,6 +4558,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
onExited={this.handleAnimationEnd}
gotoValueSelectedColumnName={gotoValueSelectedColumnName}
gotoValue={gotoValue}
gotoValueFilter={gotoValueSelectedFilter}
onGotoValueSelectedColumnNameChanged={
this.handleGotoValueSelectedColumnNameChanged
}
Expand Down