mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(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
This commit is contained in:
parent
d88f79bc5e
commit
7d3b4b49d5
@ -7,7 +7,7 @@
|
|||||||
import {DocComm} from 'app/client/components/DocComm';
|
import {DocComm} from 'app/client/components/DocComm';
|
||||||
import {MetaTableData, TableData} from 'app/client/models/TableData';
|
import {MetaTableData, TableData} from 'app/client/models/TableData';
|
||||||
import {ApplyUAOptions, ApplyUAResult} from 'app/common/ActiveDocAPI';
|
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 {DocData as BaseDocData} from 'app/common/DocData';
|
||||||
import {SchemaTypes} from 'app/common/schema';
|
import {SchemaTypes} from 'app/common/schema';
|
||||||
import {ColTypeMap} from 'app/common/TableData';
|
import {ColTypeMap} from 'app/common/TableData';
|
||||||
@ -192,9 +192,22 @@ export class DocData extends BaseDocData {
|
|||||||
|
|
||||||
// See documentation of sendActions().
|
// See documentation of sendActions().
|
||||||
private async _sendActionsImpl(actions: UserAction[], optDesc?: string): Promise<any[]> {
|
private async _sendActionsImpl(actions: UserAction[], optDesc?: string): Promise<any[]> {
|
||||||
if (this._virtualTablesFunc?.has(actions[0]?.[1] as any)) {
|
const tableName = String(actions[0]?.[1]);
|
||||||
// It would be easy to pass along actions, but we don't need this functionality yet.
|
if (this._virtualTablesFunc?.has(tableName)) {
|
||||||
throw new Error('_sendActionsImpl needs updating to direct actions to virtual tables');
|
// 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};
|
const eventData = {actions};
|
||||||
this.sendActionsEmitter.emit(eventData);
|
this.sendActionsEmitter.emit(eventData);
|
||||||
|
@ -90,11 +90,11 @@ export function isSchemaAction(action: DocAction):
|
|||||||
return SCHEMA_ACTIONS.has(action[0]);
|
return SCHEMA_ACTIONS.has(action[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDataAction(action: DocAction):
|
export function isDataAction(action: DocAction|UserAction):
|
||||||
action is AddRecord | RemoveRecord | UpdateRecord |
|
action is AddRecord | RemoveRecord | UpdateRecord |
|
||||||
BulkAddRecord | BulkRemoveRecord | BulkUpdateRecord |
|
BulkAddRecord | BulkRemoveRecord | BulkUpdateRecord |
|
||||||
ReplaceTableData | TableDataAction {
|
ReplaceTableData | TableDataAction {
|
||||||
return DATA_ACTIONS.has(action[0]);
|
return DATA_ACTIONS.has(String(action[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -249,6 +249,21 @@ describe('WebhookPage', function () {
|
|||||||
await driver.close();
|
await driver.close();
|
||||||
await driver.switchTo().window(ownerTab);
|
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) {
|
async function setField(rowNum: number, col: string, text: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user