Skip to content

Commit e20ab4d

Browse files
megothssmartin-brennan
authored andcommitted
DEV: Add value transformer for post edits indicator labels (#34075)
Introduced the `post-meta-data-edits-indicator-label` transformer to enable customization of post edits indicator labels. Added integration tests to validate customization and default behavior.
1 parent d619872 commit e20ab4d

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

app/assets/javascripts/discourse/app/components/post/meta-data/edits-indicator.gjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { service } from "@ember/service";
44
import DButton from "discourse/components/d-button";
55
import concatClass from "discourse/helpers/concat-class";
66
import { longDate } from "discourse/lib/formatter";
7+
import { applyValueTransformer } from "discourse/lib/transformer";
78
import { i18n } from "discourse-i18n";
89

910
export default class PostMetaDataEditsIndicator extends Component {
@@ -14,9 +15,11 @@ export default class PostMetaDataEditsIndicator extends Component {
1415
}
1516

1617
get label() {
17-
if (this.args.post.version > 1) {
18-
return this.args.post.version - 1;
19-
}
18+
return applyValueTransformer(
19+
"post-meta-data-edits-indicator-label",
20+
this.args.post.version > 1 ? this.args.post.version - 1 : null,
21+
{ post: this.args.post }
22+
);
2023
}
2124

2225
get title() {

app/assets/javascripts/discourse/app/lib/transformer/registry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const VALUE_TRANSFORMERS = Object.freeze([
5353
"post-flag-title",
5454
"post-menu-buttons",
5555
"post-menu-collapsed",
56+
"post-meta-data-edits-indicator-label",
5657
"post-meta-data-infos",
5758
"post-meta-data-poster-name-suppress-similar-name",
5859
"post-notice-component",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { getOwner } from "@ember/owner";
2+
import { render, settled } from "@ember/test-helpers";
3+
import { module, test } from "qunit";
4+
import PostMetaDataEditsIndicator from "discourse/components/post/meta-data/edits-indicator";
5+
import { withPluginApi } from "discourse/lib/plugin-api";
6+
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
7+
8+
function renderComponent(post) {
9+
return render(
10+
<template><PostMetaDataEditsIndicator @post={{post}} /></template>
11+
);
12+
}
13+
14+
module(
15+
"Integration | Component | Post | PostMetaDataEditsIndicator",
16+
function (hooks) {
17+
setupRenderingTest(hooks);
18+
19+
hooks.beforeEach(function () {
20+
this.siteSettings.glimmer_post_stream_mode = "enabled";
21+
22+
this.store = getOwner(this).lookup("service:store");
23+
const topic = this.store.createRecord("topic", { id: 1 });
24+
const post = this.store.createRecord("post", {
25+
id: 123,
26+
post_number: 1,
27+
topic,
28+
like_count: 3,
29+
actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }],
30+
});
31+
32+
this.post = post;
33+
});
34+
35+
test("basic rendering", async function (assert) {
36+
this.post.username = "eviltrout";
37+
this.post.name = "Robin Ward";
38+
this.post.user_title = "Trout Master";
39+
40+
await renderComponent(this.post);
41+
42+
assert.dom(".post-info.edits button").exists().hasText(/\s+/);
43+
44+
this.post.version = 2;
45+
await settled();
46+
47+
assert.dom(".post-info.edits button").exists().hasText("1");
48+
});
49+
50+
test("customize labels using the post-meta-data-edits-indicator-label transformer", async function (assert) {
51+
withPluginApi((api) => {
52+
api.registerValueTransformer(
53+
"post-meta-data-edits-indicator-label",
54+
({ value }) => {
55+
if (value) {
56+
return "(edited)";
57+
} else {
58+
return "(original)";
59+
}
60+
}
61+
);
62+
});
63+
64+
await renderComponent(this.post);
65+
assert.dom(".post-info.edits button").hasText("(original)");
66+
67+
this.post.version = 2;
68+
await settled();
69+
70+
assert.dom(".post-info.edits button").hasText("(edited)");
71+
});
72+
}
73+
);

0 commit comments

Comments
 (0)