From cba896aff651aa01c1926515e39ccdd78a32c4df Mon Sep 17 00:00:00 2001 From: Odei Maiz <33152403+odeimaiz@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:41:42 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[Frontend]=20Fix:=20Move=20folde?= =?UTF-8?q?r=20to=20a=20different=20workspace=20and=20subfolder=20(#6903)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/osparc/dashboard/MoveResourceTo.js | 4 +- .../class/osparc/dashboard/StudyBrowser.js | 50 +++--------------- .../dashboard/WorkspacesAndFoldersTree.js | 30 ++++------- .../desktop/preferences/pages/GeneralPage.js | 5 +- .../source/class/osparc/store/Folders.js | 52 ++++++++++++++++--- 5 files changed, 65 insertions(+), 76 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js b/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js index cd9a98d1d6f..ecd26def377 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js @@ -30,9 +30,9 @@ qx.Class.define("osparc.dashboard.MoveResourceTo", { const workspacesAndFoldersTree = this.getChildControl("workspaces-and-folders-tree"); this.getChildControl("cancel-btn"); - const moveButton = this.getChildControl("move-btn"); - moveButton.setEnabled(false); + const moveButton = this.getChildControl("move-btn"); + moveButton.setEnabled(currentWorkspaceId !== null || currentFolderId !== null); // disable if current location is My Workspace's root workspacesAndFoldersTree.getSelection().addListener("change", () => { const selection = workspacesAndFoldersTree.getSelection(); if (selection.getLength() > 0) { diff --git a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js index 327de47602c..0a25257f247 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js @@ -576,10 +576,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { const destWorkspaceId = data["workspaceId"]; const destFolderId = data["folderId"]; const moveFolder = () => { - Promise.all([ - this.__moveFolderToWorkspace(folderId, destWorkspaceId), - this.__moveFolderToFolder(folderId, destFolderId), - ]) + osparc.store.Folders.getInstance().moveFolderToWorkspace(folderId, destWorkspaceId) // first move to workspace + .then(() => osparc.store.Folders.getInstance().moveFolderToFolder(folderId, destFolderId)) // then move to folder .then(() => this.__reloadFolders()) .catch(err => console.error(err)); } @@ -597,38 +595,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { moveFolderTo.addListener("cancel", () => win.close()); }, - __moveFolderToWorkspace: function(folderId, destWorkspaceId) { - const folder = osparc.store.Folders.getInstance().getFolder(folderId); - if (folder.getWorkspaceId() === destWorkspaceId) { - // resolve right away - return new Promise(resolve => resolve()); - } - const params = { - url: { - folderId, - workspaceId: destWorkspaceId, - } - }; - return osparc.data.Resources.fetch("folders", "moveToWorkspace", params) - .then(() => folder.setWorkspaceId(destWorkspaceId)) - .catch(err => console.error(err)); - }, - - __moveFolderToFolder: function(folderId, destFolderId) { - if (folderId === destFolderId) { - // resolve right away - return new Promise(resolve => resolve()); - } - const folder = osparc.store.Folders.getInstance().getFolder(folderId); - const updatedData = { - name: folder.getName(), - parentFolderId: destFolderId, - }; - return osparc.store.Folders.getInstance().putFolder(folderId, updatedData) - .then(() => folder.setParentFolderId(destFolderId)) - .catch(err => console.error(err)); - }, - _trashFolderRequested: function(folderId) { osparc.store.Folders.getInstance().trashFolder(folderId, this.getCurrentWorkspaceId()) .then(() => { @@ -1243,10 +1209,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { const selection = this._resourcesContainer.getSelection(); selection.forEach(button => { const studyData = button.getResourceData(); - Promise.all([ - this.__moveStudyToWorkspace(studyData, destWorkspaceId), - this.__moveStudyToFolder(studyData, destFolderId), - ]) + this.__moveStudyToWorkspace(studyData, destWorkspaceId) // first move to workspace + .then(() => this.__moveStudyToFolder(studyData, destFolderId)) // then move to folder .then(() => this.__removeFromStudyList(studyData["uuid"])) .catch(err => { console.error(err); @@ -1667,10 +1631,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { const destWorkspaceId = data["workspaceId"]; const destFolderId = data["folderId"]; const moveStudy = () => { - Promise.all([ - this.__moveStudyToWorkspace(studyData, destWorkspaceId), - this.__moveStudyToFolder(studyData, destFolderId), - ]) + this.__moveStudyToWorkspace(studyData, destWorkspaceId) // first move to workspace + .then(() => this.__moveStudyToFolder(studyData, destFolderId)) // then move to folder .then(() => this.__removeFromStudyList(studyData["uuid"])) .catch(err => { console.error(err); diff --git a/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js b/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js index da5a21797f1..01cea4d878c 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js @@ -58,15 +58,6 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", { this.__folderRemoved(folder); }, this); - osparc.store.Folders.getInstance().addListener("folderMoved", e => { - const { - folder, - oldParentFolderId, - } = e.getData(); - this.__folderRemoved(folder, oldParentFolderId); - this.__folderAdded(folder); - }, this); - osparc.store.Workspaces.getInstance().addListener("workspaceAdded", e => { const workspace = e.getData(); this.__addWorkspace(workspace); @@ -299,25 +290,22 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", { } }, - __folderRemoved: function(folder, oldParentFolderId) { + __folderRemoved: function(folder) { // eslint-disable-next-line no-negated-condition - const parentModel = this.__getModel(folder.getWorkspaceId(), oldParentFolderId !== undefined ? oldParentFolderId : folder.getParentFolderId()); + const parentModel = this.__getModel(folder.getWorkspaceId(), folder.getParentFolderId()); if (parentModel) { - const idx = parentModel.getChildren().toArray().findIndex(c => folder.getWorkspaceId() === c.getWorkspaceId() && folder.getFolderId() === c.getFolderId()); + const idx = parentModel.getChildren().toArray().findIndex(c => "getWorkspaceId" in c && folder.getWorkspaceId() === c.getWorkspaceId() && folder.getFolderId() === c.getFolderId()); if (idx > -1) { parentModel.getChildren().removeAt(idx); } } - if (oldParentFolderId === undefined) { - // it was removed, not moved - // remove it from the cached models - const modelFound = this.__getModel(folder.getWorkspaceId(), folder.getFolderId()); - if (modelFound) { - const index = this.__models.indexOf(modelFound); - if (index > -1) { // only splice array when item is found - this.__models.splice(index, 1); // 2nd parameter means remove one item only - } + // remove it from the cached models + const modelFound = this.__getModel(folder.getWorkspaceId(), folder.getFolderId()); + if (modelFound) { + const index = this.__models.indexOf(modelFound); + if (index > -1) { // only splice array when item is found + this.__models.splice(index, 1); // 2nd parameter means remove one item only } } }, diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js index dffafeabc72..70095507e49 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js @@ -27,7 +27,7 @@ qx.Class.define("osparc.desktop.preferences.pages.GeneralPage", { if (osparc.desktop.credits.Utils.areWalletsEnabled()) { this.__addCreditsIndicatorSettings(); } - + const preferences = osparc.Preferences.getInstance(); if (preferences.getLowDiskSpaceThreshold()) { this.__addLowDiskSpaceSetting(); @@ -38,7 +38,7 @@ qx.Class.define("osparc.desktop.preferences.pages.GeneralPage", { } // this.__addJobConcurrencySetting(); - + if (osparc.product.Utils.isS4LProduct() || osparc.product.Utils.isProduct("s4llite")) { this.__addS4LUserPrivacySettings(); } @@ -147,6 +147,7 @@ qx.Class.define("osparc.desktop.preferences.pages.GeneralPage", { allowGrowX: false, enabled: true }); + const preferences = osparc.Preferences.getInstance(); preferences.bind("lowDiskSpaceThreshold", diskUsageSpinner, "value"); diskUsageSpinner.addListener("changeValue", e => osparc.Preferences.patchPreferenceField("lowDiskSpaceThreshold", diskUsageSpinner, e.getData())); diff --git a/services/static-webserver/client/source/class/osparc/store/Folders.js b/services/static-webserver/client/source/class/osparc/store/Folders.js index 4206cb212dd..bf7657a3279 100644 --- a/services/static-webserver/client/source/class/osparc/store/Folders.js +++ b/services/static-webserver/client/source/class/osparc/store/Folders.js @@ -28,7 +28,6 @@ qx.Class.define("osparc.store.Folders", { events: { "folderAdded": "qx.event.type.Data", "folderRemoved": "qx.event.type.Data", - "folderMoved": "qx.event.type.Data", }, statics: { @@ -212,17 +211,56 @@ qx.Class.define("osparc.store.Folders", { }; return osparc.data.Resources.getInstance().fetch("folders", "update", params) .then(folderData => { - this.__addToCache(folderData); - if (updateData.parentFolderId !== oldParentFolderId) { - this.fireDataEvent("folderMoved", { - folder, - oldParentFolderId, - }); + const folderMoved = updateData.parentFolderId !== oldParentFolderId; + if (folderMoved) { + this.fireDataEvent("folderRemoved", folder); + } + this.__addToCache(folderData); // it will update the folder model + if (folderMoved) { + this.fireDataEvent("folderAdded", folder); } }) .catch(console.error); }, + moveFolderToFolder: function(folderId, destFolderId) { + if (folderId === destFolderId) { + // resolve right away + return new Promise(resolve => resolve()); + } + + const folder = this.getFolder(folderId); + const updatedData = { + name: folder.getName(), + parentFolderId: destFolderId, + }; + return this.putFolder(folderId, updatedData) + .then(() => folder.setParentFolderId(destFolderId)) + .catch(err => console.error(err)); + }, + + moveFolderToWorkspace: function(folderId, destWorkspaceId) { + const folder = this.getFolder(folderId); + if (folder.getWorkspaceId() === destWorkspaceId) { + // resolve right away + return new Promise(resolve => resolve()); + } + + const params = { + url: { + folderId, + workspaceId: destWorkspaceId, + } + }; + return osparc.data.Resources.fetch("folders", "moveToWorkspace", params) + .then(() => { + this.fireDataEvent("folderRemoved", folder); + folder.setWorkspaceId(destWorkspaceId); + this.fireDataEvent("folderAdded", folder); + }) + .catch(err => console.error(err)); + }, + getFolder: function(folderId = null) { return this.foldersCached.find(f => f.getFolderId() === folderId); },