A platform for community discussion. Free, open, simple.
UX: remove post meta, use timezones, in event oneboxes (#45307)
Kriscd4c9a4a38e2
diff --git a/app/assets/stylesheets/common/base/onebox.scss b/app/assets/stylesheets/common/base/onebox.scssindex 72fabf84f35..005aeda114d 100644--- a/app/assets/stylesheets/common/base/onebox.scss+++ b/app/assets/stylesheets/common/base/onebox.scss@@ -457,11 +457,6 @@ aside.onebox:has(.discourse-event-onebox) {}}- &__metadata {- display: flex;- justify-content: space-between;- }-&.--banner-image {container-type: inline-size;@@ -494,7 +489,6 @@ aside.onebox:has(.discourse-event-onebox) {"image date title" auto"image time time" auto"image description description" auto- "image metadata metadata" auto"image . ." 1fr / 8rem auto minmax(0, 1fr);row-gap: 0;@@ -530,10 +524,6 @@ aside.onebox:has(.discourse-event-onebox) {grid-area: description;}- .discourse-event-onebox__metadata {- grid-area: metadata;- }-// Two columns leave too little room for long titles in narrow spaces like phones or the chat// drawer, so the image goes above, letterboxed into the same 16:9 frame as banner images@container event-onebox (width < 30rem) {@@ -542,8 +532,7 @@ aside.onebox:has(.discourse-event-onebox) {"image image" auto"date title" auto". time" auto- ". description" auto- ". metadata" auto / auto minmax(0, 1fr);+ ". description" auto / auto minmax(0, 1fr);.discourse-event-onebox__image.thumbnail {@include letterboxed-event-image;diff --git a/lib/onebox/engine/discourse_topic_onebox.rb b/lib/onebox/engine/discourse_topic_onebox.rbindex 30c22fb2d6e..e2e6302206b 100644--- a/lib/onebox/engine/discourse_topic_onebox.rb+++ b/lib/onebox/engine/discourse_topic_onebox.rb@@ -17,8 +17,10 @@ module Onebox@data ||= {categories: categories,link: link,- article_published_time: published_time.strftime("%-d %b %y"),- article_published_time_title: published_time.strftime("%I:%M%p - %d %B %Y"),+ # The event date is shown in the body, so a post date in the header reads as a second event date+ article_published_time: (published_time.strftime("%-d %b %y") unless event?),+ article_published_time_title:+ (published_time.strftime("%I:%M%p - %d %B %Y") unless event?),domain: html_entities.decode(raw[:site_name].truncate(80, separator: " ")),description: description,is_event: event?,diff --git a/lib/onebox/templates/discoursetopic_with_event.mustache b/lib/onebox/templates/discoursetopic_with_event.mustacheindex ecf6505ca9e..7bf127f4858 100644--- a/lib/onebox/templates/discoursetopic_with_event.mustache+++ b/lib/onebox/templates/discoursetopic_with_event.mustache@@ -51,14 +51,5 @@<p>{{description}}</p></div>{{/description}}-- {{#data1}}- <p class="discourse-event-onebox__metadata">- <span class="label1">{{label1}}: {{data1}}</span>- {{#data2}}- <span class="label2">{{label2}}: {{data2}}</span>- {{/data2}}- </p>- {{/data1}}</div></div>diff --git a/plugins/discourse-events/assets/javascripts/discourse/lib/decorate-event-oneboxes.js b/plugins/discourse-events/assets/javascripts/discourse/lib/decorate-event-oneboxes.jsindex 70653139966..ce23246515f 100644--- a/plugins/discourse-events/assets/javascripts/discourse/lib/decorate-event-oneboxes.js+++ b/plugins/discourse-events/assets/javascripts/discourse/lib/decorate-event-oneboxes.js@@ -70,7 +70,17 @@ function formatTimed(startsAt, endsAt, timezone) {value = `${value} → ${endsAt.format(format)}`;}- return `${value} (${timezone})`;+ return `${value} (${timezoneLabel(startsAt, timezone)})`;+}++// Zones without a common abbreviation format as a bare offset like "-03", so the location reads better+function timezoneLabel(date, timezone) {+ const abbreviation = date.format("z");+ if (!/^[+-]/.test(abbreviation)) {+ return abbreviation;+ }++ return timezone.split("/").pop().replaceAll("_", " ");}function parseDate(value, { allDay, timezone }) {diff --git a/plugins/discourse-events/test/javascripts/unit/lib/decorate-event-oneboxes-test.js b/plugins/discourse-events/test/javascripts/unit/lib/decorate-event-oneboxes-test.jsindex c5a12eccce9..aff1b6f482c 100644--- a/plugins/discourse-events/test/javascripts/unit/lib/decorate-event-oneboxes-test.js+++ b/plugins/discourse-events/test/javascripts/unit/lib/decorate-event-oneboxes-test.js@@ -19,11 +19,31 @@ module("Unit | Lib | decorate-event-oneboxes", function () {assert.dom(".discourse-event-onebox__time-text", element).hasText(- "11:00 PM → Oct 23, 2026 12:00 AM (Australia/Brisbane)",+ "11:00 PM → Oct 23, 2026 12:00 AM (AEST)","the time and timezone are localized");});+ test("labels the timezone with its daylight saving abbreviation", function (assert) {+ const element = buildOnebox({ startsAt: "2026-10-22T13:00:00.000Z" });++ decorateEventOneboxes(element, "America/New_York");++ assert+ .dom(".discourse-event-onebox__time-text", element)+ .hasText("9:00 AM (EDT)", "the abbreviation reflects daylight saving");+ });++ test("labels the timezone with its location when it has no abbreviation", function (assert) {+ const element = buildOnebox({ startsAt: "2026-10-22T13:00:00.000Z" });++ decorateEventOneboxes(element, "America/Sao_Paulo");++ assert+ .dom(".discourse-event-onebox__time-text", element)+ .hasText("10:00 AM (Sao Paulo)", "the location replaces a bare offset");+ });+test("keeps all-day event dates timezone-independent", function (assert) {const element = buildOnebox({allDay: true,diff --git a/spec/lib/onebox/engine/discourse_topic_onebox_spec.rb b/spec/lib/onebox/engine/discourse_topic_onebox_spec.rbindex f4e51150b15..d717a842761 100644--- a/spec/lib/onebox/engine/discourse_topic_onebox_spec.rb+++ b/spec/lib/onebox/engine/discourse_topic_onebox_spec.rb@@ -105,11 +105,18 @@ RSpec.describe Onebox::Engine::DiscourseTopicOnebox doexpect(html).to include('data-event-starts-at="2026-10-22T09:00:00.000-04:00"')expect(html).to include('class="discourse-event-onebox__date"')expect(html).to include("Meet the community")- expect(html).to include("Reading time: 1 min 🕑")- expect(html).to include("Likes: 2 ❤")+ expect(html).not_to include("Reading time")+ expect(html).not_to include("Likes")expect(html).not_to include("The ordinary topic excerpt")end+ it "omits the post date from the header" do+ expect(data[:article_published_time]).to be_nil+ expect(onebox.to_html).to include(+ '<a href="https://example.com/t/community-hangout/123" target="_blank" rel="noopener">Example community</a>',+ )+ end+context "without an event description" dolet(:event_description_json) { "" }