(core) Adds a UI panel for managing webhooks

Summary:
This adds a UI panel for managing webhooks. Work started by Cyprien Pindat. You can find the UI on a document's settings page. Main changes relative to Cyprien's demo:

  * Changed behavior of virtual table to be more consistent with the rest of Grist, by factoring out part of the implementation of on-demand tables.
  * Cell values that would create an error can now be denied and reverted (as for the rest of Grist).
  * Changes made by other users are integrated in a sane way.
  * Basic undo/redo support is added using the regular undo/redo stack.
  * The table list in the drop-down is now updated if schema changes.
  * Added a notification from back-end when webhook status is updated so constant polling isn't needed to support multi-user operation.
  *  Factored out webhook specific logic from general virtual table support.
  * Made a bunch of fixes to various broken behavior.
  * Added tests.

The code remains somewhat unpolished, and behavior in the presence of errors is imperfect in general but may be adequate for this case.

I assume that we'll soon be lifting the restriction on the set of domains that are supported for webhooks - otherwise we'd want to provide some friendly way to discover that list of supported domains rather than just throwing an error.

I don't actually know a lot about how the front-end works - it looks like tables/columns/fields/sections can be safely added if they have string ids that won't collide with bone fide numeric ids from the back end. Sneaky.

Contains a migration, so needs an extra reviewer for that.

Test Plan: added tests

Reviewers: jarek, dsagal

Reviewed By: jarek, dsagal

Differential Revision: https://phab.getgrist.com/D3856
This commit is contained in:
Paul Fitzpatrick
2023-05-08 18:06:24 -04:00
parent 5e9f2e06ea
commit 603238e966
37 changed files with 1698 additions and 376 deletions

View File

@@ -32,6 +32,8 @@ export class DocData extends BaseDocData {
private _lastActionNum: number|null = null; // ActionNum of the last action in the current bundle, or null.
private _bundleSender: BundleSender;
private _virtualTablesFunc: Map<string, Constructor<TableData>>;
/**
* Constructor for DocData.
* @param {Object} docComm: A map of server methods available on this document.
@@ -41,10 +43,12 @@ export class DocData extends BaseDocData {
constructor(public readonly docComm: DocComm, metaTableData: {[tableId: string]: TableDataAction}) {
super((tableId) => docComm.fetchTable(tableId), metaTableData);
this._bundleSender = new BundleSender(this.docComm);
this._virtualTablesFunc = new Map();
}
public createTableData(tableId: string, tableData: TableDataAction|null, colTypes: ColTypeMap): TableData {
return new TableData(this, tableId, tableData, colTypes);
const Cons = this._virtualTablesFunc?.get(tableId) || TableData;
return new Cons(this, tableId, tableData, colTypes);
}
// Version of inherited getTable() which returns the enhance TableData type.
@@ -182,8 +186,16 @@ export class DocData extends BaseDocData {
return this.sendActions([action], optDesc).then((retValues) => retValues[0]);
}
public registerVirtualTable(tableId: string, Cons: typeof TableData) {
this._virtualTablesFunc.set(tableId, Cons);
}
// 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 eventData = {actions};
this.sendActionsEmitter.emit(eventData);
const options = { desc: optDesc };
@@ -282,3 +294,5 @@ export interface BundlingInfo<T = unknown> {
// Promise for when the bundle has been finalized.
completionPromise: Promise<void>;
}
type Constructor<T> = new (...args: any[]) => T;