Skip to content

Commit

Permalink
Add ability to restore default labels when editing metadata fields
Browse files Browse the repository at this point in the history
Closes #3126
  • Loading branch information
marlo-longley committed Sep 18, 2024
1 parent dc3ad3b commit f7f5183
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 81 deletions.
43 changes: 19 additions & 24 deletions app/assets/javascripts/spotlight/spotlight.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.esm.js.map

Large diffs are not rendered by default.

43 changes: 19 additions & 24 deletions app/assets/javascripts/spotlight/spotlight.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/spotlight.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions app/assets/stylesheets/spotlight/_blacklight_configuration.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,27 @@
}
}

.metadata-configuration {
td, th {
padding: 0.75rem 0.25rem;
}
th {
font-size: $font-size-sm;
}
.metadata-label-edit {
max-width: fit-content;
}
.restore-default .btn {
text-wrap: nowrap;
margin-left: 0.5rem;
}
}

// the table id
#nested-fields {
margin-bottom: 1em;

// the tbody class
.metadata_fields {
.checkbox-cell {
vertical-align: middle;
Expand All @@ -59,6 +77,7 @@

.metadata-select {
display: inline-block;
text-wrap: nowrap;
min-width: 72px;
}
}
Expand Down
22 changes: 0 additions & 22 deletions app/javascript/spotlight/admin/appearance.js

This file was deleted.

19 changes: 19 additions & 0 deletions app/javascript/spotlight/admin/edit_in_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,24 @@ export default class {
return false;
});
})

$("[data-behavior='restore-default']").each(function(){
var hidden = $("[data-default-value]", $(this));
var value = $($("[data-in-place-edit-target]", $(this)).data('in-place-edit-target'), $(this));
var button = $("[data-restore-default]", $(this));
hidden.on('blur', function(){
if( $(this).val() == $(this).data('default-value') ) {
button.addClass('d-none');
} else {
button.removeClass('d-none');
}
});
button.on('click', function(e){
e.preventDefault();
hidden.val(hidden.data('default-value'));
value.text(hidden.data('default-value'));
button.hide();
});
});
}
}
2 changes: 0 additions & 2 deletions app/javascript/spotlight/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'Path.Drag'

import AddAnother from 'spotlight/admin/add_another'
import AddNewButton from 'spotlight/admin/add_new_button'
import Appearance from 'spotlight/admin/appearance'
import BlacklightConfiguration from 'spotlight/admin/blacklight_configuration'
import CopyEmailAddress from 'spotlight/admin/copy_email_addresses'
import Croppable from 'spotlight/admin/croppable'
Expand Down Expand Up @@ -60,7 +59,6 @@ export default class {
connect() {
new AddAnother().connect()
new AddNewButton().connect()
new Appearance().connect()
new CopyEmailAddress().connect()
new Croppable().connect()
new EditInPlace().connect()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<tr data-id="<%= key.parameterize %>" class="dd-item">
<% default_field_label = local_assigns.dig(:config, :original, :label) %>

<tr data-id="<%= key.parameterize %>" class="dd-item" data-behavior="restore-default">
<%= f.fields_for key do |field| %>
<td>
<%= field.hidden_field :weight, 'data-property' => 'weight' %>
<div class="handle-wrap" data-in-place-edit-target=".edit-in-place" data-in-place-edit-field-target="[data-edit-field-target='true']">
<div class="dd-handle dd3-handle"><%= t :drag %></div>
<a href="#edit-in-place" class="field-label edit-in-place"><%= config.display_label %></a>
<%= field.hidden_field :label, value: config.display_label, class: 'form-control form-control-sm', data: {:"edit-field-target" => 'true'} %>
</div>
<div class="d-flex justify-content-between">
<a href="#edit-in-place" class="field-label edit-in-place align-self-center"><%= config.display_label %></a>
<%= field.hidden_field :label, value: config.display_label, class: 'metadata-label-edit form-control form-control-sm', data: {:"edit-field-target" => 'true', default_value: default_field_label} %>
<% if default_field_label %>
<div class="restore-default">
<%= button_tag t(:'.restore_default'), data: {:"restore-default" => true}, class: "btn btn-secondary btn-sm #{'d-none' if config.display_label == default_field_label}" %>
</div>
<% end %>
</div>
</div>

</td>
<td class="checkbox-cell text-center">
<%= field.check_box_without_bootstrap :show, checked: config.show, disabled: !config.immutable.show.nil?, hide_label: true %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spotlight/metadata_configurations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

<p class="instructions"><%= t :'.instructions' %></p>

<table id="nested-fields" class="table table-striped dd-table">
<table id="nested-fields" class="metadata-configuration table table-striped dd-table">
<thead>
<tr>
<th><%= t :'.field.label' %></th>
<th class="w-50"><%= t :'.field.label' %></th>
<th class="text-center">
<div>
<%= t :'.view.show' %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ en:
browse: Browse
curated_features: Curated features
metadata_configurations:
metadata_field:
restore_default: "Restore default"
edit:
deselect_all: Deselect all
exhibit_specific:
Expand Down
33 changes: 32 additions & 1 deletion spec/features/javascript/edit_in_place_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
end

describe 'Main navigation' do
it 'updates the label' do
it 'updates the Appearance label' do
visit spotlight.exhibit_dashboard_path(exhibit)

within '#sidebar' do
Expand Down Expand Up @@ -89,5 +89,36 @@
expect(page).to have_css('h3', text: 'My Page Label')
end
end

it 'updates the metadata label' do
visit spotlight.exhibit_dashboard_path(exhibit)

within '#sidebar' do
click_link 'Metadata'
end

within('.metadata_fields') do
expect(html).to have_css("[data-id='language_ssm'][data-behavior='restore-default']", visible: true)
click_link('Language')
fill_in 'blacklight_configuration_index_fields_language_ssm_label', with: 'Not Language'
end

click_button 'Save changes'

find('input[type="submit"][value="Save changes"]').click

within('.metadata_fields') do
expect(page).to have_css('a[href="#edit-in-place"]', text: 'Not Language')
expect(page).to have_selector('button[name="button"][type="submit"][data-restore-default="true"]', text: 'Restore default', visible: true)
end

click_button 'Restore default'
click_button 'Save changes'

within('.metadata_fields') do
expect(page).to have_css('a[href="#edit-in-place"]', text: 'Language')
expect(page).to have_selector('button[name="button"][type="submit"][data-restore-default="true"]', text: 'Restore default', visible: false)
end
end
end
end

0 comments on commit f7f5183

Please sign in to comment.