FIX: Ensure 'modern' modal is closed when opening legacy modal (#22689)

e.g. the modernised share-topic modal will attempt to open the `create-invite` modal. Prior to this commit, this mixing of modern/legacy would fail silently, and the create-invite modal was never shown.
This commit is contained in:
David Taylor 2023-07-19 12:22:00 +01:00 committed by GitHub
parent e5bb4bbd59
commit 6fd06bc411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -193,6 +193,8 @@ export default class ModalServiceWithLegacySupport extends ModalService {
return super.show(modal, opts); return super.show(modal, opts);
} }
this.close({ initiatedBy: CLOSE_INITIATED_BY_MODAL_SHOW });
if (!KNOWN_LEGACY_MODALS.includes(modal)) { if (!KNOWN_LEGACY_MODALS.includes(modal)) {
deprecated( deprecated(
`Defining modals using a controller is deprecated. Use the component-based API instead. (modal: ${modal})`, `Defining modals using a controller is deprecated. Use the component-based API instead. (modal: ${modal})`,

View File

@ -12,6 +12,8 @@ import showModal from "discourse/lib/show-modal";
import { registerTemporaryModule } from "../helpers/temporary-module-helper"; import { registerTemporaryModule } from "../helpers/temporary-module-helper";
import { getOwner } from "discourse-common/lib/get-owner"; import { getOwner } from "discourse-common/lib/get-owner";
import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
import Component from "@glimmer/component";
import { setComponentTemplate } from "@glimmer/manager";
function silencedShowModal() { function silencedShowModal() {
return withSilencedDeprecations("discourse.modal-controllers", () => return withSilencedDeprecations("discourse.modal-controllers", () =>
@ -142,6 +144,32 @@ acceptance("Legacy Modal", function (needs) {
"it should not re-use the previous title" "it should not re-use the previous title"
); );
}); });
test("opening legacy modal while modern modal is open", async function (assert) {
registerTemporaryModule(
"discourse/templates/modal/legacy-modal",
hbs`<DModalBody @rawTitle="legacy modal title" />`
);
class ModernModal extends Component {}
setComponentTemplate(
hbs`<DModal @title="modern modal title" />`,
ModernModal
);
await visit("/");
const modalService = getOwner(this).lookup("service:modal");
modalService.show(ModernModal);
await settled();
assert.dom(".d-modal .title").hasText("modern modal title");
silencedShowModal("legacy-modal");
await settled();
assert.dom(".d-modal .title").hasText("legacy modal title");
});
}); });
acceptance("Modal Keyboard Events", function (needs) { acceptance("Modal Keyboard Events", function (needs) {