(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:
Jarosław Sadziński
2023-09-07 15:11:33 +02:00
parent 3dadf93c98
commit 4ead16176f
3 changed files with 34 additions and 5 deletions

View File

@@ -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.")});
}