Skip to content

Commit

Permalink
Merge pull request #2643 from archivesspace/ANW-1165
Browse files Browse the repository at this point in the history
ANW-1165: allow suppressed enum values to be deleted in one step
  • Loading branch information
Brian Hoffman committed Mar 1, 2022
2 parents 3b1f8e1 + 23eb570 commit 9f24d24
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions frontend/app/controllers/enumerations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ def update_value
def destroy
@enumeration = JSONModel(:enumeration).find(params[:id])
@value = params["enumeration"]["value"]
@enumeration_value = JSONModel(:enumeration_value).find( params["enumeration"]["enumeration_value_id"])


begin
# ANW-1165: Unsuppress value before attempting to delete
@enumeration_value.set_suppressed(false) if @enumeration_value["suppressed"] == true

@enumeration.values -= [@value]
@enumeration.save

Expand Down
1 change: 1 addition & 0 deletions frontend/app/views/enumerations/_delete.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="controls label-only">
<%= @value %>
<%= form.hidden_input :value, @value %>
<%= form.hidden_input :enumeration_value_id, params["enumeration_value_id"] %>
</div>
</div>
</fieldset>
Expand Down
8 changes: 5 additions & 3 deletions frontend/app/views/enumerations/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@
<% else %>
<%= link_to I18n.t("actions.suppress"), {:controller => :enumerations, :action => :update_value, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :enumeration_value_id => enum_value["id"], :suppressed => 1 }, :method => :post, :class=> "btn btn-xs btn-warning", :disabled => 'disabled' %>
<% end%>
<% if @enumeration['editable'] && !Array(@enumeration['readonly_values']).include?(enum_value['value']) && !enum_value["suppressed"] %>
<%= link_to I18n.t("actions.merge"), {:controller => :enumerations, :action => :delete, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :merge => true, :value => enum_value["value"]}, "data-toggle" => "modal-ajax", :class=> "btn btn-xs btn-info" %>
<%= link_to I18n.t("actions.delete"), {:controller => :enumerations, :action => :delete, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :value => enum_value['value']}, "data-toggle" => "modal-ajax", :class=> "btn btn-xs btn-danger" %>
<% if @enumeration['editable'] && !Array(@enumeration['readonly_values']).include?(enum_value['value']) %>
<% unless enum_value["suppressed"] %>
<%= link_to I18n.t("actions.merge"), {:controller => :enumerations, :action => :delete, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :merge => true, :value => enum_value["value"]}, "data-toggle" => "modal-ajax", :class=> "btn btn-xs btn-info" %>
<% end %>
<%= link_to I18n.t("actions.delete"), {:controller => :enumerations, :action => :delete, :id => JSONModel(:enumeration).id_for(@enumeration["uri"]), :enumeration_value_id => enum_value["id"], :value => enum_value['value']}, "data-toggle" => "modal-ajax", :class=> "btn btn-xs btn-danger" %>
<% end %>
</div>
</td>
Expand Down
29 changes: 28 additions & 1 deletion frontend/spec/selenium/spec/enumeration_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@
@driver.click_and_wait_until_element_gone(foo.find_element(:link, 'Suppress'))

expect(@driver.find_element_with_text('//tr', /fooman/).find_element(:link, 'Unsuppress')).not_to be_nil
expect(@driver.find_element_with_text('//tr', /fooman/).find_elements(:link, 'Delete').length).to eq(0)

# now lets make sure it's there
@driver.find_element(:link, 'Create').click
Expand Down Expand Up @@ -258,6 +257,34 @@
@driver.click_and_wait_until_gone(css: "form#delete_enumeration button[type='submit']")
end

it 'lets you delete a suppressed enumeration value' do
@driver.go_home
@driver.get($frontend)
@driver.find_element(:link, 'System').click
@driver.wait_for_dropdown
@driver.click_and_wait_until_gone(:link, 'Manage Controlled Value Lists')

enum_select = @driver.find_element(id: 'enum_selector')
enum_select.select_option_with_text('Collection Management Processing Priority (collection_management_processing_priority)')

@driver.find_element(:css, '.enumeration-list')

@driver.wait_for_dropdown
@driver.find_element(:link, 'Create Value').click

@driver.clear_and_send_keys([:id, 'enumeration_value_'], 'barman')
@driver.click_and_wait_until_gone(:css, '.modal-footer .btn-primary')

foo = @driver.find_element_with_text('//tr', /barman/)
@driver.click_and_wait_until_element_gone(foo.find_element(:link, 'Suppress'))

@driver.find_element_with_text('//tr', /barman/).find_element(:link, 'Delete').click
@driver.click_and_wait_until_gone(css: "form#delete_enumeration button[type='submit']")

@driver.find_element_with_text('//div', /Value Deleted/)
@driver.ensure_no_such_element(:xpath, "//td[contains(text(), \"barman\" )]")
end

it 'lets you set a default value with another value suppressed' do
@driver.go_home
@driver.get($frontend)
Expand Down

0 comments on commit 9f24d24

Please sign in to comment.