Skip to content

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.scss
index 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.gjs
index 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 {
&rarr;&nbsp;
{{/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">
{{discourseTags
this.fakePreviousTagsTopic
tagClasses=this.previousTagClassesMap
@@ -152,7 +152,7 @@ export default class Revisions extends Component {
&rarr;&nbsp;
{{/if}}
- <span class="tag-revision__wrapper">
+ <span class="tag-revision__wrapper --current">
{{discourseTags
this.fakeCurrentTagsTopic
tagClasses=this.currentTagClassesMap
diff --git a/lib/discourse_diff.rb b/lib/discourse_diff.rb
index 3965c3b2f7f..20ad26c87c6 100644
--- a/lib/discourse_diff.rb
+++ b/lib/discourse_diff.rb
@@ -86,7 +86,7 @@ class DiscourseDiff
i += 1
end
- "<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>"
end
def side_by_side_markdown
@@ -96,8 +96,8 @@ class DiscourseDiff
table << "<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>"
else
if op_code == :delete
opposite_op_code = :add
@@ -120,16 +120,16 @@ class DiscourseDiff
end
diff = ONPDiff.new(before_tokens, after_tokens).short_diff
deleted, 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 += 1
else
if 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>"
end
end
end
diff --git a/spec/lib/discourse_diff_spec.rb b/spec/lib/discourse_diff_spec.rb
index d0eac675f60..3d6877ee685 100644
--- a/spec/lib/discourse_diff_spec.rb
+++ b/spec/lib/discourse_diff_spec.rb
@@ -70,14 +70,14 @@ RSpec.describe DiscourseDiff do
describe "side_by_side_html" do
it "returns two empty divs when no content is diffed" do
expect(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>",
)
end
it "returns the diffed content on both sides when there is no difference" do
before = 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 do
before = "<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 do
after = "<p>this is one great paragraph</p><p>here is another</p>"
got = DiscourseDiff.new(before, after).side_by_side_html
expect(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 do
before = "<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 do
before = "<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 do
before = "<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 do
before = "<p>'</p>"
after = "<p></p>"
expect(DiscourseDiff.new(before, after).side_by_side_html).to eq(
- "<div class=\"revision-content\"><p><del>&#39;</del></p></div><div class=\"revision-content\"><p></p></div>",
+ "<div class=\"revision-content --previous\"><p><del>&#39;</del></p></div><div class=\"revision-content --current\"><p></p></div>",
)
end
@@ -134,7 +134,7 @@ RSpec.describe DiscourseDiff do
before = "<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 &quot;quoted&quot; string\"></p></div><div class=\"revision-content\"><p data-attr=\"Some &quot;quoted&quot; string\"></p></div>",
+ "<div class=\"revision-content --previous\"><p data-attr=\"Some &quot;quoted&quot; string\"></p></div><div class=\"revision-content --current\"><p data-attr=\"Some &quot;quoted&quot; string\"></p></div>",
)
end
end
@@ -150,14 +150,14 @@ RSpec.describe DiscourseDiff do
before = ""
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\">&lt;img src=&quot;//domain.com/image.png&gt;&quot;</td></tr></table>",
+ "<table class=\"markdown\"><tr><td class=\"--previous\"></td><td class=\"--current diff-ins\">&lt;img src=&quot;//domain.com/image.png&gt;&quot;</td></tr></table>",
)
end
it "returns the diffed content on both columns when there is no difference" do
before = 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 do
before = "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 do
before = "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 do
before = "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 do
before = "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>",
)
end
end
diff --git a/spec/requests/admin/staff_action_logs_controller_spec.rb b/spec/requests/admin/staff_action_logs_controller_spec.rb
index 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 do
parsed = response.parsed_body
name_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>
HTML
expect(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.rb
index 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 PageObjects
end
def previous_locale
- body.find(".revision__locale .revision-content:nth-child(1)")
+ body.find(".revision__locale .revision-content.--previous")
end
def current_locale
- body.find(".revision__locale .revision-content:nth-child(2)")
+ body.find(".revision__locale .revision-content.--current")
end
def current_revision