Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 493d65a

Browse files
authored
FIX: Diff modal closing along with composer menu on mobile (#803)
The `DiffModal` is triggered after selecting an option in the composer helper menu. After selecting an option, we should close the composer helper menu and only show the diff modal. On mobile, there was an edge-case where `this.args.close()` for was causing the closing of both the `DiffModal` and the `AiComposerHelperMenu`. This PR resolves that by ensuring the menu is closed _first_ asynchronously, followed by opening the relevant modal.
1 parent 03eccbe commit 493d65a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

assets/javascripts/discourse/components/ai-composer-helper-menu.gjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,20 @@ export default class AiComposerHelperMenu extends Component {
109109
}
110110

111111
@action
112-
suggestChanges(option) {
112+
async suggestChanges(option) {
113+
await this.args.close();
114+
113115
if (option.name === "illustrate_post") {
114-
this.modal.show(ThumbnailSuggestion, {
116+
return this.modal.show(ThumbnailSuggestion, {
115117
model: {
116118
mode: option.id,
117119
selectedText: this.args.data.selectedText,
118120
thumbnails: this.thumbnailSuggestions,
119121
},
120122
});
121-
return this.args.close();
122123
}
123124

124-
this.modal.show(ModalDiffModal, {
125+
return this.modal.show(ModalDiffModal, {
125126
model: {
126127
mode: option.id,
127128
selectedText: this.args.data.selectedText,
@@ -130,7 +131,6 @@ export default class AiComposerHelperMenu extends Component {
130131
customPromptValue: this.customPromptValue,
131132
},
132133
});
133-
return this.args.close();
134134
}
135135

136136
@action

spec/system/ai_helper/ai_composer_helper_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,19 @@ def trigger_composer_helper(content)
342342
expect(page).to have_no_css(".d-editor-button-bar button.ai-helper-trigger")
343343
end
344344
end
345+
346+
context "when triggering composer AI helper", mobile: true do
347+
it "should close the composer helper before showing the diff modal" do
348+
visit("/latest")
349+
page.find("#create-topic").click
350+
composer.fill_content(input)
351+
composer.click_toolbar_button("ai-helper-trigger")
352+
353+
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
354+
ai_helper_menu.select_helper_model(CompletionPrompt::TRANSLATE)
355+
expect(ai_helper_menu).to have_no_context_menu
356+
expect(diff_modal).to be_visible
357+
end
358+
end
359+
end
345360
end

0 commit comments

Comments
 (0)