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

Commit 6b66a06

Browse files
tyb-talksjjaffeux
andauthored
FIX: restore button to add user notes to post admin menu (#85)
* FIX: use api.addPostAdminMenuButton for modifying post admin menu instead of widget We use app events here to force refresh of specific post, as previously the behaviour of the widget would trigger the re-render at the same time as the primary actions. This could also be handled in the modal instead of via the action passed by the button. --------- Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
1 parent 134fcba commit 6b66a06

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

.discourse-compatibility

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
< 3.2.0.beta2-dev: 134fcba29baf2ca92ec555dab1707c096712af14
12
3.1.999: 20f8f68d127a923942cca11a586caf4ea14019eb
23
2.9.0.beta12: 7137499c69065928c0fdd8795a3fb8d175e1ff3d

assets/javascripts/discourse/initializers/enable-user-notes.js

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export default {
1010
initialize(container) {
1111
const siteSettings = container.lookup("site-settings:main");
1212
const currentUser = container.lookup("current-user:main");
13+
const appEvents = container.lookup("service:app-events");
14+
1315
if (
1416
!siteSettings.user_notes_enabled ||
1517
!currentUser ||
@@ -68,8 +70,13 @@ export default {
6870
return;
6971
}
7072

71-
const cfs = dec.attrs.userCustomFields || {};
72-
if (cfs.user_notes_count > 0) {
73+
const post = dec.getModel();
74+
if (!post) {
75+
return;
76+
}
77+
78+
const ucf = post.user_custom_fields || {};
79+
if (ucf.user_notes_count > 0) {
7380
return dec.attach("user-notes-icon");
7481
}
7582
});
@@ -79,23 +86,39 @@ export default {
7986
return;
8087
}
8188

82-
const cfs = dec.attrs.userCustomFields || {};
83-
if (cfs.user_notes_count > 0) {
89+
const post = dec.getModel();
90+
if (!post) {
91+
return;
92+
}
93+
94+
const ucf = post.user_custom_fields || {};
95+
if (ucf.user_notes_count > 0) {
8496
return dec.attach("user-notes-icon");
8597
}
8698
});
99+
api.addPostAdminMenuButton((attrs) => {
100+
return {
101+
icon: "pencil-alt",
102+
label: "user_notes.attach",
103+
action: (post) => {
104+
showUserNotes(
105+
store,
106+
attrs.user_id,
107+
(count) => {
108+
const ucf = post.user_custom_fields || {};
109+
ucf.user_notes_count = count;
110+
post.set("user_custom_fields", ucf);
87111

88-
api.decorateWidget("post-admin-menu:after", (dec) => {
89-
return dec.h(
90-
"ul",
91-
dec.attach("post-admin-menu-button", {
92-
icon: "pencil-alt",
93-
label: "user_notes.attach",
94-
action: "showUserNotes",
95-
secondaryAction: "closeAdminMenu",
96-
className: "add-user-note",
97-
})
98-
);
112+
appEvents.trigger("post-stream:refresh", {
113+
id: post.id,
114+
});
115+
},
116+
{ postId: attrs.id }
117+
);
118+
},
119+
secondaryAction: "closeAdminMenu",
120+
className: "add-user-note",
121+
};
99122
});
100123

101124
api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes);

0 commit comments

Comments
 (0)