Implement failed snapshot pop-up on task screen [SCI-6612] (#3950)

* Implement failed snapshot pop-up on task screen [SCI-6612]

* Copy change [SCI-6612]

* Proper handling of snapshot transition error [SCI-6612]

* Move modal auto open logic to JS file [SCI-6612]

* Remove unnecessary .html_safe [SCI-6612]
This commit is contained in:
artoscinote 2022-04-04 11:04:03 +02:00 committed by GitHub
parent a629e1ae71
commit 401a32edd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 101 additions and 1 deletions

View file

@ -0,0 +1,3 @@
$(document).on('turbolinks:load', function() {
$('.modal-auto-open').modal('show');
});

View file

@ -0,0 +1,38 @@
.sci-dialog {
.modal-dialog {
width: 500px;
}
.sci-dialog__icon {
margin-right: 1em;
.fas {
font-size: 2.5em;
}
&.error .fas {
color: $brand-danger;
}
&.warning .fas {
color: $brand-warning;
}
&.info .fas {
color: $brand-info;
}
&.success .fas {
color: $brand-success;
}
}
.modal-body {
display: flex;
}
.modal-footer {
text-align: center;
}
}

View file

@ -47,6 +47,10 @@ class MyModulesController < ApplicationController
def status_state def status_state
respond_to do |format| respond_to do |format|
format.json do format.json do
if @my_module.last_transition_error && @my_module.last_transition_error['type'] == 'repository_snapshot'
flash[:repository_snapshot_error] = @my_module.last_transition_error
end
render json: { status_changing: @my_module.status_changing? } render json: { status_changing: @my_module.status_changing? }
end end
end end

View file

@ -10,7 +10,9 @@ class MyModuleStatusConsequencesJob < ApplicationJob
consequence.public_send(status_changing_direction, my_module) consequence.public_send(status_changing_direction, my_module)
end end
my_module.update!(status_changing: false) my_module.update!(status_changing: false)
my_module.update!(last_transition_error: nil)
# don't clear error if in transition error rollback state
my_module.update!(last_transition_error: nil) unless my_module.transition_error_rollback
rescue StandardError => e rescue StandardError => e
Rails.logger.error(e.message) Rails.logger.error(e.message)
Rails.logger.error(e.backtrace.join("\n")) Rails.logger.error(e.backtrace.join("\n"))
@ -22,6 +24,7 @@ class MyModuleStatusConsequencesJob < ApplicationJob
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
if error.present? if error.present?
my_module.transition_error_rollback = true
my_module.my_module_status = my_module.changing_from_my_module_status my_module.my_module_status = my_module.changing_from_my_module_status
my_module.last_transition_error = error my_module.last_transition_error = error
my_module.status_changing = false my_module.status_changing = false

View file

@ -10,6 +10,8 @@ class MyModule < ApplicationRecord
include PermissionCheckableModel include PermissionCheckableModel
include Assignable include Assignable
attr_accessor :transition_error_rollback
enum state: Extends::TASKS_STATES enum state: Extends::TASKS_STATES
before_validation :archiving_and_restoring_extras, on: :update, if: :archived_changed? before_validation :archiving_and_restoring_extras, on: :update, if: :archived_changed?

View file

@ -1,3 +1,17 @@
<% if flash["repository_snapshot_error"] %>
<%= render 'shared/dialog',
id: "snapshot-error",
type: "error",
shown: true,
title: t("my_modules.modals.snapshot_error.title"),
body:
t(
"my_modules.modals.snapshot_error.body_html",
repository: Repository.find(flash["repository_snapshot_error"]["repository_id"]).name
)
%>
<% end %>
<% provide(:head_title, t("my_modules.protocols.head_title", project: h(@project.name), module: h(@my_module.name)).html_safe) %> <% provide(:head_title, t("my_modules.protocols.head_title", project: h(@project.name), module: h(@my_module.name)).html_safe) %>
<% content_for :open_mobile_app_button do %> <% content_for :open_mobile_app_button do %>
<span class="open-mobile-app-container"> <span class="open-mobile-app-container">

View file

@ -0,0 +1,32 @@
<div id="<%= id %>" class="sci-dialog modal fade <%= 'modal-auto-open' if defined?(shown) && shown %>" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><%= title %></h4>
</div>
<div class="modal-body">
<div class="sci-dialog__icon <%= type %>">
<% case type %>
<% when 'error', 'warning' %>
<i class="fas fa-exclamation-triangle"></i>
<% when 'info' %>
<i class="fas fa-info"></i>
<% when 'success' %>
<i class="fas fa-check-circle"></i>
<% else %>
<i class="fas fa-info"></i>
<% end %>
</div>
<div class="sci-dialog__body">
<%= body %>
</div>
</div>
<div class="modal-footer text-center">
<button type="button"
class="btn btn-primary"
data-dismiss="modal"><%= defined?(button_text) ? button_text : t('general.okay') %></button>
</div>
</div>
</div>
</div>

View file

@ -1046,6 +1046,9 @@ en:
hidden_tasks: "No permission: There are %{size} tasks you cant assign to." hidden_tasks: "No permission: There are %{size} tasks you cant assign to."
task: 'Assign to task' task: 'Assign to task'
task_and_downstream: 'Assign to task & downstream' task_and_downstream: 'Assign to task & downstream'
snapshot_error:
title: "Cannot change status"
body_html: "The task cannot be moved to the next status because the <strong>%{repository}</strong> inventory snapshot failed to generate. Please contact support if this problem persists."
modules_list_partial: modules_list_partial:
private_tasks_html: 'Assigned to <strong>%{nr}</strong> private task(s)' private_tasks_html: 'Assigned to <strong>%{nr}</strong> private task(s)'
no_results: no_results:
@ -2865,6 +2868,7 @@ en:
edit: "Edit" edit: "Edit"
delete: "Delete" delete: "Delete"
cancel: "Cancel" cancel: "Cancel"
okay: "Okay"
back: "Back" back: "Back"
close: "Close" close: "Close"
create: 'Create' create: 'Create'