A platform for community discussion. Free, open, simple.
FEATURE: Display locale change in post history modal (#33469)
Natalie Tay01d42ab524b8
diff --git a/app/assets/javascripts/discourse/app/components/modal/history/revisions.gjs b/app/assets/javascripts/discourse/app/components/modal/history/revisions.gjsindex d2f63f638f8..4eb0110a7e1 100644--- a/app/assets/javascripts/discourse/app/components/modal/history/revisions.gjs+++ b/app/assets/javascripts/discourse/app/components/modal/history/revisions.gjs@@ -10,6 +10,7 @@ import icon from "discourse/helpers/d-icon";import discourseTags from "discourse/helpers/discourse-tags";import htmlSafe from "discourse/helpers/html-safe";import lazyHash from "discourse/helpers/lazy-hash";+import { i18n } from "discourse-i18n";function tagClasses(tagChanges, state, className) {return (tagChanges || []).reduce((classMap, tagChange) => {@@ -42,12 +43,47 @@ export default class Revisions extends Component {return tagClasses(this.get("currentTagChanges"), "inserted", "diff-ins");}+ get previousLocale() {+ return (+ this.get("model.locale_changes.previous") ||+ i18n("post.revisions.locale.no_locale_set")+ );+ }++ get currentLocale() {+ return (+ this.get("model.locale_changes.current") ||+ i18n("post.revisions.locale.locale_removed")+ );+ }+<template><divid="revisions"data-post-id={{@model.post_id}}class={{@hiddenClasses}}>+ {{#if @model.locale_changes}}+ <div class="row revision__locale">+ <div class="revision-content">+ <div class={{if @model.locale_changes.previous "diff-del"}}>+ {{icon "globe"}}+ {{this.previousLocale}}+ </div>+ </div>++ {{#if (or @mobileView (eq @viewMode "inline"))}}+ → + {{/if}}++ <div class="revision-content">+ <div class={{if @model.locale_changes.current "diff-ins"}}>+ {{icon "globe"}}+ {{this.currentLocale}}+ </div>+ </div>+ </div>+ {{/if}}{{#if @model.title_changes}}<div class="row"><h2 class="revision__title">{{htmlSafe @titleDiff}}</h2>diff --git a/app/assets/stylesheets/common/base/history.scss b/app/assets/stylesheets/common/base/history.scssindex df59735aaa7..4c7ce756058 100644--- a/app/assets/stylesheets/common/base/history.scss+++ b/app/assets/stylesheets/common/base/history.scss@@ -72,6 +72,7 @@}.revision__title,+ .revision__locale,.body-diff,table.markdown > tbody > tr,.-tag-revisions {@@ -112,6 +113,18 @@line-height: var(--line-height-medium);}+ .revision__locale {+ font-size: var(--font-down-1);+ color: var(--primary-high);+ margin-top: 0.5em;+ margin-bottom: 0.5em;++ .diff-ins,+ .diff-del {+ width: fit-content;+ }+ }+&:not(.--mode-inline) {.-tag-revisions .tag-revision__wrapper {flex: 0 1 50%;diff --git a/app/serializers/post_revision_serializer.rb b/app/serializers/post_revision_serializer.rbindex 8ab640875cf..da4bf5da057 100644--- a/app/serializers/post_revision_serializer.rb+++ b/app/serializers/post_revision_serializer.rb@@ -42,6 +42,7 @@ class PostRevisionSerializer < ApplicationSerializeradd_compared_field :wikiadd_compared_field :post_type+ add_compared_field :localedef previous_hiddenprevious["hidden"]@@ -192,6 +193,13 @@ class PostRevisionSerializer < ApplicationSerializerprevious["category_id"] != current["category_id"]end+ def locale_changes+ prev = LocaleSiteSetting.get_language_name(previous["locale"])+ cur = LocaleSiteSetting.get_language_name(current["locale"])++ { previous: prev, current: cur }+ end+protecteddef post@@ -220,6 +228,7 @@ class PostRevisionSerializer < ApplicationSerializer"wiki" => [post.wiki],"post_type" => [post.post_type],"user_id" => [post.user_id],+ "locale" => [post.locale],}# Retrieve any `tracked_topic_fields`diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 297d230edae..d72919d86f7 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4146,6 +4146,9 @@ en:other: "Are you sure you want to merge these %{count} posts?"revisions:+ locale:+ no_locale_set: "No language set"+ locale_removed: "Language removed"controls:first: "First revision"previous: "Previous revision"diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 1c11acb670b..af0ee1e1865 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -689,6 +689,7 @@ class PostRevisorupdate_topic_excerptupdate_category_description+ update_topic_localeenddef update_topic_excerpt@@ -710,6 +711,10 @@ class PostRevisorendend+ def update_topic_locale+ @topic.update(locale: @fields[:locale]) if @fields.has_key?(:locale)+ end+def advance_draft_sequence@post.advance_draft_sequenceenddiff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rbindex 95314cbeed2..1abdc604ca1 100644--- a/spec/lib/post_revisor_spec.rb+++ b/spec/lib/post_revisor_spec.rb@@ -1,8 +1,6 @@# frozen_string_literal: true-require "post_revisor"--RSpec.describe PostRevisor do+describe PostRevisor dofab!(:topic)fab!(:newuser) { Fabricate(:newuser, last_seen_at: Date.today) }fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }@@ -318,6 +316,26 @@ RSpec.describe PostRevisor doendend+ describe "editing locale" do+ it "updates the post's locale" do+ post = Fabricate(:post)++ PostRevisor.new(post).revise!(post.user, locale: "ja")++ post.reload+ expect(post.locale).to eq("ja")+ end++ it "also updates the topic's locale if first post" do+ post = Fabricate(:post)++ PostRevisor.new(post).revise!(post.user, locale: "ja")++ post.reload+ expect(post.topic.locale).to eq("ja")+ end+ end+describe "revise wiki" dobefore { SiteSetting.unique_posts_mins = 10 }diff --git a/spec/serializers/post_revision_serializer_spec.rb b/spec/serializers/post_revision_serializer_spec.rbindex c70cf7f2a22..ce4e7739ff6 100644--- a/spec/serializers/post_revision_serializer_spec.rb+++ b/spec/serializers/post_revision_serializer_spec.rb@@ -143,4 +143,37 @@ RSpec.describe PostRevisionSerializer doexpect { serializer.as_json }.not_to raise_errorendend++ describe "post locale edits" do+ it "returns the locale changes when set to nothing" do+ post_revision =+ Fabricate(:post_revision, post: post, modifications: { "locale" => ["ja", ""] })++ json =+ PostRevisionSerializer.new(+ post_revision,+ scope: Guardian.new(Fabricate(:user)),+ root: false,+ ).as_json++ expect(json[:locale_changes][:previous]).to eq("日本語")+ expect(json[:locale_changes][:current]).to eq(nil)+ end++ it "returns the locale changes when set from nothing to something" do+ post.update!(locale: "ja")+ post_revision =+ Fabricate(:post_revision, post: post, modifications: { "locale" => ["", "ja"] })++ json =+ PostRevisionSerializer.new(+ post_revision,+ scope: Guardian.new(Fabricate(:user)),+ root: false,+ ).as_json++ expect(json[:locale_changes][:previous]).to eq(nil)+ expect(json[:locale_changes][:current]).to eq("日本語")+ end+ endenddiff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rbindex ed271e4cde0..644e17625d4 100644--- a/spec/system/content_localization_spec.rb+++ b/spec/system/content_localization_spec.rb@@ -31,7 +31,9 @@ describe "Content Localization" dolet(:topic_page) { PageObjects::Pages::Topic.new }let(:topic_list) { PageObjects::Components::TopicList.new }let(:composer) { PageObjects::Components::Composer.new }+ let(:post_1_obj) { PageObjects::Components::Post.new(1) }let(:post_4_obj) { PageObjects::Components::Post.new(4) }+ let(:post_history_modal) { PageObjects::Modals::PostHistory.new }before doFabricate(:topic_localization, topic:, locale: "ja", fancy_title: "孫子兵法からの人生戦略")@@ -114,6 +116,33 @@ describe "Content Localization" dotopic_page.click_post_action_button(post_3, :edit)expect(composer).to have_content(post_3.raw)end++ context "for post edit histories" do+ before do+ SiteSetting.editing_grace_period = 0+ PostRevisor.new(post_1).revise!(Discourse.system_user, { raw: post_1.raw, locale: "" })+ PostRevisor.new(post_1).revise!(Discourse.system_user, { raw: post_1.raw, locale: "ja" })+ end++ it "shows the language of the post in history modal" do+ sign_in(admin)++ visit("/")+ topic_list.visit_topic_with_title(topic.title)++ post_1_obj.open_post_history+ expect(post_history_modal.current_locale).to have_content("日本語")+ expect(post_history_modal.previous_locale).to have_content(+ I18n.t("js.post.revisions.locale.no_locale_set"),+ )++ post_history_modal.click_previous_revision+ expect(post_history_modal.current_locale).to have_content(+ I18n.t("js.post.revisions.locale.locale_removed"),+ )+ expect(post_history_modal.previous_locale).to have_content("English (US)")+ end+ endendcontext "for site settings" dodiff --git a/spec/system/page_objects/components/post.rb b/spec/system/page_objects/components/post.rbindex 56a94aa5677..749703ef6bd 100644--- a/spec/system/page_objects/components/post.rb+++ b/spec/system/page_objects/components/post.rb@@ -65,6 +65,10 @@ module PageObjectsfind(".post-language-content")end+ def open_post_history+ post.find(".post-info.edits").click+ end+privatedef post_iddiff --git a/spec/system/page_objects/modals/post_history.rb b/spec/system/page_objects/modals/post_history.rbnew file mode 100644index 00000000000..e77e73fdae0--- /dev/null+++ b/spec/system/page_objects/modals/post_history.rb@@ -0,0 +1,32 @@+# frozen_string_literal: true++module PageObjects+ module Modals+ class PostHistory < PageObjects::Modals::Base+ MODAL_SELECTOR = ".history-modal"++ def click_previous_revision+ footer.find("button.previous-revision").click+ self+ end++ def previous_locale+ body.find(".revision__locale .revision-content:nth-child(1)")+ end++ def current_locale+ body.find(".revision__locale .revision-content:nth-child(2)")+ end++ def current_revision+ revision_numbers.find("strong:nth-child(3)")+ end++ private++ def revision_numbers+ footer.find("#revision-numbers")+ end+ end+ end+end