(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
This commit is contained in:
Jarosław Sadziński 2022-03-08 15:00:21 +01:00
parent 7ead97b913
commit d2b82b84c7
2 changed files with 54 additions and 4 deletions

View File

@ -101,7 +101,7 @@ class FinderImpl implements IFinder {
private _sectionTableData: TableData;
private _rowStepper = new Stepper<number>();
private _fieldStepper = new Stepper<ViewFieldRec>();
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);
}

View File

@ -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.
*/