mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-13 01:23:29 +00:00
DEV: Improve AI bot conversation submit upload handling (#1497)
Try fix a flaky spec in /ai_bot/homepage_spec.rb by using ember data rather than inspecting the DOM directly to see if there are any in-progress uploads. Also add missing translation for in progress uploads warning.
This commit is contained in:
parent
d54cd1f602
commit
6b5ea38644
@ -260,10 +260,11 @@ export default class AiBotConversations extends Component {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
async prepareAndSubmitToBot() {
|
async prepareAndSubmitToBot() {
|
||||||
// Pass uploads to the service before submitting
|
|
||||||
this.aiBotConversationsHiddenSubmit.uploads = this.uploads;
|
|
||||||
try {
|
try {
|
||||||
await this.aiBotConversationsHiddenSubmit.submitToBot();
|
await this.aiBotConversationsHiddenSubmit.submitToBot({
|
||||||
|
uploads: this.uploads,
|
||||||
|
inProgressUploadsCount: this.inProgressUploads.length,
|
||||||
|
});
|
||||||
this.uploads = new TrackedArray();
|
this.uploads = new TrackedArray();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
popupAjaxError(error);
|
popupAjaxError(error);
|
||||||
|
@ -18,7 +18,6 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
|||||||
|
|
||||||
personaId;
|
personaId;
|
||||||
targetUsername;
|
targetUsername;
|
||||||
uploads = [];
|
|
||||||
|
|
||||||
inputValue = "";
|
inputValue = "";
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async submitToBot() {
|
async submitToBot(uploadData) {
|
||||||
if (
|
if (
|
||||||
this.inputValue.length <
|
this.inputValue.length <
|
||||||
this.siteSettings.min_personal_message_post_length
|
this.siteSettings.min_personal_message_post_length
|
||||||
@ -48,7 +47,7 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't submit if there are still uploads in progress
|
// Don't submit if there are still uploads in progress
|
||||||
if (document.querySelector(".ai-bot-upload--in-progress")) {
|
if (uploadData.inProgressUploadsCount > 0) {
|
||||||
return this.dialog.alert({
|
return this.dialog.alert({
|
||||||
message: i18n("discourse_ai.ai_bot.conversations.uploads_in_progress"),
|
message: i18n("discourse_ai.ai_bot.conversations.uploads_in_progress"),
|
||||||
});
|
});
|
||||||
@ -61,10 +60,10 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
|||||||
let rawContent = this.inputValue;
|
let rawContent = this.inputValue;
|
||||||
|
|
||||||
// Append upload markdown if we have uploads
|
// Append upload markdown if we have uploads
|
||||||
if (this.uploads && this.uploads.length > 0) {
|
if (uploadData.uploads && uploadData.uploads.length > 0) {
|
||||||
rawContent += "\n\n";
|
rawContent += "\n\n";
|
||||||
|
|
||||||
this.uploads.forEach((upload) => {
|
uploadData.uploads.forEach((upload) => {
|
||||||
const uploadMarkdown = getUploadMarkdown(upload);
|
const uploadMarkdown = getUploadMarkdown(upload);
|
||||||
rawContent += uploadMarkdown + "\n";
|
rawContent += uploadMarkdown + "\n";
|
||||||
});
|
});
|
||||||
@ -83,7 +82,6 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Reset uploads after successful submission
|
// Reset uploads after successful submission
|
||||||
this.uploads = [];
|
|
||||||
this.inputValue = "";
|
this.inputValue = "";
|
||||||
|
|
||||||
this.appEvents.trigger("discourse-ai:bot-pm-created", {
|
this.appEvents.trigger("discourse-ai:bot-pm-created", {
|
||||||
|
@ -872,6 +872,7 @@ en:
|
|||||||
last_7_days: "Last 7 days"
|
last_7_days: "Last 7 days"
|
||||||
last_30_days: "Last 30 days"
|
last_30_days: "Last 30 days"
|
||||||
upload_files: "Upload files"
|
upload_files: "Upload files"
|
||||||
|
uploads_in_progress: "Cannot submit while uploads are in progress"
|
||||||
sentiments:
|
sentiments:
|
||||||
dashboard:
|
dashboard:
|
||||||
title: "Sentiment"
|
title: "Sentiment"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe "AI Bot - Homepage", type: :system do
|
RSpec.describe "AI Bot - Homepage", type: :system do
|
||||||
|
let(:cdp) { PageObjects::CDP.new }
|
||||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||||
let(:composer) { PageObjects::Components::Composer.new }
|
let(:composer) { PageObjects::Components::Composer.new }
|
||||||
let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
|
let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
|
||||||
@ -164,6 +165,28 @@ RSpec.describe "AI Bot - Homepage", type: :system do
|
|||||||
expect(page).to have_no_css(".ai-bot-upload")
|
expect(page).to have_no_css(".ai-bot-upload")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "shows an error when trying to submit while uploads are in progress" do
|
||||||
|
ai_pm_homepage.visit
|
||||||
|
expect(ai_pm_homepage).to have_homepage
|
||||||
|
|
||||||
|
file_path_1 = file_from_fixtures("logo.png", "images").path
|
||||||
|
file_path_2 = file_from_fixtures("logo.jpg", "images").path
|
||||||
|
|
||||||
|
ai_pm_homepage.input.fill_in(with: "Some message to send to AI with uploads")
|
||||||
|
|
||||||
|
cdp.with_slow_upload do
|
||||||
|
attach_file([file_path_1, file_path_2]) do
|
||||||
|
find(".ai-bot-upload-btn", visible: true).click
|
||||||
|
end
|
||||||
|
expect(page).to have_css(".ai-bot-upload--in-progress", count: 2)
|
||||||
|
|
||||||
|
ai_pm_homepage.submit
|
||||||
|
expect(page).to have_content(
|
||||||
|
I18n.t("js.discourse_ai.ai_bot.conversations.uploads_in_progress"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "allows removing an upload before submission" do
|
it "allows removing an upload before submission" do
|
||||||
ai_pm_homepage.visit
|
ai_pm_homepage.visit
|
||||||
expect(ai_pm_homepage).to have_homepage
|
expect(ai_pm_homepage).to have_homepage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user