Skip to content

Commit ee36743

Browse files
authored
🎨 [Frontend] Lazy load stranger-users' metadata (ITISFoundation#7021)
1 parent 37ca873 commit ee36743

File tree

5 files changed

+68
-64
lines changed

5 files changed

+68
-64
lines changed

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

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
148148
return false;
149149
},
150150

151-
populateShareIcon: async function(shareIcon, accessRights) {
151+
populateShareIcon: function(shareIcon, accessRights) {
152152
const gids = Object.keys(accessRights).map(key => parseInt(key));
153153

154154
const groupsStore = osparc.store.Groups.getInstance();
@@ -169,6 +169,17 @@ qx.Class.define("osparc.dashboard.CardBase", {
169169
}
170170

171171
// Tooltip
172+
const canIWrite = osparc.data.model.Study.canIWrite(accessRights);
173+
const myGroupId = groupsStore.getMyGroupId();
174+
if (gids.length === 0 || (gids.length === 1 && gids[0] === myGroupId)) {
175+
if (canIWrite) {
176+
shareIcon.set({
177+
toolTipText: qx.locale.Manager.tr("Share")
178+
});
179+
}
180+
return;
181+
}
182+
172183
const sharedGrps = [];
173184
const groups = [];
174185
groups.push(groupEveryone);
@@ -181,43 +192,44 @@ qx.Class.define("osparc.dashboard.CardBase", {
181192
gids.splice(idx, 1);
182193
}
183194
});
184-
// once the groups were removed, the remaining group ids are users' primary groups ids
185-
const usersStore = osparc.store.Users.getInstance();
186-
const myGroupId = groupsStore.getMyGroupId();
187-
for (let i=0; i<gids.length; i++) {
188-
const gid = gids[i];
189-
if (myGroupId !== gid) {
190-
const user = await usersStore.getUser(gid);
191-
if (user) {
192-
sharedGrps.push(user);
195+
196+
const hint = new osparc.ui.hint.Hint(shareIcon);
197+
shareIcon.addListener("mouseover", async () => {
198+
hint.show();
199+
200+
// lazy load tooltip, this can be an expensive call
201+
202+
// once the groups were removed, the remaining group ids are users' primary groups ids
203+
const usersStore = osparc.store.Users.getInstance();
204+
for (let i=0; i<gids.length; i++) {
205+
const gid = gids[i];
206+
if (myGroupId !== gid) {
207+
const user = await usersStore.getUser(gid);
208+
if (user) {
209+
sharedGrps.push(user);
210+
}
193211
}
194212
}
195-
}
196213

197-
const canIWrite = osparc.data.model.Study.canIWrite(accessRights);
198-
if (sharedGrps.length === 0) {
199-
if (canIWrite) {
200-
shareIcon.set({
201-
toolTipText: qx.locale.Manager.tr("Share")
202-
});
203-
}
204-
return;
205-
}
206-
const sharedGrpLabels = [];
207-
const maxItems = 6;
208-
for (let i=0; i<sharedGrps.length; i++) {
209-
if (i > maxItems) {
210-
sharedGrpLabels.push("...");
211-
break;
212-
}
213-
const sharedGrpLabel = sharedGrps[i].getLabel();
214-
if (!sharedGrpLabels.includes(sharedGrpLabel)) {
215-
sharedGrpLabels.push(sharedGrpLabel);
214+
if (hint.getText() === "") {
215+
const sharedGrpLabels = [];
216+
const maxItems = 6;
217+
for (let i=0; i<sharedGrps.length; i++) {
218+
if (i > maxItems) {
219+
sharedGrpLabels.push("...");
220+
break;
221+
}
222+
const sharedGrpLabel = sharedGrps[i].getLabel();
223+
if (!sharedGrpLabels.includes(sharedGrpLabel)) {
224+
sharedGrpLabels.push(sharedGrpLabel);
225+
}
226+
}
227+
const hintText = sharedGrpLabels.join("<br>");
228+
if (hintText) {
229+
hint.setText(hintText);
230+
}
216231
}
217-
}
218-
const hintText = sharedGrpLabels.join("<br>");
219-
const hint = new osparc.ui.hint.Hint(shareIcon, hintText);
220-
shareIcon.addListener("mouseover", () => hint.show(), this);
232+
}, this);
221233
shareIcon.addListener("mouseout", () => hint.exclude(), this);
222234
},
223235
},

‎services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,15 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
208208

209209
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
210210
const membersList = [];
211-
const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(true);
212211
const canIWrite = wallet.getMyAccessRights()["write"];
213-
wallet.getAccessRights().forEach(accessRights => {
212+
const accessRightss = wallet.getAccessRights();
213+
const usersStore = osparc.store.Users.getInstance();
214+
for (let i=0; i<Object.keys(accessRightss).length; i++) {
215+
const accessRights = accessRightss[i];
214216
const gid = parseInt(accessRights["gid"]);
215-
if (Object.prototype.hasOwnProperty.call(potentialCollaborators, gid)) {
216-
// only users or groupMe
217-
const collab = potentialCollaborators[gid];
217+
// only users or groupMe
218+
const collab = await usersStore.getUser(gid);
219+
if (collab) {
218220
const collaborator = {};
219221
collaborator["userId"] = gid === myGroupId ? osparc.auth.Data.getInstance().getUserId() : collab.getUserId();
220222
collaborator["groupId"] = collab.getGroupId();
@@ -250,7 +252,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
250252
collaborator["showOptions"] = Boolean(options.length);
251253
membersList.push(collaborator);
252254
}
253-
});
255+
}
254256
membersList.sort(this.self().sortWalletMembers);
255257
membersList.forEach(member => membersModel.append(qx.data.marshal.Json.createModel(member)));
256258
},

‎services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,6 @@ qx.Class.define("osparc.filter.OrganizationsAndMembers", {
5959
return selectedGIDs;
6060
},
6161

62-
reloadVisibleCollaborators: function(collaboratorsToBeRemoved = null) {
63-
if (collaboratorsToBeRemoved) {
64-
this.__collaboratorsToBeRemoved = collaboratorsToBeRemoved.map(collaboratorToBeRemoved => parseInt(collaboratorToBeRemoved));
65-
}
66-
67-
osparc.store.Groups.getInstance().getPotentialCollaborators()
68-
.then(potentialCollaborators => {
69-
this.__visibleCollaborators = potentialCollaborators;
70-
this.__addOrgsAndMembers();
71-
});
72-
},
73-
7462
__addOrgsAndMembers: function() {
7563
this.reset();
7664

‎services/static-webserver/client/source/class/osparc/share/Collaborators.js‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ qx.Class.define("osparc.share.Collaborators", {
392392
return null;
393393
},
394394

395-
_reloadCollaboratorsList: function() {
395+
_reloadCollaboratorsList: async function() {
396396
// reload "Share with..." list
397397
if (this.__addCollaborators) {
398398
const serializedDataCopy = osparc.utils.Utils.deepCloneObject(this._serializedDataCopy);
@@ -412,10 +412,17 @@ qx.Class.define("osparc.share.Collaborators", {
412412
const accessRights = this._serializedDataCopy["accessRights"];
413413
const collaboratorsList = [];
414414
const showOptions = this.__canIChangePermissions();
415-
const allGroupsAndUsers = groupsStore.getAllGroupsAndUsers();
416-
Object.keys(accessRights).forEach(gid => {
417-
if (gid in allGroupsAndUsers) {
418-
const collab = allGroupsAndUsers[gid];
415+
const allGroups = groupsStore.getAllGroups();
416+
const usersStore = osparc.store.Users.getInstance();
417+
for (let i=0; i<Object.keys(accessRights).length; i++) {
418+
const gid = parseInt(Object.keys(accessRights)[i]);
419+
let collab = null;
420+
if (gid in allGroups) {
421+
collab = allGroups[gid];
422+
} else {
423+
collab = await usersStore.getUser(gid);
424+
}
425+
if (collab) {
419426
// Do not override collaborator object
420427
const collaborator = {
421428
"gid": collab.getGroupId(),
@@ -436,7 +443,7 @@ qx.Class.define("osparc.share.Collaborators", {
436443
collaborator["resourceType"] = this._resourceType;
437444
collaboratorsList.push(collaborator);
438445
}
439-
});
446+
}
440447
collaboratorsList.sort(this.self().sortStudyOrServiceCollabs);
441448
collaboratorsList.forEach(c => this.__collaboratorsModel.append(qx.data.marshal.Json.createModel(c)));
442449
},

‎services/static-webserver/client/source/class/osparc/store/Groups.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ qx.Class.define("osparc.store.Groups", {
131131
})
132132
},
133133

134-
getAllGroupsAndUsers: function() {
134+
getAllGroups: function() {
135135
const allGroupsAndUsers = {};
136136

137137
const groupEveryone = this.getEveryoneGroup();
@@ -147,11 +147,6 @@ qx.Class.define("osparc.store.Groups", {
147147
allGroupsAndUsers[organization.getGroupId()] = organization;
148148
});
149149

150-
const users = osparc.store.Users.getInstance().getUsers();
151-
users.forEach(user => {
152-
allGroupsAndUsers[user.getGroupId()] = user;
153-
});
154-
155150
return allGroupsAndUsers;
156151
},
157152

0 commit comments

Comments
 (0)