FEATURE: small action post accepts href (#14816)
Optionally add href to small action. It can be used by discourse-assign to link to correct post from translation
This commit is contained in:
parent
53abcd825d
commit
fe8087e523
|
@ -1,6 +1,7 @@
|
|||
import I18n from "I18n";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import { getAbsoluteURL } from "discourse-common/lib/get-url";
|
||||
|
||||
const _additionalAttributes = [];
|
||||
|
||||
|
@ -147,6 +148,9 @@ export default function transformPost(
|
|||
postAtts.linkCounts = post.link_counts;
|
||||
postAtts.actionCode = post.action_code;
|
||||
postAtts.actionCodeWho = post.action_code_who;
|
||||
postAtts.actionCodeHref = getAbsoluteURL(
|
||||
post.action_code_href || `/t/${topic.id}`
|
||||
);
|
||||
postAtts.topicUrl = topic.get("url");
|
||||
postAtts.isSaving = post.isSaving;
|
||||
postAtts.staged = post.staged;
|
||||
|
|
|
@ -8,7 +8,7 @@ import { h } from "virtual-dom";
|
|||
import { iconNode } from "discourse-common/lib/icon-library";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
|
||||
export function actionDescriptionHtml(actionCode, createdAt, username) {
|
||||
export function actionDescriptionHtml(actionCode, createdAt, username, href) {
|
||||
const dt = new Date(createdAt);
|
||||
const when = autoUpdatingRelativeAge(dt, {
|
||||
format: "medium-with-ago-and-on",
|
||||
|
@ -22,7 +22,7 @@ export function actionDescriptionHtml(actionCode, createdAt, username) {
|
|||
who = `<a class="mention" href="${userPath(username)}">@${username}</a>`;
|
||||
}
|
||||
}
|
||||
return I18n.t(`action_codes.${actionCode}`, { who, when }).htmlSafe();
|
||||
return I18n.t(`action_codes.${actionCode}`, { who, when, href }).htmlSafe();
|
||||
}
|
||||
|
||||
export function actionDescription(actionCode, createdAt, username) {
|
||||
|
@ -131,7 +131,8 @@ export default createWidget("post-small-action", {
|
|||
const description = actionDescriptionHtml(
|
||||
attrs.actionCode,
|
||||
new Date(attrs.created_at),
|
||||
attrs.actionCodeWho
|
||||
attrs.actionCodeWho,
|
||||
attrs.actionCodeHref
|
||||
);
|
||||
contents.push(new RawHtml({ html: `<p>${description}</p>` }));
|
||||
|
||||
|
|
|
@ -170,6 +170,7 @@ class UserAction < ActiveRecord::Base
|
|||
action_type
|
||||
action_code
|
||||
action_code_who
|
||||
action_code_href
|
||||
topic_closed
|
||||
topic_id
|
||||
topic_archived
|
||||
|
@ -218,6 +219,7 @@ class UserAction < ActiveRecord::Base
|
|||
p.post_type,
|
||||
p.action_code,
|
||||
pc.value AS action_code_who,
|
||||
pc2.value AS action_code_href,
|
||||
p.edit_reason,
|
||||
t.category_id
|
||||
FROM user_actions as a
|
||||
|
@ -229,6 +231,7 @@ class UserAction < ActiveRecord::Base
|
|||
JOIN users au on au.id = a.user_id
|
||||
LEFT JOIN categories c on c.id = t.category_id
|
||||
LEFT JOIN post_custom_fields pc ON pc.post_id = a.target_post_id AND pc.name = 'action_code_who'
|
||||
LEFT JOIN post_custom_fields pc2 ON pc2.post_id = a.target_post_id AND pc.name = 'action_code_href'
|
||||
/*where*/
|
||||
/*order_by*/
|
||||
/*offset*/
|
||||
|
|
|
@ -79,6 +79,7 @@ class PostSerializer < BasicPostSerializer
|
|||
:is_auto_generated,
|
||||
:action_code,
|
||||
:action_code_who,
|
||||
:action_code_href,
|
||||
:notice,
|
||||
:last_wiki_edit,
|
||||
:locked,
|
||||
|
@ -443,6 +444,14 @@ class PostSerializer < BasicPostSerializer
|
|||
include_action_code? && action_code_who.present?
|
||||
end
|
||||
|
||||
def action_code_href
|
||||
post_custom_fields["action_code_href"]
|
||||
end
|
||||
|
||||
def include_action_code_href?
|
||||
include_action_code? && action_code_href.present?
|
||||
end
|
||||
|
||||
def notice
|
||||
post_custom_fields[Post::NOTICE]
|
||||
end
|
||||
|
|
|
@ -29,6 +29,7 @@ class UserActionSerializer < ApplicationSerializer
|
|||
:post_type,
|
||||
:action_code,
|
||||
:action_code_who,
|
||||
:action_code_href,
|
||||
:edit_reason,
|
||||
:category_id,
|
||||
:closed,
|
||||
|
@ -90,4 +91,12 @@ class UserActionSerializer < ApplicationSerializer
|
|||
object.action_code_who
|
||||
end
|
||||
|
||||
def include_action_code_href?
|
||||
action_code_href.present?
|
||||
end
|
||||
|
||||
def action_code_href
|
||||
object.action_code_href
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -53,9 +53,10 @@
|
|||
<%
|
||||
post_custom_fields = @topic_view.post_custom_fields[post.id] || {}
|
||||
who_username = post_custom_fields["action_code_who"] || ""
|
||||
small_action_href = post_custom_fields["action_code_href"] || ""
|
||||
if post.action_code
|
||||
%>
|
||||
<%= t("js.action_codes.#{post.action_code}", when: "", who: who_username).html_safe %>
|
||||
<%= t("js.action_codes.#{post.action_code}", when: "", who: who_username, href: small_action_href).html_safe %>
|
||||
<% end %>
|
||||
</span>
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class TopicView
|
|||
end
|
||||
|
||||
def self.default_post_custom_fields
|
||||
@default_post_custom_fields ||= [Post::NOTICE, "action_code_who"]
|
||||
@default_post_custom_fields ||= [Post::NOTICE, "action_code_who", "action_code_href"]
|
||||
end
|
||||
|
||||
def self.post_custom_fields_allowlisters
|
||||
|
|
Loading…
Reference in New Issue