mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +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:
@@ -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<any[]> {
|
||||
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);
|
||||
|
||||
@@ -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]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user