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>
This commit is contained in:
parent
134fcba29b
commit
6b66a06174
|
@ -1,2 +1,3 @@
|
||||||
|
< 3.2.0.beta2-dev: 134fcba29baf2ca92ec555dab1707c096712af14
|
||||||
3.1.999: 20f8f68d127a923942cca11a586caf4ea14019eb
|
3.1.999: 20f8f68d127a923942cca11a586caf4ea14019eb
|
||||||
2.9.0.beta12: 7137499c69065928c0fdd8795a3fb8d175e1ff3d
|
2.9.0.beta12: 7137499c69065928c0fdd8795a3fb8d175e1ff3d
|
||||||
|
|
|
@ -10,6 +10,8 @@ export default {
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
const currentUser = container.lookup("current-user:main");
|
const currentUser = container.lookup("current-user:main");
|
||||||
|
const appEvents = container.lookup("service:app-events");
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!siteSettings.user_notes_enabled ||
|
!siteSettings.user_notes_enabled ||
|
||||||
!currentUser ||
|
!currentUser ||
|
||||||
|
@ -68,8 +70,13 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cfs = dec.attrs.userCustomFields || {};
|
const post = dec.getModel();
|
||||||
if (cfs.user_notes_count > 0) {
|
if (!post) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ucf = post.user_custom_fields || {};
|
||||||
|
if (ucf.user_notes_count > 0) {
|
||||||
return dec.attach("user-notes-icon");
|
return dec.attach("user-notes-icon");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -79,23 +86,39 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cfs = dec.attrs.userCustomFields || {};
|
const post = dec.getModel();
|
||||||
if (cfs.user_notes_count > 0) {
|
if (!post) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ucf = post.user_custom_fields || {};
|
||||||
|
if (ucf.user_notes_count > 0) {
|
||||||
return dec.attach("user-notes-icon");
|
return dec.attach("user-notes-icon");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
api.addPostAdminMenuButton((attrs) => {
|
||||||
|
return {
|
||||||
|
icon: "pencil-alt",
|
||||||
|
label: "user_notes.attach",
|
||||||
|
action: (post) => {
|
||||||
|
showUserNotes(
|
||||||
|
store,
|
||||||
|
attrs.user_id,
|
||||||
|
(count) => {
|
||||||
|
const ucf = post.user_custom_fields || {};
|
||||||
|
ucf.user_notes_count = count;
|
||||||
|
post.set("user_custom_fields", ucf);
|
||||||
|
|
||||||
api.decorateWidget("post-admin-menu:after", (dec) => {
|
appEvents.trigger("post-stream:refresh", {
|
||||||
return dec.h(
|
id: post.id,
|
||||||
"ul",
|
});
|
||||||
dec.attach("post-admin-menu-button", {
|
},
|
||||||
icon: "pencil-alt",
|
{ postId: attrs.id }
|
||||||
label: "user_notes.attach",
|
);
|
||||||
action: "showUserNotes",
|
},
|
||||||
secondaryAction: "closeAdminMenu",
|
secondaryAction: "closeAdminMenu",
|
||||||
className: "add-user-note",
|
className: "add-user-note",
|
||||||
})
|
};
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes);
|
api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes);
|
||||||
|
|
Loading…
Reference in New Issue