(core) Exposing custom widgets on the UI

Summary:
Exposing custom widgets as a dropdown menu in custom section configuration panel.

Adding new environmental variable GRIST_WIDGET_LIST_URL that points to a
json file with an array of available widgets. When not present, custom widget menu is
hidden, exposing only Custom URL option.

Available widget list can be fetched from:
https://github.com/gristlabs/grist-widget/releases/download/latest/manifest.json

Test Plan: New tests, and updated old ones.

Reviewers: paulfitz, dsagal

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3127
This commit is contained in:
Jarosław Sadziński
2021-11-26 11:43:55 +01:00
parent be96db4689
commit 1425461cd8
16 changed files with 482 additions and 25 deletions

View File

@@ -12,6 +12,7 @@ import {RequestWithOrg} from 'app/server/lib/extractOrg';
import * as log from 'app/server/lib/log';
import {addPermit, getDocScope, getScope, integerParam, isParameterOn, sendOkReply,
sendReply, stringParam} from 'app/server/lib/requestUtils';
import {IWidgetRepository} from 'app/server/lib/WidgetRepository';
import {Request} from 'express';
import {User} from './entity/User';
@@ -98,7 +99,8 @@ export class ApiServer {
*/
constructor(
private _app: express.Application,
private _dbManager: HomeDBManager
private _dbManager: HomeDBManager,
private _widgetRepository: IWidgetRepository
) {
this._addEndpoints();
}
@@ -238,6 +240,13 @@ export class ApiServer {
return sendReply(req, res, query);
}));
// GET /api/widgets/
// Get all widget definitions from external source.
this._app.get('/api/widgets/', expressWrap(async (req, res) => {
const widgetList = await this._widgetRepository.getWidgets();
return sendOkReply(req, res, widgetList);
}));
// PATCH /api/docs/:did
// Update the specified doc.
this._app.patch('/api/docs/:did', expressWrap(async (req, res) => {