mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -9,6 +9,9 @@ import sortBy = require('lodash/sortBy');
|
||||
|
||||
export interface ActionGroupWithCursorPos extends MinimalActionGroup {
|
||||
cursorPos?: CursorPos;
|
||||
// For operations not done by the server, we supply a function to
|
||||
// handle them.
|
||||
op?: (ag: MinimalActionGroup, isUndo: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
// Provides observables indicating disabled state for undo/redo.
|
||||
@@ -28,7 +31,7 @@ export class UndoStack extends dispose.Disposable {
|
||||
private _gristDoc: GristDoc;
|
||||
private _stack: ActionGroupWithCursorPos[];
|
||||
private _pointer: number;
|
||||
private _linkMap: Map<number, MinimalActionGroup[]>;
|
||||
private _linkMap: Map<number, ActionGroupWithCursorPos[]>;
|
||||
|
||||
// Chain of promises which send undo actions to the server. This delays the execution of the
|
||||
// next action until the current one has been received and moved the pointer index.
|
||||
@@ -119,11 +122,17 @@ export class UndoStack extends dispose.Disposable {
|
||||
// responsive, then again when the action is done. The second jump matters more for most
|
||||
// changes, but the first is the important one when Undoing an AddRecord.
|
||||
this._gristDoc.moveToCursorPos(ag.cursorPos, ag).catch(() => { /* do nothing */ });
|
||||
await this._gristDoc.docComm.applyUserActionsById(
|
||||
actionGroups.map(a => a.actionNum),
|
||||
actionGroups.map(a => a.actionHash),
|
||||
isUndo,
|
||||
{ otherId: ag.actionNum });
|
||||
if (actionGroups.length === 1 && actionGroups[0].op) {
|
||||
// this is an internal operation, rather than one done by the server,
|
||||
// so we can't ask the server to undo it.
|
||||
await actionGroups[0].op(actionGroups[0], isUndo);
|
||||
} else {
|
||||
await this._gristDoc.docComm.applyUserActionsById(
|
||||
actionGroups.map(a => a.actionNum),
|
||||
actionGroups.map(a => a.actionHash),
|
||||
isUndo,
|
||||
{ otherId: ag.actionNum });
|
||||
}
|
||||
this._gristDoc.moveToCursorPos(ag.cursorPos, ag).catch(() => { /* do nothing */ });
|
||||
} catch (err) {
|
||||
err.message = `Failed to apply ${isUndo ? 'undo' : 'redo'} action: ${err.message}`;
|
||||
@@ -134,7 +143,7 @@ export class UndoStack extends dispose.Disposable {
|
||||
/**
|
||||
* Find all actionGroups in the bundle that starts with the given action group.
|
||||
*/
|
||||
private _findActionBundle(ag: MinimalActionGroup) {
|
||||
private _findActionBundle(ag: ActionGroupWithCursorPos) {
|
||||
const prevNums = new Set();
|
||||
const actionGroups = [];
|
||||
const queue = [ag];
|
||||
|
||||
Reference in New Issue
Block a user