A platform for community discussion. Free, open, simple.
DEV: use classes to style hidden post history revision (#38159)
Krisbb386fcfa7ec
diff --git a/app/assets/stylesheets/common/base/history.scss b/app/assets/stylesheets/common/base/history.scssindex 60fd9487887..be596e68c8b 100644--- a/app/assets/stylesheets/common/base/history.scss+++ b/app/assets/stylesheets/common/base/history.scss@@ -313,15 +313,13 @@}.hidden-revision-previous .row {- div:nth-of-type(1),- td:nth-of-type(1) {+ .--previous {opacity: 0.5;}}.hidden-revision-current .row {- div:nth-of-type(2),- td:nth-of-type(2) {+ .--current {opacity: 0.5;}}diff --git a/frontend/discourse/app/components/modal/history/revisions.gjs b/frontend/discourse/app/components/modal/history/revisions.gjsindex e7db2316a88..27d5bcbd13c 100644--- a/frontend/discourse/app/components/modal/history/revisions.gjs+++ b/frontend/discourse/app/components/modal/history/revisions.gjs@@ -70,7 +70,7 @@ export default class Revisions extends Component {>{{#if @model.locale_changes}}<div class="row revision__locale">- <div class="revision-content">+ <div class="revision-content --previous"><div class={{if @model.locale_changes.previous "diff-del"}}>{{icon "globe"}}{{this.previousLocale}}@@ -81,7 +81,7 @@ export default class Revisions extends Component {→ {{/if}}- <div class="revision-content">+ <div class="revision-content --current"><div class={{if @model.locale_changes.current "diff-ins"}}>{{icon "globe"}}{{this.currentLocale}}@@ -141,7 +141,7 @@ export default class Revisions extends Component {{{/if}}{{#if @model.tags_changes}}<div class="row -tag-revisions">- <span class="tag-revision__wrapper">+ <span class="tag-revision__wrapper --previous">{{discourseTagsthis.fakePreviousTagsTopictagClasses=this.previousTagClassesMap@@ -152,7 +152,7 @@ export default class Revisions extends Component {→ {{/if}}- <span class="tag-revision__wrapper">+ <span class="tag-revision__wrapper --current">{{discourseTagsthis.fakeCurrentTagsTopictagClasses=this.currentTagClassesMapdiff --git a/lib/discourse_diff.rb b/lib/discourse_diff.rbindex 3965c3b2f7f..20ad26c87c6 100644--- a/lib/discourse_diff.rb+++ b/lib/discourse_diff.rb@@ -86,7 +86,7 @@ class DiscourseDiffi += 1end- "<div class=\"revision-content\">#{left.join}</div><div class=\"revision-content\">#{right.join}</div>"+ "<div class=\"revision-content --previous\">#{left.join}</div><div class=\"revision-content --current\">#{right.join}</div>"enddef side_by_side_markdown@@ -96,8 +96,8 @@ class DiscourseDifftable << "<tr>"op_code = line_by_line_diff[i][1]if op_code == :common- table << "<td>#{line_by_line_diff[i][0]}</td>"- table << "<td>#{line_by_line_diff[i][0]}</td>"+ table << "<td class=\"--previous\">#{line_by_line_diff[i][0]}</td>"+ table << "<td class=\"--current\">#{line_by_line_diff[i][0]}</td>"elseif op_code == :deleteopposite_op_code = :add@@ -120,16 +120,16 @@ class DiscourseDiffenddiff = ONPDiff.new(before_tokens, after_tokens).short_diffdeleted, inserted = generate_side_by_side_markdown(diff)- table << "<td class=\"diff-del\">#{deleted.join}</td>"- table << "<td class=\"diff-ins\">#{inserted.join}</td>"+ table << "<td class=\"--previous diff-del\">#{deleted.join}</td>"+ table << "<td class=\"--current diff-ins\">#{inserted.join}</td>"i += 1elseif op_code == :delete- table << "<td class=\"diff-del\">#{line_by_line_diff[i][0]}</td>"- table << "<td></td>"+ table << "<td class=\"--previous diff-del\">#{line_by_line_diff[i][0]}</td>"+ table << "<td class=\"--current\"></td>"else- table << "<td></td>"- table << "<td class=\"diff-ins\">#{line_by_line_diff[i][0]}</td>"+ table << "<td class=\"--previous\"></td>"+ table << "<td class=\"--current diff-ins\">#{line_by_line_diff[i][0]}</td>"endendenddiff --git a/spec/lib/discourse_diff_spec.rb b/spec/lib/discourse_diff_spec.rbindex d0eac675f60..3d6877ee685 100644--- a/spec/lib/discourse_diff_spec.rb+++ b/spec/lib/discourse_diff_spec.rb@@ -70,14 +70,14 @@ RSpec.describe DiscourseDiff dodescribe "side_by_side_html" doit "returns two empty divs when no content is diffed" doexpect(DiscourseDiff.new("", "").side_by_side_html).to eq(- "<div class=\"revision-content\"></div><div class=\"revision-content\"></div>",+ "<div class=\"revision-content --previous\"></div><div class=\"revision-content --current\"></div>",)endit "returns the diffed content on both sides when there is no difference" dobefore = after = "<p>this is a paragraph</p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p>this is a paragraph</p></div><div class=\"revision-content\"><p>this is a paragraph</p></div>",+ "<div class=\"revision-content --previous\"><p>this is a paragraph</p></div><div class=\"revision-content --current\"><p>this is a paragraph</p></div>",)end@@ -85,7 +85,7 @@ RSpec.describe DiscourseDiff dobefore = "<p>this is a paragraph</p>"after = "<p>this is a great paragraph</p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p>this is a paragraph</p></div><div class=\"revision-content\"><p>this is a <ins>great </ins>paragraph</p></div>",+ "<div class=\"revision-content --previous\"><p>this is a paragraph</p></div><div class=\"revision-content --current\"><p>this is a <ins>great </ins>paragraph</p></div>",)end@@ -94,7 +94,7 @@ RSpec.describe DiscourseDiff doafter = "<p>this is one great paragraph</p><p>here is another</p>"got = DiscourseDiff.new(before, after).side_by_side_htmlexpect(got).to eq(- "<div class=\"revision-content\"><p>this is one paragraph</p><p>here is <del>yet </del>another</p></div><div class=\"revision-content\"><p>this is one <ins>great </ins>paragraph</p><p>here is another</p></div>",+ "<div class=\"revision-content --previous\"><p>this is one paragraph</p><p>here is <del>yet </del>another</p></div><div class=\"revision-content --current\"><p>this is one <ins>great </ins>paragraph</p><p>here is another</p></div>",)end@@ -102,7 +102,7 @@ RSpec.describe DiscourseDiff dobefore = "<p>this is a great paragraph</p>"after = "<p>this is a paragraph</p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p>this is a <del>great </del>paragraph</p></div><div class=\"revision-content\"><p>this is a paragraph</p></div>",+ "<div class=\"revision-content --previous\"><p>this is a <del>great </del>paragraph</p></div><div class=\"revision-content --current\"><p>this is a paragraph</p></div>",)end@@ -110,7 +110,7 @@ RSpec.describe DiscourseDiff dobefore = "<p>this is the first paragraph</p>"after = "<p>this is the first paragraph</p><p>this is the second paragraph</p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p>this is the first paragraph</p></div><div class=\"revision-content\"><p>this is the first paragraph</p><p class=\"diff-ins\">this is the second paragraph</p></div>",+ "<div class=\"revision-content --previous\"><p>this is the first paragraph</p></div><div class=\"revision-content --current\"><p>this is the first paragraph</p><p class=\"diff-ins\">this is the second paragraph</p></div>",)end@@ -118,7 +118,7 @@ RSpec.describe DiscourseDiff dobefore = "<p>this is the first paragraph</p><p>this is the second paragraph</p>"after = "<p>this is the second paragraph</p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p class=\"diff-del\">this is the first paragraph</p><p>this is the second paragraph</p></div><div class=\"revision-content\"><p>this is the second paragraph</p></div>",+ "<div class=\"revision-content --previous\"><p class=\"diff-del\">this is the first paragraph</p><p>this is the second paragraph</p></div><div class=\"revision-content --current\"><p>this is the second paragraph</p></div>",)end@@ -126,7 +126,7 @@ RSpec.describe DiscourseDiff dobefore = "<p>'</p>"after = "<p></p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p><del>'</del></p></div><div class=\"revision-content\"><p></p></div>",+ "<div class=\"revision-content --previous\"><p><del>'</del></p></div><div class=\"revision-content --current\"><p></p></div>",)end@@ -134,7 +134,7 @@ RSpec.describe DiscourseDiff dobefore = "<p data-attr='Some \"quoted\" string'></p>"after = "<p data-attr='Some \"quoted\" string'></p>"expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(- "<div class=\"revision-content\"><p data-attr=\"Some "quoted" string\"></p></div><div class=\"revision-content\"><p data-attr=\"Some "quoted" string\"></p></div>",+ "<div class=\"revision-content --previous\"><p data-attr=\"Some "quoted" string\"></p></div><div class=\"revision-content --current\"><p data-attr=\"Some "quoted" string\"></p></div>",)endend@@ -150,14 +150,14 @@ RSpec.describe DiscourseDiff dobefore = ""after = "<img src=\"//domain.com/image.png>\""expect(DiscourseDiff.new(before, after).side_by_side_markdown).to eq(- "<table class=\"markdown\"><tr><td></td><td class=\"diff-ins\"><img src="//domain.com/image.png>"</td></tr></table>",+ "<table class=\"markdown\"><tr><td class=\"--previous\"></td><td class=\"--current diff-ins\"><img src="//domain.com/image.png>"</td></tr></table>",)endit "returns the diffed content on both columns when there is no difference" dobefore = after = "this is a paragraph"expect(DiscourseDiff.new(before, after).side_by_side_markdown).to eq(- "<table class=\"markdown\"><tr><td>this is a paragraph</td><td>this is a paragraph</td></tr></table>",+ "<table class=\"markdown\"><tr><td class=\"--previous\">this is a paragraph</td><td class=\"--current\">this is a paragraph</td></tr></table>",)end@@ -165,7 +165,7 @@ RSpec.describe DiscourseDiff dobefore = "this is a paragraph"after = "this is a great paragraph"expect(DiscourseDiff.new(before, after).side_by_side_markdown).to eq(- "<table class=\"markdown\"><tr><td class=\"diff-del\">this is a paragraph</td><td class=\"diff-ins\">this is a <ins>great </ins>paragraph</td></tr></table>",+ "<table class=\"markdown\"><tr><td class=\"--previous diff-del\">this is a paragraph</td><td class=\"--current diff-ins\">this is a <ins>great </ins>paragraph</td></tr></table>",)end@@ -173,7 +173,7 @@ RSpec.describe DiscourseDiff dobefore = "this is a great paragraph"after = "this is a paragraph"expect(DiscourseDiff.new(before, after).side_by_side_markdown).to eq(- "<table class=\"markdown\"><tr><td class=\"diff-del\">this is a <del>great </del>paragraph</td><td class=\"diff-ins\">this is a paragraph</td></tr></table>",+ "<table class=\"markdown\"><tr><td class=\"--previous diff-del\">this is a <del>great </del>paragraph</td><td class=\"--current diff-ins\">this is a paragraph</td></tr></table>",)end@@ -181,7 +181,7 @@ RSpec.describe DiscourseDiff dobefore = "this is the first paragraph"after = "this is the first paragraph\nthis is the second paragraph"expect(DiscourseDiff.new(before, after).side_by_side_markdown).to eq(- "<table class=\"markdown\"><tr><td class=\"diff-del\">this is the first paragraph</td><td class=\"diff-ins\">this is the first paragraph<ins>\nthis is the second paragraph</ins></td></tr></table>",+ "<table class=\"markdown\"><tr><td class=\"--previous diff-del\">this is the first paragraph</td><td class=\"--current diff-ins\">this is the first paragraph<ins>\nthis is the second paragraph</ins></td></tr></table>",)end@@ -189,7 +189,7 @@ RSpec.describe DiscourseDiff dobefore = "this is the first paragraph\nthis is the second paragraph"after = "this is the second paragraph"expect(DiscourseDiff.new(before, after).side_by_side_markdown).to eq(- "<table class=\"markdown\"><tr><td class=\"diff-del\">this is the first paragraph\n</td><td></td></tr><tr><td>this is the second paragraph</td><td>this is the second paragraph</td></tr></table>",+ "<table class=\"markdown\"><tr><td class=\"--previous diff-del\">this is the first paragraph\n</td><td class=\"--current\"></td></tr><tr><td class=\"--previous\">this is the second paragraph</td><td class=\"--current\">this is the second paragraph</td></tr></table>",)endenddiff --git a/spec/requests/admin/staff_action_logs_controller_spec.rb b/spec/requests/admin/staff_action_logs_controller_spec.rbindex d7206092669..f067aa8e9f4 100644--- a/spec/requests/admin/staff_action_logs_controller_spec.rb+++ b/spec/requests/admin/staff_action_logs_controller_spec.rb@@ -327,7 +327,7 @@ RSpec.describe Admin::StaffActionLogsController doparsed = response.parsed_bodyname_diff = <<-HTML- <h3>name</h3><p></p><table class="markdown"><tr><td class="diff-del"><del>#{tag_group1.name}</del></td><td class="diff-ins"><ins>#{tag_group2.name}</ins></td></tr></table>+ <h3>name</h3><p></p><table class="markdown"><tr><td class="--previous diff-del"><del>#{tag_group1.name}</del></td><td class="--current diff-ins"><ins>#{tag_group2.name}</ins></td></tr></table>HTMLexpect(parsed["side_by_side"]).to include(name_diff.strip)expect(parsed["side_by_side"]).to include("<del>#{tag1.name}</del>")diff --git a/spec/system/page_objects/modals/post_history.rb b/spec/system/page_objects/modals/post_history.rbindex a6f5cb689a7..48394c24f60 100644--- a/spec/system/page_objects/modals/post_history.rb+++ b/spec/system/page_objects/modals/post_history.rb@@ -11,11 +11,11 @@ module PageObjectsenddef previous_locale- body.find(".revision__locale .revision-content:nth-child(1)")+ body.find(".revision__locale .revision-content.--previous")enddef current_locale- body.find(".revision__locale .revision-content:nth-child(2)")+ body.find(".revision__locale .revision-content.--current")enddef current_revision