From 7d3b4b49d5052ae5f8f73957a04869bedac93a82 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Thu, 15 Jun 2023 16:12:19 -0400 Subject: [PATCH] (core) forward more kinds of edits to a virtual table Summary: Some edits to virtual tables (such as webhook lists) happen via a route that was not yet handled. Actually Cyprien (the original author) had handled this case but it got removed because I didn't know what it was for :-). This brings back support for edits by this route. Test Plan: added a test Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3924 --- app/client/models/DocData.ts | 21 +++++++++++++++++---- app/common/DocActions.ts | 4 ++-- test/nbrowser/WebhookPage.ts | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/client/models/DocData.ts b/app/client/models/DocData.ts index 1af61329..747a6f19 100644 --- a/app/client/models/DocData.ts +++ b/app/client/models/DocData.ts @@ -7,7 +7,7 @@ import {DocComm} from 'app/client/components/DocComm'; import {MetaTableData, TableData} from 'app/client/models/TableData'; import {ApplyUAOptions, ApplyUAResult} from 'app/common/ActiveDocAPI'; -import {CellValue, TableDataAction, UserAction} from 'app/common/DocActions'; +import {CellValue, getTableId, isDataAction, TableDataAction, UserAction} from 'app/common/DocActions'; import {DocData as BaseDocData} from 'app/common/DocData'; import {SchemaTypes} from 'app/common/schema'; import {ColTypeMap} from 'app/common/TableData'; @@ -192,9 +192,22 @@ export class DocData extends BaseDocData { // See documentation of sendActions(). private async _sendActionsImpl(actions: UserAction[], optDesc?: string): Promise { - if (this._virtualTablesFunc?.has(actions[0]?.[1] as any)) { - // It would be easy to pass along actions, but we don't need this functionality yet. - throw new Error('_sendActionsImpl needs updating to direct actions to virtual tables'); + const tableName = String(actions[0]?.[1]); + if (this._virtualTablesFunc?.has(tableName)) { + // Actions applying to virtual tables are handled directly by their TableData instance. + for (const action of actions) { + if (!isDataAction(action)) { + throw new Error('virtual table received an action it cannot handle'); + } + if (getTableId(action) !== tableName) { + throw new Error('virtual table actions mixed with other actions'); + } + } + const tableActions = actions.map(a => [a[0], ...a.slice(2)]); + // The type on sendTableActions seems kind of misleading, and + // only working because UserAction is defined weakly. The first + // thing the method does is splice back in the table names... + return this.getTable(tableName)!.sendTableActions(tableActions, optDesc); } const eventData = {actions}; this.sendActionsEmitter.emit(eventData); diff --git a/app/common/DocActions.ts b/app/common/DocActions.ts index 453f50d3..503e01a3 100644 --- a/app/common/DocActions.ts +++ b/app/common/DocActions.ts @@ -90,11 +90,11 @@ export function isSchemaAction(action: DocAction): return SCHEMA_ACTIONS.has(action[0]); } -export function isDataAction(action: DocAction): +export function isDataAction(action: DocAction|UserAction): action is AddRecord | RemoveRecord | UpdateRecord | BulkAddRecord | BulkRemoveRecord | BulkUpdateRecord | ReplaceTableData | TableDataAction { - return DATA_ACTIONS.has(action[0]); + return DATA_ACTIONS.has(String(action[0])); } /** diff --git a/test/nbrowser/WebhookPage.ts b/test/nbrowser/WebhookPage.ts index e88c4f98..c438d49d 100644 --- a/test/nbrowser/WebhookPage.ts +++ b/test/nbrowser/WebhookPage.ts @@ -249,6 +249,21 @@ describe('WebhookPage', function () { await driver.close(); await driver.switchTo().window(ownerTab); }); + + /** + * Checks that a particular route to modifying cells in a virtual table + * is in place (previously it was not). + */ + it('can paste into a cell without clicking into it', async function() { + await openWebhookPage(); + await setField(1, 'Name', '1234'); + await gu.waitForServer(); + await gu.sendKeys(await gu.copyKey()); + await gu.getDetailCell({col: 'Memo', rowNum: 1}).click(); + await gu.sendKeys(await gu.pasteKey()); + await gu.waitForServer(); + assert.equal(await getField(1, 'Memo'), '1234'); + }); }); async function setField(rowNum: number, col: string, text: string) {