From bfe3b1c3b877978b8d09f0da0479031d6e388fd2 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 16 Aug 2024 10:08:58 -0700 Subject: [PATCH] FIX: Modals in composer helper menu not working (#755) --- .../components/ai-composer-helper-menu.gjs | 41 ++++++++----------- .../discourse/components/modal/diff-modal.gjs | 14 +++---- .../modal/thumbnail-suggestions.gjs | 2 +- .../ai_helper/ai_composer_helper_spec.rb | 17 ++++++++ spec/system/page_objects/modals/diff_modal.rb | 4 ++ 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/assets/javascripts/discourse/components/ai-composer-helper-menu.gjs b/assets/javascripts/discourse/components/ai-composer-helper-menu.gjs index f5c4a6c3..c9f26f0a 100644 --- a/assets/javascripts/discourse/components/ai-composer-helper-menu.gjs +++ b/assets/javascripts/discourse/components/ai-composer-helper-menu.gjs @@ -1,6 +1,5 @@ import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; -import { fn } from "@ember/helper"; import { action } from "@ember/object"; import { service } from "@ember/service"; import { modifier } from "ember-modifier"; @@ -17,6 +16,7 @@ import ModalDiffModal from "../components/modal/diff-modal"; import ThumbnailSuggestion from "../components/modal/thumbnail-suggestions"; export default class AiComposerHelperMenu extends Component { + @service modal; @service siteSettings; @service aiComposerHelper; @service currentUser; @@ -29,7 +29,6 @@ export default class AiComposerHelperMenu extends Component { @tracked lastUsedOption = null; @tracked thumbnailSuggestions = null; @tracked showThumbnailModal = false; - @tracked showDiffModal = false; @tracked lastSelectionRange = null; MENU_STATES = this.aiComposerHelper.MENU_STATES; prompts = []; @@ -100,7 +99,16 @@ export default class AiComposerHelperMenu extends Component { { icon: "exchange-alt", label: "discourse_ai.ai_helper.context_menu.view_changes", - action: () => (this.showDiffModal = true), + action: () => + this.modal.show(ModalDiffModal, { + model: { + diff: this.diff, + oldValue: this.initialValue, + newValue: this.newSelectedText, + revert: this.undoAiAction, + confirm: () => this.updateMenuState(this.MENU_STATES.resets), + }, + }), classes: "view-changes", }, { @@ -202,8 +210,12 @@ export default class AiComposerHelperMenu extends Component { if (option.name === "illustrate_post") { this._toggleLoadingState(false); this.closeMenu(); - this.showThumbnailModal = true; this.thumbnailSuggestions = data.thumbnails; + this.modal.show(ThumbnailSuggestion, { + model: { + thumbnails: this.thumbnailSuggestions, + }, + }); } else { this._updateSuggestedByAi(data); } @@ -326,26 +338,5 @@ export default class AiComposerHelperMenu extends Component { /> {{/if}} - - {{#if this.showDiffModal}} - - {{/if}} - - {{#if this.showThumbnailModal}} - - {{/if}} } diff --git a/assets/javascripts/discourse/components/modal/diff-modal.gjs b/assets/javascripts/discourse/components/modal/diff-modal.gjs index 8edf0cfa..66cba0f0 100644 --- a/assets/javascripts/discourse/components/modal/diff-modal.gjs +++ b/assets/javascripts/discourse/components/modal/diff-modal.gjs @@ -9,13 +9,13 @@ export default class ModalDiffModal extends Component { @action triggerConfirmChanges() { this.args.closeModal(); - this.args.confirm(); + this.args.model.confirm(); } @action triggerRevertChanges() { + this.args.model.revert(); this.args.closeModal(); - this.args.revert(); }