From ca824e547edd62b9711d0636f33dfb75fca9b797 Mon Sep 17 00:00:00 2001
From: Antoine Guenet
Date: Fri, 27 Oct 2023 13:23:47 +0200
Subject: [PATCH] [FIX] web_editor: do not base selected alternative on index
When selecting an alternative in the AI Copywriter dialog, what we store
in the state is the index of the message. But that targets a different
message every time we add each new message at the start of the list.
This pushes new messages at the end of the list and only displays them
in reverse order, but also adds an ID to each message so they can be
targeted more robustly.
Part-of: odoo/odoo#139857
---
.../wysiwyg/widgets/chatgpt_alternatives_dialog.js | 5 +++--
.../widgets/chatgpt_alternatives_dialog.xml | 10 +++++-----
.../src/js/wysiwyg/widgets/chatgpt_dialog.js | 7 ++++---
.../js/wysiwyg/widgets/chatgpt_prompt_dialog.js | 14 ++++++++++----
.../js/wysiwyg/widgets/chatgpt_prompt_dialog.xml | 2 +-
5 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js
index 07d46032b5f..ac71dc05a26 100644
--- a/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js
+++ b/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js
@@ -25,7 +25,7 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog {
setup() {
super.setup();
this.state = useState({
- selectedMessage: null,
+ ...this.state,
conversationHistory: [{
role: 'system',
content: 'The user wrote the following text:\n' +
@@ -86,12 +86,13 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog {
content,
});
}
- this.state.messages.unshift({
+ this.state.messages.push({
author: 'assistant',
text: alternative,
isError,
batchId,
mode: this.state.alternativesMode,
+ id: new Date().getTime(),
});
}
}).catch(() => {
diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.xml b/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.xml
index 49d9ed5c303..c398105a2b9 100644
--- a/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.xml
+++ b/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.xml
@@ -23,7 +23,7 @@
Generating alternatives...