mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Showing workspace selector on duplicate document popup
Summary: Duplicate document popup wasn't offering workspace selection for personal orgs. Also, when workspace was removed, the URL wasn't updated which left user with an error page `workspace not found`. Test Plan: Updated Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D4031
This commit is contained in:
parent
3dadf93c98
commit
4ead16176f
@ -87,6 +87,7 @@ export function createHomeLeftPane(leftPanelOpen: Observable<boolean>, home: Hom
|
||||
testId('dm-workspace-options'),
|
||||
),
|
||||
testId('dm-workspace'),
|
||||
dom.cls('test-dm-workspace-selected', (use) => use(home.currentWSId) === ws.id),
|
||||
),
|
||||
cssPageEntry.cls('-renaming', isRenaming),
|
||||
dom.maybe(isRenaming, () =>
|
||||
@ -218,7 +219,23 @@ function addMenu(home: HomeModel, creating: Observable<boolean>): DomElementArg[
|
||||
function workspaceMenu(home: HomeModel, ws: Workspace, renaming: Observable<Workspace|null>) {
|
||||
function deleteWorkspace() {
|
||||
confirmModal(t("Delete {{workspace}} and all included documents?", {workspace: ws.name}), t("Delete"),
|
||||
() => home.deleteWorkspace(ws.id, false),
|
||||
async () => {
|
||||
let all = home.workspaces.get();
|
||||
const index = all.findIndex((w) => w.id === ws.id);
|
||||
const selected = home.currentWSId.get() === ws.id;
|
||||
await home.deleteWorkspace(ws.id, false);
|
||||
// If workspace was not selected, don't do navigation.
|
||||
if (!selected) { return; }
|
||||
all = home.workspaces.get();
|
||||
if (!all.length) {
|
||||
// There was only one workspace, navigate to all docs.
|
||||
await urlState().pushUrl({homePage: 'all'});
|
||||
} else {
|
||||
// Maintain the index.
|
||||
const newIndex = Math.max(0, Math.min(index, all.length - 1));
|
||||
await urlState().pushUrl({ws: all[newIndex].id});
|
||||
}
|
||||
},
|
||||
{explanation: t("Workspace will be moved to Trash.")});
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,20 @@ class SaveCopyModal extends Disposable {
|
||||
private _saveDisabled = Computed.create(this, this._destWS, this._destName, (use, ws, name) =>
|
||||
(!name.trim() || !ws || !roles.canEdit(ws.access)));
|
||||
|
||||
// Only show workspaces for team sites, since they are not a feature of personal orgs.
|
||||
private _showWorkspaces = Computed.create(this, this._destOrg, (use, org) => Boolean(org && !org.owner));
|
||||
private _showWorkspaces = Computed.create(this, this._destOrg, (use, org) => {
|
||||
// Workspace are available for personal and team sites now, but there are legacy sites without it.
|
||||
// Make best effort to figure out if they are disabled, but if we don't have the info, show the selector.
|
||||
if (!org) {
|
||||
return false;
|
||||
}
|
||||
// We won't have info about any other org except the one we are at.
|
||||
if (org.id === this._app.currentOrg?.id) {
|
||||
const workspaces = this._app.currentOrg.billingAccount?.product.features.workspaces ?? true;
|
||||
const numberAllowed = this._app.currentOrg.billingAccount?.product.features.maxWorkspacesPerOrg ?? 2;
|
||||
return workspaces && numberAllowed > 1;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// If orgs is non-null, then we show a selector for orgs.
|
||||
constructor(private _params: SaveCopyModalParams) {
|
||||
@ -144,7 +156,8 @@ class SaveCopyModal extends Disposable {
|
||||
// Set _destOrg to an Organization object from _orgs array; there should be one equivalent
|
||||
// to currentOrg, but we need the actual object for select() to recognize it as selected.
|
||||
const orgId = this._app.currentOrg.id;
|
||||
this._destOrg.set(this._orgs.find((org) => org.id === orgId) || this._orgs[0]);
|
||||
const newOrg = this._orgs.find((org) => org.id === orgId) || this._orgs[0];
|
||||
this._destOrg.set(newOrg);
|
||||
}
|
||||
this.autoDispose(subscribe(this._destOrg, (use, org) => this._updateWorkspaces(org).catch(reportError)));
|
||||
}
|
||||
|
@ -202,7 +202,6 @@ describe("DuplicateDocument", function() {
|
||||
await driver.find('.test-copy-dest-org .test-select-open').click();
|
||||
await driver.findContent('.test-select-menu li', 'Personal').click();
|
||||
await gu.waitForServer();
|
||||
assert.equal(await driver.find('.test-copy-dest-workspace').isPresent(), false);
|
||||
assert.equal(await driver.find('.test-copy-warning').isPresent(), false);
|
||||
assert.equal(await driver.find('.test-modal-confirm').getAttribute('disabled'), null);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user