Skip to content

A platform for community discussion. Free, open, simple.

FIX: Href attribute for post-date link (#16471)

Penar Musaraj650adbe423ca
diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js
index 22a743988bb..3ba650dd683 100644
--- a/app/assets/javascripts/discourse/app/widgets/post.js
+++ b/app/assets/javascripts/discourse/app/widgets/post.js
@@ -19,7 +19,6 @@ import { iconNode } from "discourse-common/lib/icon-library";
import { postTransformCallbacks } from "discourse/widgets/post-stream";
import { prioritizeNameInUx } from "discourse/lib/settings";
import { relativeAgeMediumSpan } from "discourse/lib/formatter";
-import { wantsNewWindow } from "discourse/lib/intercept-click";
import { transformBasicPost } from "discourse/lib/transform-post";
import autoGroupFlairForUser from "discourse/lib/avatar-flair";
import showModal from "discourse/lib/show-modal";
@@ -353,25 +352,30 @@ createWidget("post-date", {
tagName: "div.post-info.post-date",
html(attrs) {
- const attributes = { href: attrs.shareUrl, class: "post-date" };
- let date = attrs.created_at;
- if (attrs.lastWikiEdit) {
- attributes["class"] += " last-wiki-edit";
- date = attrs.lastWikiEdit;
- }
- return h("a", { attributes }, dateNode(new Date(date)));
- },
+ let date,
+ linkClassName = "post-date";
- click() {
- if (wantsNewWindow(event)) {
- return;
- }
+ if (attrs.wiki && attrs.lastWikiEdit) {
+ linkClassName += " last-wiki-edit";
+ date = new Date(attrs.lastWikiEdit);
+ } else {
+ date = new Date(attrs.created_at);
+ }
+ return this.attach("link", {
+ rawLabel: dateNode(date),
+ className: linkClassName,
+ omitSpan: true,
+ title: "post.sr_date",
+ href: attrs.shareUrl,
+ action: "showShareModal",
+ });
+ },
+ showShareModal() {
const post = this.findAncestorModel();
const topic = post.topic;
const controller = showModal("share-topic", { model: topic.category });
controller.setProperties({ topic, post });
- event.preventDefault();
},
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js
index 1b2821e0099..c18f96508d9 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js
@@ -1,6 +1,6 @@
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
import I18n from "I18n";
-import { click, visit } from "@ember/test-helpers";
+import { click, currentURL, visit } from "@ember/test-helpers";
import {
acceptance,
exists,
@@ -59,14 +59,19 @@ acceptance("Share and Invite modal", function (needs) {
test("Post date link", async function (assert) {
await visit("/t/short-topic-with-two-posts/54077");
- await click("#post_2 .post-info.post-date");
assert.ok(
query("#post_2 .post-info.post-date a").href.endsWith(
"/t/short-topic-with-two-posts/54077/2?u=eviltrout"
)
);
+ await click("#post_2 a.post-date");
assert.ok(exists(".share-topic-modal"), "it shows the share modal");
+ assert.strictEqual(
+ currentURL(),
+ "/t/short-topic-with-two-posts/54077",
+ "it does not route to post #2"
+ );
});
test("Share topic in a restricted category", async function (assert) {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index a47e96af8c1..0b974911de6 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3066,6 +3066,7 @@ en:
deleted_by_author_simple: "(post deleted by author)"
collapse: "collapse"
sr_collapse_replies: "Collapse embedded replies"
+ sr_date: "Post date"
sr_expand_replies:
one: "This post has %{count} reply. Click to expand"
other: "This post has %{count} replies. Click to expand"