<p></p>
<p><b>@pablobm</b> commented on this pull request.</p>
<p dir="auto">I love this ❤️ Some notes:</p>
<ul dir="auto">
<li>The border in the middle (<code class="notranslate">border-start</code> of value cell) looks perhaps a bit too thin to me, particularly when contrasted with the one in the left (tag name cell). Probably not a big deal, but I wonder if other variants can be experimented.</li>
<li>I see you added a background color for dark mode. To me it looks subtle enough not to clash with the text, so that's good. Still I wonder: is there a rationale for this difference?</li>
<li>I wonder if there's a way to make this work with assistive technologies too. An <code class="notranslate">aria-*</code> tag or something, but I can't find anything right now and it's a very tricky subject anyway. Perhaps for a future PR.</li>
</ul><hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#discussion_r2432248604">app/views/browse/_tag_details_with_changes.html.erb</a>:</p>
<pre style='color:#555'>> + <% tag_changes = tag_changes_for_version(tag_details_object, @old_features) %>
+ <% tag_changes.sort.each do |key, change_info| %>
</pre>
<p dir="auto">I think it's fine to have these in a single line:</p>
⬇️ Suggested change
<pre style="color: #555">- <% tag_changes = tag_changes_for_version(tag_details_object, @old_features) %>
- <% tag_changes.sort.each do |key, change_info| %>
+ <% tag_changes_for_version(tag_details_object, @old_features).sort.each do |key, change_info| %>
</pre>
<p dir="auto">On a quick search, I've seen two existing examples of what you are doing, but both look like something that should be moved to a helper instead (<a href="https://github.com/openstreetmap/openstreetmap-website/blob/6ff5918bd07673fb8db633701f77abeb16c5a1bd/app/views/layouts/_control_icons.html.erb#L1">app/views/layouts/_control_icons.html.erb</a>, <a href="https://github.com/openstreetmap/openstreetmap-website/blob/6ff5918bd07673fb8db633701f77abeb16c5a1bd/app/views/site/help.html.erb#L7-L8">app/views/site/help.html.erb</a>).</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#discussion_r2432338148">app/views/browse/_common_details.html.erb</a>:</p>
<pre style='color:#555'>> @@ -38,4 +38,8 @@
<% end %>
</div>
-<%= render :partial => "browse/tag_details", :object => common_details.tags %>
+<%= if defined?(@old_features) && @old_features
</pre>
<p dir="auto">This shouldn't be necessary in Ruby. Instance variables (starting with <code class="notranslate">@</code>) resolve to <code class="notranslate">nil</code> if not defined.</p>
⬇️ Suggested change
<pre style="color: #555">-<%= if defined?(@old_features) && @old_features
+<%= if @old_features
</pre>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#discussion_r2432338916">app/views/browse/_tag_details_with_changes.html.erb</a>:</p>
<pre style='color:#555'>> @@ -0,0 +1,18 @@
+<% unless tag_details_with_changes.empty? %>
+ <h4><%= t ".tags" %></h4>
+ <div class='mb-3 border border-secondary-subtle rounded overflow-hidden'>
+ <table class='mb-0 browse-tag-list table align-middle'>
+ <% if defined?(@old_features) && @old_features %>
</pre>
<p dir="auto">Same as above:</p>
⬇️ Suggested change
<pre style="color: #555">- <% if defined?(@old_features) && @old_features %>
+ <% if @old_features %>
</pre>
<hr>
<p>On <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#discussion_r2432403679">app/views/browse/_tag_with_changes.html.erb</a>:</p>
<p dir="auto">There's a lot of duplication across <code class="notranslate">_tag</code>/<code class="notranslate">_tag_with_changes</code> and <code class="notranslate">_tag_details</code>/<code class="notranslate">_tag_details_with_changes</code>. I wonder if they can be merged into only <code class="notranslate">_tag</code> and <code class="notranslate">_tag_details</code>, with conditionals to show the changes only when available. In this case you will need <code class="notranslate">defined?</code> as <code class="notranslate">tag_details_object</code> is a local variable, as opposed to an instance variable that will be nil if undefined.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#discussion_r2432423139">app/helpers/browse_helper.rb</a>:</p>
<pre style='color:#555'>> + changes = {}
+
+ # Check for added and modified tags
+ current_tags.each do |key, value|
+ if !previous_tags.key?(key)
+ changes[key] = { type: :added, current: value }
+ elsif previous_tags[key] != value
+ changes[key] = { type: :modified, current: value, previous: previous_tags[key] }
+ else
+ changes[key] = { type: :unchanged, current: value }
+ end
+ end
</pre>
<p dir="auto">I try to avoid <code class="notranslate">each</code> for these things because it often means "anything could happen here!". Using idiomatic methods like <code class="notranslate">each_with_object</code> helps communicating that, eg: "we are going to build a hash step by step":</p>
⬇️ Suggested change
<pre style="color: #555">- changes = {}
-
- # Check for added and modified tags
- current_tags.each do |key, value|
- if !previous_tags.key?(key)
- changes[key] = { type: :added, current: value }
- elsif previous_tags[key] != value
- changes[key] = { type: :modified, current: value, previous: previous_tags[key] }
- else
- changes[key] = { type: :unchanged, current: value }
- end
- end
+ changes = current_tags.each_with_object({}) do |(key, value), memo|
+ if !previous_tags.key?(key)
+ memo[key] = { type: :added, current: value }
+ elsif previous_tags[key] != value
+ memo[key] = { type: :modified, current: value, previous: previous_tags[key] }
+ else
+ memo[key] = { type: :unchanged, current: value }
+ end
+ end
</pre>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#discussion_r2432608758">app/helpers/browse_helper.rb</a>:</p>
<pre style='color:#555'>> + previous_tags.each do |key, value|
+ unless current_tags.key?(key)
+ changes[key] = { type: :deleted, previous: value }
+ end
+ end
</pre>
<p dir="auto">Another way to do this. In Ruby you can do Array difference with <code class="notranslate">-</code>. Also you are not using the <code class="notranslate">previous</code> for deleted tags, so it can be removed:</p>
⬇️ Suggested change
<pre style="color: #555">- previous_tags.each do |key, value|
- unless current_tags.key?(key)
- changes[key] = { type: :deleted, previous: value }
- end
- end
+ (previous_tags.keys - current_tags.keys).each do |key|
+ changes[key] = { type: :deleted }
+ end
</pre>
<p dir="auto">I have to admit that in this instance I'm not 100% sure if my alternative is too clever. Thoughts?</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6448#pullrequestreview-3339952946">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLJLC47WSTND2YLOOOL3XZFMTAVCNFSM6AAAAACJGVZNZ2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTGMZZHE2TEOJUGY">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLIISOZEBL7HXCTVRPT3XZFMTA5CNFSM6AAAAACJGVZNZ2WGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTWHCORTE.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/6448/review/3339952946</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/6448#pullrequestreview-3339952946",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/6448#pullrequestreview-3339952946",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>