2022-10-28 16:11:08 +00:00
|
|
|
import {dom, makeTestId, styled} from 'grainjs';
|
2023-05-20 23:58:41 +00:00
|
|
|
import {getSingleOrg, isFeatureEnabled} from 'app/common/gristUrls';
|
2021-11-05 14:47:17 +00:00
|
|
|
import {getOrgName} from 'app/common/UserAPI';
|
2022-10-28 16:11:08 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2021-11-05 14:47:17 +00:00
|
|
|
import {AppModel} from 'app/client/models/AppModel';
|
|
|
|
import {urlState} from 'app/client/models/gristUrlState';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {theme} from 'app/client/ui2018/cssVars';
|
2022-06-08 17:54:00 +00:00
|
|
|
import {menuDivider, menuIcon, menuItem, menuItemLink, menuSubHeader} from 'app/client/ui2018/menus';
|
2021-11-05 14:47:17 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('SiteSwitcher');
|
|
|
|
|
2021-11-05 14:47:17 +00:00
|
|
|
const testId = makeTestId('test-site-switcher-');
|
|
|
|
|
(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
|
|
|
/**
|
|
|
|
* Adds a menu divider and a site switcher, if there is need for one.
|
|
|
|
*/
|
|
|
|
export function maybeAddSiteSwitcherSection(appModel: AppModel) {
|
|
|
|
const orgs = appModel.topAppModel.orgs;
|
2023-05-20 23:58:41 +00:00
|
|
|
return dom.maybe((use) => use(orgs).length > 0 && !getSingleOrg() && isFeatureEnabled("multiSite"), () => [
|
(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
|
|
|
menuDivider(),
|
|
|
|
buildSiteSwitcher(appModel),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-11-05 14:47:17 +00:00
|
|
|
/**
|
|
|
|
* Builds a menu sub-section that displays a list of orgs/sites that the current
|
|
|
|
* valid user has access to, with buttons to navigate to them.
|
|
|
|
*
|
|
|
|
* Used by AppHeader and AccountWidget.
|
|
|
|
*/
|
|
|
|
export function buildSiteSwitcher(appModel: AppModel) {
|
|
|
|
const orgs = appModel.topAppModel.orgs;
|
|
|
|
|
|
|
|
return [
|
2022-12-06 13:57:29 +00:00
|
|
|
menuSubHeader(t("Switch Sites")),
|
2021-11-05 14:47:17 +00:00
|
|
|
dom.forEach(orgs, (org) =>
|
|
|
|
menuItemLink(urlState().setLinkUrl({ org: org.domain || undefined }),
|
|
|
|
cssOrgSelected.cls('', appModel.currentOrg ? org.id === appModel.currentOrg.id : false),
|
|
|
|
getOrgName(org),
|
|
|
|
cssOrgCheckmark('Tick', testId('org-tick')),
|
|
|
|
testId('org'),
|
|
|
|
)
|
|
|
|
),
|
2022-06-08 17:54:00 +00:00
|
|
|
menuItem(
|
|
|
|
() => appModel.showNewSiteModal(),
|
2021-11-05 14:47:17 +00:00
|
|
|
menuIcon('Plus'),
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Create new team site"),
|
2021-11-05 14:47:17 +00:00
|
|
|
testId('create-new-site'),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
const cssOrgSelected = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.siteSwitcherActiveBg};
|
|
|
|
color: ${theme.siteSwitcherActiveFg};
|
2021-11-05 14:47:17 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssOrgCheckmark = styled(icon, `
|
|
|
|
flex: none;
|
|
|
|
margin-left: 16px;
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.siteSwitcherActiveFg};
|
2021-11-05 14:47:17 +00:00
|
|
|
display: none;
|
|
|
|
.${cssOrgSelected.className} > & {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
`);
|