Skip to content

Commit 1efd09c

Browse files
authored
🐛 [Frontend] Fix: Limit conversation title (50) (#8416)
1 parent 9a67845 commit 1efd09c

File tree

5 files changed

+81
-44
lines changed

5 files changed

+81
-44
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ qx.Class.define("osparc.conversation.AddMessage", {
8585
control = new osparc.editor.MarkdownEditor();
8686
control.addListener("textChanged", () => this.__addCommentPressed(), this);
8787
control.setCompact(true);
88+
control.getChildControl("text-area").set({
89+
maxLength: osparc.data.model.Conversation.MAX_CONTENT_LENGTH,
90+
});
91+
// make it visually connected to the button
8892
control.getChildControl("text-area").getContentElement().setStyles({
8993
"border-top-right-radius": "0px", // no roundness there to match the arrow button
9094
});

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ qx.Class.define("osparc.data.model.Conversation", {
5858
CONVERSATION_MESSAGE_UPDATED: "conversation:message:updated",
5959
CONVERSATION_MESSAGE_DELETED: "conversation:message:deleted",
6060
},
61+
62+
MAX_TITLE_LENGTH: 50,
63+
MAX_CONTENT_LENGTH: 4096,
6164
},
6265

6366
properties: {
@@ -256,9 +259,8 @@ qx.Class.define("osparc.data.model.Conversation", {
256259

257260
renameConversation: function(newName) {
258261
osparc.store.ConversationsSupport.getInstance().renameConversation(this.getConversationId(), newName)
259-
.then(() => {
260-
this.setName(newName);
261-
});
262+
.then(() => this.setName(newName))
263+
.catch(err => osparc.FlashMessenger.logError(err));
262264
},
263265

264266
patchExtraContext: function(extraContext) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ qx.Class.define("osparc.study.ConversationPage", {
111111
visibility: osparc.data.model.Study.canIWrite(this.__studyData["accessRights"]) ? "visible" : "excluded",
112112
});
113113
renameButton.addListener("execute", () => {
114-
const titleEditor = new osparc.widget.Renamer(tabButton.getLabel());
114+
const titleEditor = new osparc.widget.Renamer(tabButton.getLabel()).set({
115+
maxChars: osparc.data.model.Conversation.MAX_TITLE_LENGTH,
116+
});
115117
titleEditor.addListener("labelChanged", e => {
116118
titleEditor.close();
117119
const newLabel = e.getData()["newLabel"];

services/static-webserver/client/source/class/osparc/support/ConversationPage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ qx.Class.define("osparc.support.ConversationPage", {
301301
if (oldName === "null") {
302302
oldName = "";
303303
}
304-
const renamer = new osparc.widget.Renamer(oldName);
304+
const renamer = new osparc.widget.Renamer(oldName).set({
305+
maxChars: osparc.data.model.Conversation.MAX_TITLE_LENGTH,
306+
});
305307
renamer.addListener("labelChanged", e => {
306308
renamer.close();
307309
const newLabel = e.getData()["newLabel"];

services/static-webserver/client/source/class/osparc/widget/Renamer.js

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ qx.Class.define("osparc.widget.Renamer", {
4040
construct: function(oldLabel = "", subtitle = "", winTitle) {
4141
this.base(arguments, winTitle || this.tr("Rename"));
4242

43-
const maxWidth = 350;
44-
const minWidth = 200;
43+
const maxWidth = 400;
44+
const minWidth = 250;
4545
const labelWidth = oldLabel ? Math.min(Math.max(parseInt(oldLabel.length*4), minWidth), maxWidth) : minWidth;
4646
this.set({
4747
layout: new qx.ui.layout.VBox(5),
@@ -63,66 +63,93 @@ qx.Class.define("osparc.widget.Renamer", {
6363
"labelChanged": "qx.event.type.Data"
6464
},
6565

66+
properties: {
67+
maxChars: {
68+
check: "Number",
69+
init: 50,
70+
apply: "__applyMaxChars",
71+
}
72+
},
73+
6674
members: {
67-
__save: null,
75+
_createChildControlImpl: function(id) {
76+
let control;
77+
switch (id) {
78+
case "main-layout":
79+
control = new qx.ui.container.Composite(new qx.ui.layout.HBox(10));
80+
this.add(control);
81+
break;
82+
case "text-field":
83+
control = new qx.ui.form.TextField().set({
84+
placeholder: this.tr("Type text"),
85+
allowGrowX: true
86+
});
87+
this.getChildControl("main-layout").add(control, {
88+
flex: 1
89+
});
90+
break;
91+
case "save-button":
92+
control = new qx.ui.form.Button(this.tr("Save")).set({
93+
appearance: "form-button",
94+
padding: [1, 5]
95+
});
96+
this.getChildControl("main-layout").add(control);
97+
break;
98+
case "subtitle":
99+
control = new qx.ui.basic.Label().set({
100+
font: "text-12"
101+
});
102+
this.add(control);
103+
break;
104+
}
105+
return control || this.base(arguments, id);
106+
},
68107

69108
__populateNodeLabelEditor: function(oldLabel, labelWidth) {
70-
const nodeLabelEditor = new qx.ui.container.Composite(new qx.ui.layout.HBox(10));
71-
72-
// Create a text field in which to edit the data
73-
const labelEditor = new qx.ui.form.TextField(oldLabel).set({
74-
placeholder: this.tr("Type text"),
75-
allowGrowX: true,
76-
minWidth: labelWidth
109+
const textField = this.getChildControl("text-field").set({
110+
value: oldLabel,
111+
minWidth: labelWidth,
77112
});
78-
nodeLabelEditor.add(labelEditor, {
79-
flex: 1
80-
});
81-
82-
this.addListener("appear", e => {
83-
labelEditor.focus();
84-
if (labelEditor.getValue()) {
85-
labelEditor.setTextSelection(0, labelEditor.getValue().length);
86-
}
87-
}, this);
88113

89-
// Create the "Save" button to close the cell editor
90-
const save = this.__save = new qx.ui.form.Button(this.tr("Save"));
91-
save.set({
92-
appearance: "form-button",
93-
padding: [1, 5]
94-
});
95-
save.addListener("execute", e => {
96-
const newLabel = labelEditor.getValue();
114+
const saveButton = this.getChildControl("save-button");
115+
saveButton.addListener("execute", () => {
116+
const newLabel = textField.getValue();
97117
const data = {
98118
newLabel
99119
};
100120
this.fireDataEvent("labelChanged", data);
101121
}, this);
102-
nodeLabelEditor.add(save);
103122

104-
this.add(nodeLabelEditor);
123+
this.addListener("appear", () => {
124+
textField.focus();
125+
if (textField.getValue()) {
126+
textField.setTextSelection(0, textField.getValue().length);
127+
}
128+
}, this);
129+
},
130+
131+
__applyMaxChars: function(value) {
132+
this.getChildControl("text-field").setMaxLength(value);
133+
134+
this.__addSubtitle(this.tr("%1 characters max", value));
105135
},
106136

107-
__addSubtitle: function(subtitleLabel) {
108-
if (subtitleLabel) {
109-
const subtitle = new qx.ui.basic.Label(subtitleLabel).set({
110-
font: "text-12"
111-
});
112-
this.add(subtitle);
137+
__addSubtitle: function(subtitleText) {
138+
if (subtitleText) {
139+
this.getChildControl("subtitle").setValue(subtitleText);
113140
}
114141
},
115142

116143
__attachEventHandlers: function() {
117144
let command = new qx.ui.command.Command("Enter");
118-
command.addListener("execute", e => {
119-
this.__save.execute();
145+
command.addListener("execute", () => {
146+
this.getChildControl("save-button").execute();
120147
command.dispose();
121148
command = null;
122149
});
123150

124151
let commandEsc = new qx.ui.command.Command("Esc");
125-
commandEsc.addListener("execute", e => {
152+
commandEsc.addListener("execute", () => {
126153
this.close();
127154
commandEsc.dispose();
128155
commandEsc = null;

0 commit comments

Comments
 (0)