Skip to content

Commit 5fcf4dc

Browse files
committed
didContextChange
1 parent bc3464a commit 5fcf4dc

File tree

1 file changed

+38
-16
lines changed
  • services/static-webserver/client/source/class/osparc/dashboard

1 file changed

+38
-16
lines changed

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
225225
.then(resp => {
226226
// Context might have been changed while waiting for the response.
227227
// The new call is on the way, therefore this response can be ignored.
228-
const reqParams = osparc.utils.Utils.deepCloneObject(resp["params"]["url"]);
229-
delete reqParams["limit"];
230-
delete reqParams["offset"];
231-
const currentParams = this.__getRequestParams();
232-
if (JSON.stringify(reqParams) !== JSON.stringify(currentParams)) {
233-
// it did change
234-
console.log("context changed");
228+
const contextChanged = this.__didContextChange(resp["params"]["url"]);
229+
if (contextChanged) {
235230
if (this._resourcesContainer.getFlatList()) {
236231
this._resourcesContainer.getFlatList().nextRequest = null;
237232
}
@@ -613,16 +608,43 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
613608
}, this);
614609
},
615610

611+
__didContextChange: function(reqParams) {
612+
// not needed for the comparison
613+
delete reqParams["type"];
614+
delete reqParams["limit"];
615+
delete reqParams["offset"];
616+
617+
// check the entries in currentParams are the same as the reqParams
618+
const currentParams = this.__getRequestParams();
619+
let sameContext = true;
620+
Object.entries(currentParams).forEach(([key, value]) => {
621+
sameContext &= key in reqParams && reqParams[key] === value;
622+
});
623+
return !sameContext;
624+
},
625+
616626
__getNextPageParams: function() {
617-
if ("nextRequest" in this._resourcesContainer.getFlatList() &&
618-
this._resourcesContainer.getFlatList().nextRequest !== null &&
619-
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset") &&
620-
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
621-
) {
622-
return {
623-
offset: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset"),
624-
limit: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
625-
};
627+
if (this._resourcesContainer.getFlatList() && this._resourcesContainer.getFlatList().nextRequest) {
628+
// Context might have been changed while waiting for the response.
629+
// The new call is on the way, therefore this response can be ignored.
630+
const url = new URL(this._resourcesContainer.getFlatList().nextRequest);
631+
const urlSearchParams = new URLSearchParams(url.search);
632+
const urlParams = {};
633+
for (const [snakeKey, value] of urlSearchParams.entries()) {
634+
const key = osparc.utils.Utils.snakeToCamel(snakeKey);
635+
urlParams[key] = value === "null" ? null : value;
636+
}
637+
const contextChanged = this.__didContextChange(urlParams);
638+
if (
639+
!contextChanged &&
640+
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset") &&
641+
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
642+
) {
643+
return {
644+
offset: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset"),
645+
limit: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
646+
};
647+
}
626648
}
627649
return null;
628650
},

0 commit comments

Comments
 (0)