mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Site Switcher and Other Sites
Summary: A new section, Other Sites, will now be shown on the All Documents page when: - A user is on a personal site and has access to other team sites. - A user is on a public site with view access only. In addition, a site switcher is now available by clicking the site name in the top-left section of the UI next to the Grist logo. It works much like the switcher in the Account menu. Test Plan: Browser tests. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2979
This commit is contained in:
@@ -8,7 +8,7 @@ import {GristLoadConfig} from 'app/common/gristUrls';
|
||||
import {FullUser} from 'app/common/LoginSessionAPI';
|
||||
import {LocalPlugin} from 'app/common/plugin';
|
||||
import {getOrgName, Organization, OrgError, UserAPI, UserAPIImpl} from 'app/common/UserAPI';
|
||||
import {Computed, Disposable, Observable, subscribe} from 'grainjs';
|
||||
import {bundleChanges, Computed, Disposable, Observable, subscribe} from 'grainjs';
|
||||
|
||||
export {reportError} from 'app/client/models/errors';
|
||||
|
||||
@@ -29,6 +29,9 @@ export interface TopAppModel {
|
||||
// different parts of the code aren't using different users/orgs while the switch is pending.
|
||||
appObs: Observable<AppModel|null>;
|
||||
|
||||
orgs: Observable<Organization[]>;
|
||||
users: Observable<FullUser[]>;
|
||||
|
||||
// Reinitialize the app. This is called when org or user changes.
|
||||
initialize(): void;
|
||||
|
||||
@@ -68,6 +71,8 @@ export class TopAppModelImpl extends Disposable implements TopAppModel {
|
||||
public readonly currentSubdomain = Computed.create(this, urlState().state, (use, s) => s.org);
|
||||
public readonly notifier = Notifier.create(this);
|
||||
public readonly appObs = Observable.create<AppModel|null>(this, null);
|
||||
public readonly orgs = Observable.create<Organization[]>(this, []);
|
||||
public readonly users = Observable.create<FullUser[]>(this, []);
|
||||
public readonly plugins: LocalPlugin[] = [];
|
||||
private readonly _gristConfig?: GristLoadConfig;
|
||||
|
||||
@@ -85,6 +90,8 @@ export class TopAppModelImpl extends Disposable implements TopAppModel {
|
||||
// and the FullUser to use for it (the user may change when switching orgs).
|
||||
this.autoDispose(subscribe(this.currentSubdomain, (use) => this.initialize()));
|
||||
this.plugins = this._gristConfig?.plugins || [];
|
||||
|
||||
this._fetchUsersAndOrgs().catch(reportError);
|
||||
}
|
||||
|
||||
public initialize(): void {
|
||||
@@ -146,6 +153,15 @@ export class TopAppModelImpl extends Disposable implements TopAppModel {
|
||||
AppModelImpl.create(this.appObs, this, null, null, {error: err.message, status: err.status || 500});
|
||||
}
|
||||
}
|
||||
|
||||
private async _fetchUsersAndOrgs() {
|
||||
const data = await this.api.getSessionAll();
|
||||
if (this.isDisposed()) { return; }
|
||||
bundleChanges(() => {
|
||||
this.users.set(data.users);
|
||||
this.orgs.set(data.orgs);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AppModelImpl extends Disposable implements AppModel {
|
||||
|
||||
Reference in New Issue
Block a user