Skip to content

Commit 9845835

Browse files
authored
🐛 [Frontend] Conversations: fixes (#8168)
1 parent d928d88 commit 9845835

File tree

8 files changed

+55
-35
lines changed

8 files changed

+55
-35
lines changed

services/static-webserver/client/source/class/osparc/conversation/Conversation.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ qx.Class.define("osparc.conversation.Conversation", {
6464
__messages: null,
6565
__nextRequestParams: null,
6666
__messagesTitle: null,
67+
__messageScroll: null,
6768
__messagesList: null,
6869
__loadMoreMessages: null,
6970

@@ -147,10 +148,15 @@ qx.Class.define("osparc.conversation.Conversation", {
147148
this.__messagesTitle = new qx.ui.basic.Label();
148149
this._add(this.__messagesTitle);
149150

151+
// add spacer to keep the messages list at the bottom
152+
this._add(new qx.ui.core.Spacer(), {
153+
flex: 100 // high number to keep even a one message list at the bottom
154+
});
155+
150156
this.__messagesList = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({
151157
alignY: "middle"
152158
});
153-
const scrollView = new qx.ui.container.Scroll();
159+
const scrollView = this.__messageScroll = new qx.ui.container.Scroll();
154160
scrollView.add(this.__messagesList);
155161
this._add(scrollView, {
156162
flex: 1
@@ -197,7 +203,8 @@ qx.Class.define("osparc.conversation.Conversation", {
197203

198204
__reloadMessages: function(removeMessages = true) {
199205
if (this.getConversationId() === null) {
200-
this.__messagesTitle.setValue(this.tr("No messages yet"));
206+
// temporary conversation page
207+
this.__messagesTitle.setValue(this.tr("No Messages yet"));
201208
this.__messagesList.hide();
202209
this.__loadMoreMessages.hide();
203210
return;
@@ -217,7 +224,7 @@ qx.Class.define("osparc.conversation.Conversation", {
217224
const messages = resp["data"];
218225
messages.forEach(message => this.addMessage(message));
219226
this.__nextRequestParams = resp["_links"]["next"];
220-
if (this.__nextRequestParams === null) {
227+
if (this.__nextRequestParams === null && this.__loadMoreMessages) {
221228
this.__loadMoreMessages.exclude();
222229
}
223230
})
@@ -226,7 +233,9 @@ qx.Class.define("osparc.conversation.Conversation", {
226233

227234
__updateMessagesNumber: function() {
228235
const nMessages = this.__messages.filter(msg => msg["type"] === "MESSAGE").length;
229-
if (nMessages === 1) {
236+
if (nMessages === 0) {
237+
this.__messagesTitle.setValue(this.tr("No Messages yet"));
238+
} else if (nMessages === 1) {
230239
this.__messagesTitle.setValue(this.tr("1 Message"));
231240
} else if (nMessages > 1) {
232241
this.__messagesTitle.setValue(nMessages + this.tr(" Messages"));
@@ -243,9 +252,9 @@ qx.Class.define("osparc.conversation.Conversation", {
243252
return;
244253
}
245254

246-
// determine insertion index for most‐recent‐first order
255+
// determine insertion index for latest‐first order
247256
const newTime = new Date(message["created"]);
248-
let insertAt = this.__messages.findIndex(m => new Date(m["created"]) < newTime);
257+
let insertAt = this.__messages.findIndex(m => new Date(m["created"]) > newTime);
249258
if (insertAt === -1) {
250259
insertAt = this.__messages.length;
251260
}
@@ -270,6 +279,12 @@ qx.Class.define("osparc.conversation.Conversation", {
270279
this.__messagesList.addAt(control, insertAt);
271280
}
272281

282+
// scroll to bottom
283+
// add timeout to ensure the scroll happens after the UI is updated
284+
setTimeout(() => {
285+
this.__messageScroll.scrollToY(this.__messageScroll.getChildControl("pane").getScrollMaxY());
286+
}, 50);
287+
273288
this.__updateMessagesNumber();
274289
},
275290

services/static-webserver/client/source/class/osparc/data/model/Node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ qx.Class.define("osparc.data.model.Node", {
718718
});
719719
} else {
720720
this.fireDataEvent("projectDocumentChanged", {
721-
"op": "delete",
721+
"op": "remove",
722722
"path": `/ui/workbench/${this.getNodeId()}/marker`,
723723
"osparc-resource": "ui",
724724
});

services/static-webserver/client/source/class/osparc/data/model/Study.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -573,19 +573,21 @@ qx.Class.define("osparc.data.model.Study", {
573573
// Do not listen to output related backend updates if the node is a frontend node.
574574
// The frontend controls its output values, progress and states.
575575
// If a File Picker is uploading a file, the backend could override the current state with some older state.
576-
if (node && nodeData && !osparc.data.model.Node.isFrontend(node.getMetaData())) {
577-
node.setOutputData(nodeData.outputs);
578-
if ("progress" in nodeData) {
579-
const progress = Number.parseInt(nodeData["progress"]);
580-
node.getStatus().setProgress(progress);
576+
if (node) {
577+
if (nodeData && !osparc.data.model.Node.isFrontend(node.getMetaData())) {
578+
node.setOutputData(nodeData.outputs);
579+
if ("progress" in nodeData) {
580+
const progress = Number.parseInt(nodeData["progress"]);
581+
node.getStatus().setProgress(progress);
582+
}
583+
node.populateStates(nodeData);
584+
}
585+
if ("errors" in nodeUpdatedData) {
586+
const errors = nodeUpdatedData["errors"];
587+
node.setErrors(errors);
588+
} else {
589+
node.setErrors([]);
581590
}
582-
node.populateStates(nodeData);
583-
}
584-
if (node && "errors" in nodeUpdatedData) {
585-
const errors = nodeUpdatedData["errors"];
586-
node.setErrors(errors);
587-
} else {
588-
node.setErrors([]);
589591
}
590592
},
591593

services/static-webserver/client/source/class/osparc/data/model/StudyUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
143143
if (annotationId in this.getAnnotations()) {
144144
const annotation = this.getAnnotations()[annotationId]
145145
this.fireDataEvent("projectDocumentChanged", {
146-
"op": "delete",
146+
"op": "remove",
147147
"path": `/ui/annotations/${annotation.getId()}`,
148148
"osparc-resource": "study-ui",
149149
});

services/static-webserver/client/source/class/osparc/data/model/Workbench.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ qx.Class.define("osparc.data.model.Workbench", {
320320
this.__addNode(node);
321321

322322
node.populateNodeData();
323-
this.giveUniqueNameToNode(node, node.getLabel());
323+
this.__giveUniqueNameToNode(node, node.getLabel());
324324
node.checkState();
325325

326326
return node;
@@ -653,15 +653,15 @@ qx.Class.define("osparc.data.model.Workbench", {
653653
return false;
654654
},
655655

656-
giveUniqueNameToNode: function(node, label, suffix = 2) {
656+
__giveUniqueNameToNode: function(node, label, suffix = 2) {
657657
const newLabel = label + "_" + suffix;
658658
const allModels = this.getNodes();
659659
const nodes = Object.values(allModels);
660660
for (const node2 of nodes) {
661661
if (node2.getNodeId() !== node.getNodeId() &&
662662
node2.getLabel().localeCompare(node.getLabel()) === 0) {
663663
node.setLabel(newLabel);
664-
this.giveUniqueNameToNode(node, label, suffix+1);
664+
this.__giveUniqueNameToNode(node, label, suffix+1);
665665
}
666666
}
667667
},
@@ -720,7 +720,7 @@ qx.Class.define("osparc.data.model.Workbench", {
720720

721721
nodeIds.forEach(nodeId => {
722722
const node = this.getNode(nodeId);
723-
this.giveUniqueNameToNode(node, node.getLabel());
723+
this.__giveUniqueNameToNode(node, node.getLabel());
724724
});
725725
});
726726
},

services/static-webserver/client/source/class/osparc/study/Conversations.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ qx.Class.define("osparc.study.Conversations", {
221221

222222
__addToPages: function(conversationPage) {
223223
const conversationsLayout = this.getChildControl("conversations-layout");
224+
if (conversationsLayout.getChildren().length === 1) {
225+
// remove the temporary conversation page
226+
if (conversationsLayout.getChildren()[0].getConversationId() === null) {
227+
conversationsLayout.remove(conversationsLayout.getChildren()[0]);
228+
}
229+
}
224230
conversationsLayout.add(conversationPage);
225231

226232
if (this.__newConversationButton === null) {
@@ -246,8 +252,11 @@ qx.Class.define("osparc.study.Conversations", {
246252
conversationsLayout.getChildControl("bar").add(newConversationButton);
247253
}
248254
// remove and add to move to last position
249-
conversationsLayout.getChildControl("bar").remove(this.__newConversationButton);
250-
conversationsLayout.getChildControl("bar").add(this.__newConversationButton);
255+
const bar = conversationsLayout.getChildControl("bar");
256+
if (bar.indexOf(this.__newConversationButton) > -1) {
257+
bar.remove(this.__newConversationButton);
258+
}
259+
bar.add(this.__newConversationButton);
251260
},
252261

253262
__removeConversationPage: function(conversationId, changeSelection = false) {

services/static-webserver/client/source/class/osparc/workbench/Annotation.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,8 @@ qx.Class.define("osparc.workbench.Annotation", {
276276
const serializeData = {
277277
type: this.getType(),
278278
attributes: this.getAttributes(),
279+
color: this.getColor(), // TYPES.NOTE and TYPES.CONVERSATION do not need a color but backend expects it
279280
};
280-
if ([
281-
this.self().TYPES.RECT,
282-
this.self().TYPES.TEXT,
283-
this.self().TYPES.NOTE,
284-
].includes(this.getType())) {
285-
serializeData.color = this.getColor();
286-
}
287281
return serializeData;
288282
}
289283
}

services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
346346

347347
__addNode: async function(service, pos) {
348348
// render temporary node
349-
let tempNodeUI = this.__createTemporaryNodeUI(pos);
349+
let dashedNodeUI = this.__createTemporaryNodeUI(pos);
350350

351351
let nodeUI = null;
352352
try {
@@ -359,7 +359,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
359359
console.error(err);
360360
} finally {
361361
// remove temporary node
362-
this.__removeTemporaryNodeUI(tempNodeUI);
362+
this.__removeTemporaryNodeUI(dashedNodeUI);
363363
}
364364
return nodeUI;
365365
},

0 commit comments

Comments
 (0)