Skip to content

Commit

Permalink
Refactor labels to badges (#3503)
Browse files Browse the repository at this point in the history
From the migrations documentation of Bootstrap v4 -> v5:

> - Consolidated .label and .badge to disambiguate from the <label> element and simplify related components.

This change refactors the usage of labels to their counterparts as badges. Namely the logout label/badge and the representation of booleans. The label classes currently referenced no longer exist.
  • Loading branch information
fuegas committed Apr 5, 2022
1 parent 9c72851 commit 42d668f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/views/layouts/rails_admin/_secondary_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<% end %>
<% if logout_path.present? %>
<li class="nav-item">
<%= link_to t('admin.misc.log_out'), logout_path, method: logout_method, class: 'nav-link label label-danger', data: {turbo: 'false'} %>
<%= link_to logout_path, method: logout_method, class: 'nav-link', data: {turbo: 'false'} do %>
<span class="badge bg-danger"><%= t('admin.misc.log_out') %></span>
<% end %>
</li>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/types/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Boolean < RailsAdmin::Config::Fields::Base
end

register_instance_option :pretty_value do
%(<span class="label label-#{css_classes[form_value]}">#{labels[form_value]}</span>).html_safe
%(<span class="badge bg-#{css_classes[form_value]}">#{labels[form_value]}</span>).html_safe
end

register_instance_option :export_value do
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/rails_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
is_expected.to have_content 'Log out'
end

it 'has label-danger class on log out link' do
it 'has bg-danger class on log out link' do
visit dashboard_path
is_expected.to have_selector('.label-danger')
is_expected.to have_selector('.bg-danger')
end

it 'has links for actions which are marked as show_in_navigation' do
Expand Down
6 changes: 3 additions & 3 deletions spec/rails_admin/config/fields/types/boolean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

describe '#pretty_value' do
{
false => %(<span class="label label-danger"><span class="fas fa-times"></span></span>),
true => %(<span class="label label-success"><span class="fas fa-check"></span></span>),
nil => %(<span class="label label-default"><span class="fas fa-minus"></span></span>),
false => %(<span class="badge bg-danger"><span class="fas fa-times"></span></span>),
true => %(<span class="badge bg-success"><span class="fas fa-check"></span></span>),
nil => %(<span class="badge bg-default"><span class="fas fa-minus"></span></span>),
}.each do |field_value, expected_result|
context "when field value is '#{field_value.inspect}'" do
let(:test_object) { FieldTest.new(boolean_field: field_value) }
Expand Down

0 comments on commit 42d668f

Please sign in to comment.