From d2b82b84c737a5c712a89e8e3d2b103b73591f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Sadzi=C5=84ski?= Date: Tue, 8 Mar 2022 15:00:21 +0100 Subject: [PATCH] (core) Fixing bug with resuming search on a hidden column. Summary: Fix for error that happens when a search is resumed after one of the columns was hidden. Test Plan: Added test that shows the error. Reviewers: alexmojaki Reviewed By: alexmojaki Subscribers: alexmojaki Differential Revision: https://phab.getgrist.com/D3309 --- app/client/models/SearchModel.ts | 18 ++++++++++---- test/nbrowser/gristUtils.ts | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/client/models/SearchModel.ts b/app/client/models/SearchModel.ts index e9aa6cf4..162035c6 100644 --- a/app/client/models/SearchModel.ts +++ b/app/client/models/SearchModel.ts @@ -101,7 +101,7 @@ class FinderImpl implements IFinder { private _sectionTableData: TableData; private _rowStepper = new Stepper(); private _fieldStepper = new Stepper(); - private _fieldFormatters: BaseFormatter[]; + private _fieldFormatters: [ViewFieldRec, BaseFormatter][]; private _pagesSwitched: number = 0; private _aborted = false; private _clearCursorHighlight: (() => void)|undefined; @@ -218,7 +218,7 @@ class FinderImpl implements IFinder { this._sectionTableData = tableModel.tableData; this._fieldStepper.array = section.viewFields().peek(); - this._fieldFormatters = this._fieldStepper.array.map(f => f.formatter.peek()); + this._initFormatters(); return tableModel; } @@ -252,6 +252,10 @@ class FinderImpl implements IFinder { this._sectionStepper.array = view.viewSections().peek(); } + private _initFormatters() { + this._fieldFormatters = this._fieldStepper.array.map(f => [f, f.formatter.peek()]); + } + private _matches(): boolean { if (this._pageStepper.index < 0 || this._sectionStepper.index < 0 || this._rowStepper.index < 0 || this._fieldStepper.index < 0) { @@ -259,14 +263,20 @@ class FinderImpl implements IFinder { return false; } const field = this._fieldStepper.value; - const formatter = this._fieldFormatters[this._fieldStepper.index]; + let formatter = this._fieldFormatters[this._fieldStepper.index]; + // When fields are removed during search (or reordered) we need to update + // formatters we retrieved on init. + if (!formatter || formatter[0 /* field */] !== field) { + this._initFormatters(); + formatter = this._fieldFormatters[this._fieldStepper.index]; + } const rowId = this._rowStepper.value; const displayCol = field.displayColModel.peek(); const value = this._sectionTableData.getValue(rowId, displayCol.colId.peek()); // TODO: Note that formatting dates is now the bulk of the performance cost. - const text = formatter.formatAny(value); + const text = formatter[1 /* formatter */].formatAny(value); return this._searchRegexp.test(text); } diff --git a/test/nbrowser/gristUtils.ts b/test/nbrowser/gristUtils.ts index 402ed231..7ae18513 100644 --- a/test/nbrowser/gristUtils.ts +++ b/test/nbrowser/gristUtils.ts @@ -998,6 +998,46 @@ export async function waitForSidePanel() { await driver.sleep((transitionDuration + delta) * 1000); } +/** + * Opens a Creator Panel on Widget/Table settings tab. + */ +export async function openWidgetPanel() { + await toggleSidePanel('right', 'open'); + await driver.find('.test-right-tab-pagewidget').click(); +} + +/** + * Moves a column from a hidden to visible section. + * Needs a visible Creator panel. + */ +export async function moveToVisible(col: string) { + const row = await driver.findContent(".test-vfc-hidden-fields .kf_draggable_content", exactMatch(col)); + await row.mouseMove(); + await row.find('.test-vfc-hide').click(); + await waitForServer(); +} + +/** + * Moves a column from a visible to hidden section. + * Needs a visible Creator panel. + */ +export async function moveToHidden(col: string) { + const row = await driver.findContent(".test-vfc-visible-fields .kf_draggable_content", exactMatch(col)); + await row.mouseMove(); + await row.find('.test-vfc-hide').click(); + await waitForServer(); +} + +export async function search(what: string) { + await driver.find('.test-tb-search-icon').doClick(); + await driver.sleep(500); + await driver.find('.test-tb-search-input').doClick(); + await selectAll(); + await driver.sendKeys(what); + // Sleep for search debounce time + await driver.sleep(120); +} + /** * Toggles (opens or closes) the filter bar for a section. */