From 44817b0a6d46aaf059b254c697a62331ce66cbc5 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Thu, 11 Jan 2024 09:40:04 -0500 Subject: [PATCH 1/6] fix(GoToRow): changing column keeps manually entered value --- packages/iris-grid/src/IrisGrid.tsx | 33 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/iris-grid/src/IrisGrid.tsx b/packages/iris-grid/src/IrisGrid.tsx index 3d387c75d2..146f6938d0 100644 --- a/packages/iris-grid/src/IrisGrid.tsx +++ b/packages/iris-grid/src/IrisGrid.tsx @@ -437,6 +437,7 @@ export interface IrisGridState { gotoValueSelectedColumnName: ColumnName; gotoValueSelectedFilter: FilterTypeValue; + goToValueManuallyChanged: boolean; gotoValue: string; columnHeaderGroups: readonly ColumnHeaderGroup[]; @@ -844,6 +845,7 @@ export class IrisGrid extends Component { gotoValueSelectedColumnName: model.columns[0]?.name ?? '', gotoValueSelectedFilter: FilterType.eqIgnoreCase, gotoValue: '', + goToValueManuallyChanged: false, columnHeaderGroups: columnHeaderGroups ?? model.initialColumnHeaderGroups, }; } @@ -3943,20 +3945,39 @@ export class IrisGrid extends Component { 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, @@ -3969,7 +3990,7 @@ export class IrisGrid extends Component { } handleGotoValueChanged = (input: string): void => { - this.setState({ gotoValue: input }); + this.setState({ gotoValue: input, goToValueManuallyChanged: true }); this.debouncedSeekRow(input); }; From f33dbe5dc1208689f08c11404dcbbfa9af55eadb Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Mon, 15 Jan 2024 11:04:37 -0500 Subject: [PATCH 2/6] test(GoToRow): add changing column tests --- packages/iris-grid/src/GotoRow.tsx | 1 + tests/table-gotorow.spec.ts | 145 +++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 tests/table-gotorow.spec.ts diff --git a/packages/iris-grid/src/GotoRow.tsx b/packages/iris-grid/src/GotoRow.tsx index 6848d2b09f..6cd5ded240 100644 --- a/packages/iris-grid/src/GotoRow.tsx +++ b/packages/iris-grid/src/GotoRow.tsx @@ -372,6 +372,7 @@ const GotoRow = forwardRef( }} value={gotoValueSelectedColumnName} aria-label="column-name-select" + id="column-name-select" > {columns.map(column => (