Use `modifyClass("model:post", ...)` as an alternative to `addPostTransformCallback`
This commit is contained in:
parent
1b8b2a3a32
commit
e8cb94931e
|
@ -392,7 +392,6 @@ function initialize(api) {
|
||||||
api.addPostSmallActionIcon("unassigned_group", "group-times");
|
api.addPostSmallActionIcon("unassigned_group", "group-times");
|
||||||
api.addPostSmallActionIcon("unassigned_from_post", "user-xmark");
|
api.addPostSmallActionIcon("unassigned_from_post", "user-xmark");
|
||||||
api.addPostSmallActionIcon("unassigned_group_from_post", "group-times");
|
api.addPostSmallActionIcon("unassigned_group_from_post", "group-times");
|
||||||
api.includePostAttributes("assigned_to_user", "assigned_to_group");
|
|
||||||
api.addPostSmallActionIcon("reassigned", "user-plus");
|
api.addPostSmallActionIcon("reassigned", "user-plus");
|
||||||
api.addPostSmallActionIcon("reassigned_group", "group-plus");
|
api.addPostSmallActionIcon("reassigned_group", "group-plus");
|
||||||
|
|
||||||
|
@ -712,6 +711,30 @@ function initialize(api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function customizePost(api) {
|
function customizePost(api) {
|
||||||
|
api.addTrackedPostProperties("assigned_to_user", "assigned_to_group");
|
||||||
|
|
||||||
|
api.modifyClass(
|
||||||
|
"model:post",
|
||||||
|
(Superclass) =>
|
||||||
|
class extends Superclass {
|
||||||
|
get can_edit() {
|
||||||
|
return isAssignSmallAction(this.action_code) ? true : super.can_edit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// overriding tracked properties requires overriding both the getter and the setter.
|
||||||
|
// otherwise the superclass will throw an error when the application sets the field value
|
||||||
|
set can_edit(value) {
|
||||||
|
super.can_edit = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSmallAction() {
|
||||||
|
return isAssignSmallAction(this.action_code)
|
||||||
|
? true
|
||||||
|
: super.isSmallAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
api.renderAfterWrapperOutlet(
|
api.renderAfterWrapperOutlet(
|
||||||
"post-content-cooked-html",
|
"post-content-cooked-html",
|
||||||
PostAssignmentsDisplay
|
PostAssignmentsDisplay
|
||||||
|
@ -872,12 +895,18 @@ function customizeWidgetPost(api) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// This won't have a direct translation in the Glimmer API as it uses can_edit from the model
|
// `addPostTransformCallback` doesn't have a direct translation in the new Glimmer API.
|
||||||
// TODO (glimmer-post-stream): check the post small action component and introduce a transformer to override the
|
// We need to use a modify class in the post model instead
|
||||||
// canEdit behavior there
|
|
||||||
api.addPostTransformCallback((transformed) => {
|
api.addPostTransformCallback((transformed) => {
|
||||||
if (
|
if (isAssignSmallAction(transformed.actionCode)) {
|
||||||
[
|
transformed.isSmallAction = true;
|
||||||
|
transformed.canEdit = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAssignSmallAction(actionCode) {
|
||||||
|
return [
|
||||||
"assigned",
|
"assigned",
|
||||||
"unassigned",
|
"unassigned",
|
||||||
"reassigned",
|
"reassigned",
|
||||||
|
@ -891,12 +920,7 @@ function customizeWidgetPost(api) {
|
||||||
"details_change",
|
"details_change",
|
||||||
"note_change",
|
"note_change",
|
||||||
"status_change",
|
"status_change",
|
||||||
].includes(transformed.actionCode)
|
].includes(actionCode);
|
||||||
) {
|
|
||||||
transformed.isSmallAction = true;
|
|
||||||
transformed.canEdit = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function customizePostMenu(api) {
|
function customizePostMenu(api) {
|
||||||
|
|
Loading…
Reference in New Issue