(core) In make-copy dialog, ensure it's non-saveable while fetching workspaces after a switch of the destination org

Summary:
While switching the destination site in the Duplicate Document dialog, there
were times when it was saveable even though destination workspaces were still
being fetched. This sometimes causes a test failure, with the document getting
saved to a workspace from the previously-selected org.

Test Plan:
Tested manually; reproduced by adding a conditional artificial delay
in _updateWorkspaces helper.

Reviewers: paulfitz, georgegevoian

Reviewed By: paulfitz, georgegevoian

Differential Revision: https://phab.getgrist.com/D3032
This commit is contained in:
Dmitry S 2021-09-20 11:54:01 -04:00
parent a1480faa09
commit cd241a633a

View File

@ -222,8 +222,14 @@ class SaveCopyModal extends Disposable {
*/ */
private async _updateWorkspaces(org: Organization|null) { private async _updateWorkspaces(org: Organization|null) {
this._workspaces.set(null); // Show that workspaces are loading. this._workspaces.set(null); // Show that workspaces are loading.
this._destWS.set(null); // Disable saving while waiting to set a new destination workspace.
try { try {
let wss = org ? await this._app.api.getOrgWorkspaces(org.id) : []; let wss = org ? await this._app.api.getOrgWorkspaces(org.id) : [];
if (this._destOrg.get() !== org) {
// We must have switched the org. Don't update anything; in particularr, keep _workspaces
// and _destWS as null, to show loading/save-disabled status. Let the new fetch update things.
return;
}
// Sort the same way that HomeModel sorts workspaces. // Sort the same way that HomeModel sorts workspaces.
wss = sortBy(wss, wss = sortBy(wss,
(ws) => [ws.isSupportWorkspace, ownerName(this._app, ws).toLowerCase(), ws.name.toLowerCase()]); (ws) => [ws.isSupportWorkspace, ownerName(this._app, ws).toLowerCase(), ws.name.toLowerCase()]);