A platform for community discussion. Free, open, simple.
DEV: Convert user-notes components to glimmer (#33974)
Jarek Radoszfc9eff6f3c46
diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.gjsindex cae21aabda8..2b76c2e3b46 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.gjs@@ -1,16 +1,17 @@-import Component from "@ember/component";-import { classNames, tagName } from "@ember-decorators/component";+import Component from "@glimmer/component";+import { service } from "@ember/service";import AdminReport from "admin/components/admin-report";-@tagName("div")-@classNames(- "admin-dashboard-moderation-bottom-outlet",- "recent-user-notes-report-table"-)export default class RecentUserNotesReportTable extends Component {+ @service siteSettings;+<template>- {{#if this.siteSettings.user_notes_enabled}}- <AdminReport @dataSourceName="user_notes" @filters={{this.filters}} />- {{/if}}+ <div+ class="admin-dashboard-moderation-bottom-outlet recent-user-notes-report-table"+ >+ {{#if this.siteSettings.user_notes_enabled}}+ <AdminReport @dataSourceName="user_notes" @filters={{@filters}} />+ {{/if}}+ </div></template>}diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-user-controls-after/add-user-notes-button.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-user-controls-after/add-user-notes-button.gjsindex 45be413076e..e74cb7bd000 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-user-controls-after/add-user-notes-button.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/admin-user-controls-after/add-user-notes-button.gjs@@ -1,34 +1,29 @@-import Component from "@ember/component";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";import { action } from "@ember/object";import { service } from "@ember/service";-import { classNames, tagName } from "@ember-decorators/component";import ShowUserNotes from "../../components/show-user-notes";import { showUserNotes } from "../../lib/user-notes";-@tagName("")-@classNames("admin-user-controls-after-outlet", "add-user-notes-button")export default class AddUserNotesButton extends Component {- static shouldRender(args, context) {- const { siteSettings, currentUser } = context;- return siteSettings.user_notes_enabled && currentUser && currentUser.staff;+ static shouldRender(args, { siteSettings, currentUser }) {+ return siteSettings.user_notes_enabled && currentUser?.staff;}@service store;- init() {- super.init(...arguments);- const { model } = this;- this.set(- "userNotesCount",- model.user_notes_count || model.get("custom_fields.user_notes_count") || 0- );- }+ @tracked+ userNotesCount =+ this.args.model.user_notes_count ||+ this.args.model.custom_fields?.user_notes_count ||+ 0;@actionshowUserNotes() {- const user = this.model;- showUserNotes(this.store, user.id, (count) =>- this.set("userNotesCount", count)+ showUserNotes(+ this.store,+ this.args.model.id,+ (count) => (this.userNotesCount = count));}diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/after-reviewable-post-user/show-user-notes-on-flags.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/after-reviewable-post-user/show-user-notes-on-flags.gjsindex c2bed1c1605..d3bf4f297e2 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/after-reviewable-post-user/show-user-notes-on-flags.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/after-reviewable-post-user/show-user-notes-on-flags.gjs@@ -1,62 +1,55 @@-import Component from "@ember/component";-import EmberObject, { action } from "@ember/object";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";import { service } from "@ember/service";-import { classNames, tagName } from "@ember-decorators/component";import DButton from "discourse/components/d-button";import icon from "discourse/helpers/d-icon";import { emojiUrlFor } from "discourse/lib/text";import { i18n } from "discourse-i18n";import { showUserNotes } from "../../lib/user-notes";-@tagName("div")-@classNames("after-reviewable-post-user-outlet", "show-user-notes-on-flags")+const EMOJI_URL = emojiUrlFor("memo");+export default class ShowUserNotesOnFlags extends Component {- static shouldRender(args, context) {- return context.siteSettings.user_notes_enabled && args.user;+ static shouldRender(args, { siteSettings }) {+ return siteSettings.user_notes_enabled && args.user;}@service store;+ @service siteSettings;- init() {- super.init(...arguments);- const model = EmberObject.create(this.user);- const userNotesCount = model.get("custom_fields.user_notes_count") || 0;- this.setProperties({- userNotesCount,- emojiEnabled: this.siteSettings.enable_emoji,- emojiUrl: emojiUrlFor("memo"),- userNotesTitle: i18n("user_notes.show", {- count: userNotesCount,- }),- });- }+ @tracked+ userNotesCount = this.args.user.get("custom_fields.user_notes_count") || 0;@actionshowUserNotes() {- const user = this.user;- showUserNotes(this.store, user.id, (count) =>- this.set("userNotesCount", count)+ showUserNotes(+ this.store,+ this.args.user.id,+ (count) => (this.userNotesCount = count));}<template>- {{#if this.userNotesCount}}- <DButton- @translatedTitle={{this.userNotesTitle}}- @action={{this.showUserNotes}}- class="btn btn-flat"- >- {{#if this.emojiEnabled}}- <img- src={{this.emojiUrl}}- title={{this.userNotesTitle}}- alt- class="emoji"- />- {{else}}- {{icon "pen-to-square"}}- {{/if}}- </DButton>- {{/if}}+ <div class="after-reviewable-post-user-outlet show-user-notes-on-flags">+ {{#if this.userNotesCount}}+ <DButton+ @translatedTitle={{i18n "user_notes.show" count=this.userNotesCount}}+ @action={{this.showUserNotes}}+ class="btn-flat"+ >+ {{#if this.siteSettings.enable_emoji}}+ <img+ src={{EMOJI_URL}}+ title={{i18n "user_notes.show" count=this.userNotesCount}}+ alt+ class="emoji"+ />+ {{else}}+ {{icon "pen-to-square"}}+ {{/if}}+ </DButton>+ {{/if}}+ </div></template>}diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/reviewable-note-form-after-note/copy-reviewable-note-to-user-option.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/reviewable-note-form-after-note/copy-reviewable-note-to-user-option.gjsindex e7b874f6f1a..817eddfa177 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/reviewable-note-form-after-note/copy-reviewable-note-to-user-option.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/reviewable-note-form-after-note/copy-reviewable-note-to-user-option.gjs@@ -2,10 +2,8 @@ import Component from "@glimmer/component";import { i18n } from "discourse-i18n";export default class CopyReviewableNoteToUserOption extends Component {- static shouldRender(args, context) {- return (- context.siteSettings.user_notes_enabled && context.currentUser?.staff- );+ static shouldRender(args, { siteSettings, currentUser }) {+ return siteSettings.user_notes_enabled && currentUser?.staff;}<template>diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-card-post-names/show-user-notes-on-card.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-card-post-names/show-user-notes-on-card.gjsindex 626254383ee..a7ebffb08f1 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-card-post-names/show-user-notes-on-card.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-card-post-names/show-user-notes-on-card.gjs@@ -4,23 +4,21 @@ import { service } from "@ember/service";import DButton from "discourse/components/d-button";import icon from "discourse/helpers/d-icon";import emoji from "discourse/helpers/emoji";-import I18n from "discourse-i18n";+import { i18n } from "discourse-i18n";import { showUserNotes } from "../../lib/user-notes";export default class extends Component {- static shouldRender(args, context) {- const { siteSettings, currentUser } = context;+ static shouldRender(args, { siteSettings, currentUser }) {return siteSettings.user_notes_enabled && currentUser?.staff;}@service siteSettings;- @service currentUser;@service store;get userNotesCount() {return parseInt(- this.args.outletArgs.user.get("user_notes_count") ||- this.args.outletArgs.user.get("custom_fields.user_notes_count") ||+ this.args.user.get("user_notes_count") ||+ this.args.user.get("custom_fields.user_notes_count") ||0,10);@@ -28,17 +26,14 @@ export default class extends Component {@actionshowUserNotes() {- showUserNotes(this.store, this.args.outletArgs.user.id);+ showUserNotes(this.store, this.args.user.id);}<template><div class="show-user-notes-on-card">{{#if this.userNotesCount}}<DButton- @translatedTitle={{I18n.t- "user_notes.show"- count=this.userNotesCount- }}+ @translatedTitle={{i18n "user_notes.show" count=this.userNotesCount}}@action={{this.showUserNotes}}class="btn-flat">diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-profile-controls/show-notes-on-profile.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-profile-controls/show-notes-on-profile.gjsindex 64f03302a23..a9617f5e3fd 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-profile-controls/show-notes-on-profile.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/connectors/user-profile-controls/show-notes-on-profile.gjs@@ -1,41 +1,38 @@-import Component from "@ember/component";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";import { action } from "@ember/object";import { service } from "@ember/service";-import { classNames, tagName } from "@ember-decorators/component";import ShowUserNotes from "../../components/show-user-notes";import { showUserNotes } from "../../lib/user-notes";-@tagName("li")-@classNames("user-profile-controls-outlet", "show-notes-on-profile")export default class ShowNotesOnProfile extends Component {- static shouldRender(args, context) {- const { siteSettings, currentUser } = context;- return siteSettings.user_notes_enabled && currentUser && currentUser.staff;+ static shouldRender(args, { siteSettings, currentUser }) {+ return siteSettings.user_notes_enabled && currentUser?.staff;}@service store;- init() {- super.init(...arguments);- const { model } = this;- this.set(- "userNotesCount",- model.user_notes_count || model.get("custom_fields.user_notes_count") || 0- );- }+ @tracked+ userNotesCount =+ this.args.model.user_notes_count ||+ this.args.model.custom_fields?.user_notes_count ||+ 0;@actionshowUserNotes() {- const user = this.model;- showUserNotes(this.store, user.id, (count) =>- this.set("userNotesCount", count)+ showUserNotes(+ this.store,+ this.args.model.id,+ (count) => (this.userNotesCount = count));}<template>- <ShowUserNotes- @show={{this.showUserNotes}}- @count={{this.userNotesCount}}- />+ <li class="user-profile-controls-outlet show-notes-on-profile">+ <ShowUserNotes+ @show={{this.showUserNotes}}+ @count={{this.userNotesCount}}+ />+ </li></template>}diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/lib/user-notes.js b/plugins/discourse-user-notes/assets/javascripts/discourse/lib/user-notes.jsindex b20de37de83..f1965a918ab 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/lib/user-notes.js+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/lib/user-notes.js@@ -1,24 +1,22 @@import { getOwnerWithFallback } from "discourse/lib/get-owner";-import UserNotesModal from "../../discourse/components/modal/user-notes";+import UserNotesModal from "../components/modal/user-notes";-export function showUserNotes(store, userId, callback, opts) {+export async function showUserNotes(store, userId, callback, opts = {}) {const modal = getOwnerWithFallback(this).lookup("service:modal");- opts = opts || {};- return store.find("user-note", { user_id: userId }).then((model) => {- return modal.show(UserNotesModal, {- model: {- note: model,- userId,- callback,- postId: opts.postId,- },- });+ const model = await store.find("user-note", { user_id: userId });++ await modal.show(UserNotesModal, {+ model: {+ note: model,+ userId,+ callback,+ postId: opts.postId,+ },});}export function updatePostUserNotesCount(post, count) {- const cfs = post.user_custom_fields || {};- cfs.user_notes_count = count;- post.user_custom_fields = cfs;+ post.user_custom_fields ||= {};+ post.user_custom_fields.user_notes_count = count;}