(core) Allow configuring (mostly hiding) various little bits of UI

Summary:
Adds two new env vars GRIST_HIDE_UI_ELEMENTS and GRIST_PAGE_TITLE_SUFFIX which translate to values in GristLoadConfig that the server sends the client when loading.

For checkin task https://gristlabs.getgrist.com/doc/check-ins/p/5#a1.s9.r1882.c19

Test Plan: Tested manually

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3449
This commit is contained in:
Alex Hall
2022-05-27 13:03:56 +02:00
parent 74ec9358da
commit 6b372fa6cd
14 changed files with 64 additions and 14 deletions

View File

@@ -33,6 +33,10 @@ export const StringUnion = <UnionType extends string>(...values: UnionType[]) =>
return value;
};
const checkAll = (arr: string[]): UnionType[] => {
return arr.map(check);
};
/**
* StringUnion.parse(value) returns value when it's valid, and undefined otherwise.
*/
@@ -40,6 +44,6 @@ export const StringUnion = <UnionType extends string>(...values: UnionType[]) =>
return value != null && guard(value) ? value : undefined;
};
const unionNamespace = {guard, check, parse, values};
const unionNamespace = {guard, check, parse, values, checkAll};
return Object.freeze(unionNamespace as typeof unionNamespace & {type: UnionType});
};

View File

@@ -5,6 +5,7 @@ import {encodeQueryParams, isAffirmative} from 'app/common/gutil';
import {LocalPlugin} from 'app/common/plugin';
import {StringUnion} from 'app/common/StringUnion';
import {UIRowId} from 'app/common/UIRowId';
import {getGristConfig} from 'app/common/urlUtils';
import {Document} from 'app/common/UserAPI';
import clone = require('lodash/clone');
import pickBy = require('lodash/pickBy');
@@ -520,6 +521,23 @@ export interface GristLoadConfig {
tagManagerId?: string;
activation?: ActivationState;
// Parts of the UI to hide
hideUiElements?: IHideableUiElement[];
// String to append to the end of the HTML document.title
pageTitleSuffix?: string;
}
export const HideableUiElements = StringUnion("helpCenter", "billing", "templates", "multiSite", "multiAccounts");
export type IHideableUiElement = typeof HideableUiElements.type;
export function shouldHideUiElement(elem: IHideableUiElement): boolean {
return (getGristConfig().hideUiElements || []).includes(elem);
}
export function getPageTitleSuffix(config?: GristLoadConfig) {
return config?.pageTitleSuffix ?? " - Grist";
}
/**