DEV: Convert `site-setting-default-categories` modal to component-based API (#22968)

This commit is contained in:
Isaac Janzen 2023-08-10 04:31:34 -05:00 committed by GitHub
parent e7dee94c5c
commit c280c1c52b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 56 deletions

View File

@ -0,0 +1,23 @@
<DModal
class="incoming-emails"
@title={{html-safe @model.siteSetting.key}}
@closeModal={{this.cancel}}
>
<:body>
{{i18n
"admin.site_settings.default_categories.modal_description"
count=@model.siteSetting.count
}}
</:body>
<:footer>
<DButton
@action={{this.updateExistingUsers}}
class="btn-primary"
@label="admin.site_settings.default_categories.modal_yes"
/>
<DButton
@action={{this.cancel}}
@label="admin.site_settings.default_categories.modal_no"
/>
</:footer>
</DModal>

View File

@ -0,0 +1,16 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
export default class SiteSettingDefaultCategories extends Component {
@action
updateExistingUsers() {
this.args.model.setUpdateExistingUsers(true);
this.args.closeModal();
}
@action
cancel() {
this.args.model.setUpdateExistingUsers(false);
this.args.closeModal();
}
}

View File

@ -1,8 +0,0 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import ModalUpdateExistingUsers from "discourse/mixins/modal-update-existing-users";
export default class SiteSettingDefaultCategoriesController extends Controller.extend(
ModalFunctionality,
ModalUpdateExistingUsers
) {}

View File

@ -7,10 +7,11 @@ import { ajax } from "discourse/lib/ajax";
import { categoryLinkHTML } from "discourse/helpers/category-link";
import discourseComputed, { bind } from "discourse-common/utils/decorators";
import { htmlSafe } from "@ember/template";
import showModal from "discourse/lib/show-modal";
import { warn } from "@ember/debug";
import { action } from "@ember/object";
import { splitString } from "discourse/lib/utilities";
import { inject as service } from "@ember/service";
import SiteSettingDefaultCategoriesModal from "../components/modal/site-setting-default-categories";
const CUSTOM_TYPES = [
"bool",
@ -74,6 +75,8 @@ const DEFAULT_USER_PREFERENCES = [
];
export default Mixin.create({
modal: service(),
site: service(),
attributeBindings: ["setting.setting:data-setting"],
classNameBindings: [":row", ":setting", "overridden", "typeClass"],
validationMessage: null,
@ -190,22 +193,24 @@ export default Mixin.create({
});
const count = result.user_count;
if (count > 0) {
const controller = showModal("site-setting-default-categories", {
model: { count, key: key.replaceAll("_", " ") },
admin: true,
});
controller.set("onClose", () => {
this.updateExistingUsers = controller.updateExistingUsers;
this.save();
await this.modal.show(SiteSettingDefaultCategoriesModal, {
model: {
siteSetting: { count, key: key.replaceAll("_", " ") },
setUpdateExistingUsers: this.setUpdateExistingUsers,
},
});
this.save();
} else {
await this.save();
}
},
@action
setUpdateExistingUsers(value) {
this.updateExistingUsers = value;
},
@action
async save() {
try {

View File

@ -1,18 +0,0 @@
<DModalBody @class="incoming-emails" @rawTitle={{this.model.key}}>
{{i18n
"admin.site_settings.default_categories.modal_description"
count=this.model.count
}}
</DModalBody>
<div class="modal-footer">
<DButton
@action={{action "updateExistingUsers"}}
@class="btn-primary"
@label="admin.site_settings.default_categories.modal_yes"
/>
<DButton
@action={{action "cancel"}}
@label="admin.site_settings.default_categories.modal_no"
/>
</div>

View File

@ -1,19 +0,0 @@
import Mixin from "@ember/object/mixin";
export default Mixin.create({
onShow() {
this.set("updateExistingUsers", null);
},
actions: {
updateExistingUsers() {
this.set("updateExistingUsers", true);
this.send("closeModal");
},
cancel() {
this.set("updateExistingUsers", false);
this.send("closeModal");
},
},
});

View File

@ -48,7 +48,6 @@ const KNOWN_LEGACY_MODALS = [
"topic-summary",
"user-status",
"admin-penalize-user",
"site-setting-default-categories",
"admin-badge-preview",
"admin-edit-badge-groupings",
"admin-reseed",