2020-10-02 15:10:00 +00:00
|
|
|
import {urlState} from 'app/client/models/gristUrlState';
|
2021-08-18 17:49:34 +00:00
|
|
|
import {getTheme} from 'app/client/ui/CustomThemes';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {cssLeftPane} from 'app/client/ui/PagePanels';
|
|
|
|
import {colors, testId, vars} from 'app/client/ui2018/cssVars';
|
2022-05-27 11:03:56 +00:00
|
|
|
import {shouldHideUiElement} from 'app/common/gristUrls';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as version from 'app/common/version';
|
2021-08-18 17:49:34 +00:00
|
|
|
import {BindableValue, Disposable, dom, styled} from "grainjs";
|
(core) make Grist easier to run with a single server
Summary:
This makes many small changes so that Grist is less fussy to run as a single instance behind a reverse proxy. Some users had difficulty with the self-connections Grist would make, due to internal network setup, and since these are unnecessary in any case in this scenario, they are now optimized away. Likewise some users had difficulties related to doc worker urls, which are now also optimized away. With these changes, users should be able to get a lot further on first try, at least far enough to open and edit documents.
The `GRIST_SINGLE_ORG` setting was proving a bit confusing, since it appeared to only work when set to `docs`. This diff
adds a check for whether the specified org exists, and if not, it creates it. This still depends on having a user email to make as the owner of the team, so there could be remaining difficulties there.
Test Plan: tested manually with nginx
Reviewers: jarek
Reviewed By: jarek
Differential Revision: https://phab.getgrist.com/D3299
2022-03-02 19:07:26 +00:00
|
|
|
import {menu, menuItem, menuItemLink, menuSubHeader} from 'app/client/ui2018/menus';
|
2022-06-08 17:54:00 +00:00
|
|
|
import {isTemplatesOrg, Organization} from 'app/common/UserAPI';
|
2021-08-18 17:49:34 +00:00
|
|
|
import {AppModel} from 'app/client/models/AppModel';
|
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2021-11-05 14:47:17 +00:00
|
|
|
import {DocPageModel} from 'app/client/models/DocPageModel';
|
|
|
|
import * as roles from 'app/common/roles';
|
2022-06-03 14:58:07 +00:00
|
|
|
import {manageTeamUsersApp} from 'app/client/ui/OpenUserManager';
|
(core) make Grist easier to run with a single server
Summary:
This makes many small changes so that Grist is less fussy to run as a single instance behind a reverse proxy. Some users had difficulty with the self-connections Grist would make, due to internal network setup, and since these are unnecessary in any case in this scenario, they are now optimized away. Likewise some users had difficulties related to doc worker urls, which are now also optimized away. With these changes, users should be able to get a lot further on first try, at least far enough to open and edit documents.
The `GRIST_SINGLE_ORG` setting was proving a bit confusing, since it appeared to only work when set to `docs`. This diff
adds a check for whether the specified org exists, and if not, it creates it. This still depends on having a user email to make as the owner of the team, so there could be remaining difficulties there.
Test Plan: tested manually with nginx
Reviewers: jarek
Reviewed By: jarek
Differential Revision: https://phab.getgrist.com/D3299
2022-03-02 19:07:26 +00:00
|
|
|
import {maybeAddSiteSwitcherSection} from 'app/client/ui/SiteSwitcher';
|
2022-06-03 14:58:07 +00:00
|
|
|
import {DomContents} from 'grainjs';
|
2021-08-18 17:49:34 +00:00
|
|
|
|
2022-06-03 14:58:07 +00:00
|
|
|
// Maps a name of a Product (from app/gen-server/entity/Product.ts) to a tag (pill) to show next
|
|
|
|
// to the org name.
|
|
|
|
const productPills: {[name: string]: string|null} = {
|
|
|
|
// TODO We don't label paid team plans with a tag yet, but we should label as "Pro" once we
|
|
|
|
// update our pricing pages to refer to paid team plans as Pro plans.
|
|
|
|
"professional": null, // Deprecated but used in development.
|
|
|
|
"team": null, // Used for the paid team plans.
|
|
|
|
"teamFree": "Free", // The new free team plan.
|
|
|
|
// Other plans are either personal, or grandfathered, or for testing.
|
|
|
|
};
|
2021-08-18 17:49:34 +00:00
|
|
|
|
|
|
|
export class AppHeader extends Disposable {
|
2021-11-05 14:47:17 +00:00
|
|
|
constructor(private _orgName: BindableValue<string>, private _appModel: AppModel,
|
|
|
|
private _docPageModel?: DocPageModel) {
|
2021-08-18 17:49:34 +00:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom() {
|
|
|
|
const theme = getTheme(this._appModel.topAppModel.productFlavor);
|
|
|
|
|
2021-11-05 14:47:17 +00:00
|
|
|
const currentOrg = this._appModel.currentOrg;
|
2022-06-08 17:54:00 +00:00
|
|
|
const isBillingManager = this._appModel.isBillingManager() || this._appModel.isSupport();
|
2021-11-05 14:47:17 +00:00
|
|
|
|
2021-08-18 17:49:34 +00:00
|
|
|
return cssAppHeader(
|
|
|
|
cssAppHeader.cls('-widelogo', theme.wideLogo || false),
|
|
|
|
// Show version when hovering over the application icon.
|
|
|
|
cssAppLogo(
|
|
|
|
{title: `Ver ${version.version} (${version.gitcommit})`},
|
|
|
|
urlState().setLinkUrl({}),
|
|
|
|
testId('dm-logo')
|
|
|
|
),
|
|
|
|
cssOrg(
|
2022-06-03 14:58:07 +00:00
|
|
|
cssOrgName(dom.text(this._orgName), testId('dm-orgname')),
|
|
|
|
productPill(currentOrg),
|
2021-08-18 17:49:34 +00:00
|
|
|
this._orgName && cssDropdownIcon('Dropdown'),
|
2021-11-05 14:47:17 +00:00
|
|
|
menu(() => [
|
2022-07-26 17:49:35 +00:00
|
|
|
menuSubHeader(
|
|
|
|
`${this._appModel.isTeamSite ? 'Team' : 'Personal'} Site`
|
|
|
|
+ (this._appModel.isLegacySite ? ' (Legacy)' : ''),
|
|
|
|
testId('orgmenu-title'),
|
|
|
|
),
|
2021-11-05 14:47:17 +00:00
|
|
|
menuItemLink(urlState().setLinkUrl({}), 'Home Page', testId('orgmenu-home-page')),
|
2021-08-18 17:49:34 +00:00
|
|
|
|
2021-11-05 14:47:17 +00:00
|
|
|
// Show 'Organization Settings' when on a home page of a valid org.
|
|
|
|
(!this._docPageModel && currentOrg && !currentOrg.owner ?
|
2022-06-03 14:58:07 +00:00
|
|
|
menuItem(() => manageTeamUsersApp(this._appModel),
|
|
|
|
'Manage Team', testId('orgmenu-manage-team'),
|
2021-11-05 14:47:17 +00:00
|
|
|
dom.cls('disabled', !roles.canEditAccess(currentOrg.access))) :
|
|
|
|
// Don't show on doc pages, or for personal orgs.
|
|
|
|
null),
|
|
|
|
|
|
|
|
// Show link to billing pages.
|
2022-05-27 11:03:56 +00:00
|
|
|
currentOrg && !currentOrg.owner && !shouldHideUiElement("billing") ?
|
2021-11-05 14:47:17 +00:00
|
|
|
// For links, disabling with just a class is hard; easier to just not make it a link.
|
|
|
|
// TODO weasel menus should support disabling menuItemLink.
|
|
|
|
(isBillingManager ?
|
|
|
|
menuItemLink(urlState().setLinkUrl({billing: 'billing'}), 'Billing Account') :
|
|
|
|
menuItem(() => null, 'Billing Account', dom.cls('disabled', true), testId('orgmenu-billing'))
|
|
|
|
) :
|
|
|
|
null,
|
2021-08-18 17:49:34 +00:00
|
|
|
|
(core) make Grist easier to run with a single server
Summary:
This makes many small changes so that Grist is less fussy to run as a single instance behind a reverse proxy. Some users had difficulty with the self-connections Grist would make, due to internal network setup, and since these are unnecessary in any case in this scenario, they are now optimized away. Likewise some users had difficulties related to doc worker urls, which are now also optimized away. With these changes, users should be able to get a lot further on first try, at least far enough to open and edit documents.
The `GRIST_SINGLE_ORG` setting was proving a bit confusing, since it appeared to only work when set to `docs`. This diff
adds a check for whether the specified org exists, and if not, it creates it. This still depends on having a user email to make as the owner of the team, so there could be remaining difficulties there.
Test Plan: tested manually with nginx
Reviewers: jarek
Reviewed By: jarek
Differential Revision: https://phab.getgrist.com/D3299
2022-03-02 19:07:26 +00:00
|
|
|
maybeAddSiteSwitcherSection(this._appModel),
|
2021-11-05 14:47:17 +00:00
|
|
|
], { placement: 'bottom-start' }),
|
|
|
|
testId('dm-org'),
|
2021-08-18 17:49:34 +00:00
|
|
|
),
|
2021-11-05 14:47:17 +00:00
|
|
|
);
|
2021-08-18 17:49:34 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 14:58:07 +00:00
|
|
|
export function productPill(org: Organization|null, options: {large?: boolean} = {}): DomContents {
|
|
|
|
if (!org || isTemplatesOrg(org)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const product = org?.billingAccount?.product.name;
|
|
|
|
const pillTag = product && productPills[product];
|
|
|
|
if (!pillTag) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return cssProductPill(cssProductPill.cls('-' + pillTag),
|
|
|
|
options.large ? cssProductPill.cls('-large') : null,
|
|
|
|
pillTag,
|
|
|
|
testId('appheader-product-pill'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-18 17:49:34 +00:00
|
|
|
const cssAppHeader = styled('div', `
|
2020-10-02 15:10:00 +00:00
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
align-items: center;
|
|
|
|
&, &:hover, &:focus {
|
|
|
|
text-decoration: none;
|
|
|
|
outline: none;
|
|
|
|
color: ${colors.dark};
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2021-08-18 17:49:34 +00:00
|
|
|
const cssAppLogo = styled('a', `
|
2020-10-02 15:10:00 +00:00
|
|
|
flex: none;
|
|
|
|
height: 48px;
|
|
|
|
width: 48px;
|
|
|
|
background-image: var(--icon-GristLogo);
|
2022-05-12 06:08:06 +00:00
|
|
|
background-size: ${vars.logoSize};
|
2020-10-02 15:10:00 +00:00
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-position: center;
|
|
|
|
background-color: ${vars.logoBg};
|
|
|
|
.${cssAppHeader.className}-widelogo & {
|
|
|
|
width: 100%;
|
|
|
|
background-size: contain;
|
|
|
|
background-origin: content-box;
|
|
|
|
padding: 8px;
|
|
|
|
}
|
|
|
|
.${cssLeftPane.className}-open .${cssAppHeader.className}-widelogo & {
|
|
|
|
background-image: var(--icon-GristWideLogo, var(--icon-GristLogo));
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2021-08-18 17:49:34 +00:00
|
|
|
const cssDropdownIcon = styled(icon, `
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin-right: 8px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssOrg = styled('div', `
|
2022-07-27 19:02:28 +00:00
|
|
|
display: none;
|
2021-08-18 17:49:34 +00:00
|
|
|
flex-grow: 1;
|
|
|
|
align-items: center;
|
|
|
|
max-width: calc(100% - 48px);
|
|
|
|
cursor: pointer;
|
|
|
|
height: 100%;
|
2022-06-03 14:58:07 +00:00
|
|
|
font-weight: 500;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: ${colors.mediumGrey};
|
|
|
|
}
|
2022-07-27 19:02:28 +00:00
|
|
|
|
|
|
|
.${cssLeftPane.className}-open & {
|
|
|
|
display: flex;
|
|
|
|
}
|
2021-08-18 17:49:34 +00:00
|
|
|
`);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const cssOrgName = styled('div', `
|
2021-08-18 17:49:34 +00:00
|
|
|
padding-left: 16px;
|
|
|
|
padding-right: 8px;
|
2020-10-02 15:10:00 +00:00
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
.${cssAppHeader.className}-widelogo & {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
`);
|
2022-06-03 14:58:07 +00:00
|
|
|
|
|
|
|
const cssProductPill = styled('div', `
|
|
|
|
border-radius: 4px;
|
|
|
|
font-size: ${vars.smallFontSize};
|
|
|
|
padding: 2px 4px;
|
|
|
|
display: inline;
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
|
|
&-Free {
|
|
|
|
background-color: ${colors.orange};
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
&-Pro {
|
|
|
|
background-color: ${colors.lightGreen};
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
&-large {
|
|
|
|
padding: 4px 8px;
|
|
|
|
margin-left: 16px;
|
|
|
|
font-size: ${vars.mediumFontSize};
|
|
|
|
}
|
|
|
|
`);
|