mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
39
app/common/CustomWidget.ts
Normal file
39
app/common/CustomWidget.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Custom widget manifest definition.
|
||||
*/
|
||||
export interface ICustomWidget {
|
||||
/**
|
||||
* Widget friendly name, used on the UI.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Widget unique id, probably in npm package format @gristlabs/custom-widget-name.
|
||||
*/
|
||||
widgetId: string;
|
||||
/**
|
||||
* Custom widget main page URL.
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* Optional desired access level.
|
||||
*/
|
||||
accessLevel?: AccessLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget access level.
|
||||
*/
|
||||
export enum AccessLevel {
|
||||
/**
|
||||
* Default, no access to Grist.
|
||||
*/
|
||||
none = "none",
|
||||
/**
|
||||
* Read only access to table the widget is based on.
|
||||
*/
|
||||
read_table = "read table",
|
||||
/**
|
||||
* Full access to document on user's behalf.
|
||||
*/
|
||||
full = "full",
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {BrowserSettings} from 'app/common/BrowserSettings';
|
||||
import {BulkColValues, TableColValues, UserAction} from 'app/common/DocActions';
|
||||
import {DocCreationInfo, OpenDocMode} from 'app/common/DocListAPI';
|
||||
import {Features} from 'app/common/Features';
|
||||
import {ICustomWidget} from 'app/common/CustomWidget';
|
||||
import {isClient} from 'app/common/gristUrls';
|
||||
import {FullUser} from 'app/common/LoginSessionAPI';
|
||||
import {OrgPrefs, UserOrgPrefs, UserPrefs} from 'app/common/Prefs';
|
||||
@@ -321,6 +322,7 @@ export interface UserAPI {
|
||||
deleteUser(userId: number, name: string): Promise<void>;
|
||||
getBaseUrl(): string; // Get the prefix for all the endpoints this object wraps.
|
||||
forRemoved(): UserAPI; // Get a version of the API that works on removed resources.
|
||||
getWidgets(): Promise<ICustomWidget[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,6 +430,10 @@ export class UserAPIImpl extends BaseAPI implements UserAPI {
|
||||
return this.requestJson(`${this._url}/api/templates?onlyFeatured=${onlyFeatured ? 1 : 0}`, { method: 'GET' });
|
||||
}
|
||||
|
||||
public async getWidgets(): Promise<ICustomWidget[]> {
|
||||
return await this.requestJson(`${this._url}/api/widgets`, { method: 'GET' });
|
||||
}
|
||||
|
||||
public async getDoc(docId: string): Promise<Document> {
|
||||
return this.requestJson(`${this._url}/api/docs/${docId}`, { method: 'GET' });
|
||||
}
|
||||
|
||||
@@ -469,6 +469,9 @@ export interface GristLoadConfig {
|
||||
|
||||
// List of registered plugins (used by HomePluginManager and DocPluginManager)
|
||||
plugins?: LocalPlugin[];
|
||||
|
||||
// If custom widget list is available.
|
||||
enableWidgetRepository?: boolean;
|
||||
}
|
||||
|
||||
// Acceptable org subdomains are alphanumeric (hyphen also allowed) and of
|
||||
|
||||
Reference in New Issue
Block a user