Skip to content

Commit

Permalink
Remove individual action partials and use conditional instead
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianna-chang-shopify committed Jan 25, 2021
1 parent f435701 commit d010302
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 48 deletions.
3 changes: 2 additions & 1 deletion app/controllers/maintenance_tasks/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def index
# Shows running and completed instances of the Task.
def show
@task = TaskData.find(params.fetch(:id))
set_refresh if @task.last_run&.active?
@last_run = @task.last_run
set_refresh if @last_run&.active?
@pagy, @previous_runs = pagy(@task.previous_runs)
end

Expand Down
4 changes: 0 additions & 4 deletions app/views/maintenance_tasks/tasks/_upload_csv.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/maintenance_tasks/tasks/actions/_cancelled.html.erb

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/maintenance_tasks/tasks/actions/_enqueued.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/maintenance_tasks/tasks/actions/_errored.html.erb

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/maintenance_tasks/tasks/actions/_new.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/maintenance_tasks/tasks/actions/_paused.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/maintenance_tasks/tasks/actions/_pausing.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/maintenance_tasks/tasks/actions/_running.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/maintenance_tasks/tasks/actions/_succeeded.html.erb

This file was deleted.

29 changes: 28 additions & 1 deletion app/views/maintenance_tasks/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,34 @@
<%= render 'maintenance_tasks/runs/info', run: @task.last_run, with_status: false if @task.last_run %>

<div class="buttons">
<%= render "maintenance_tasks/tasks/actions/#{@task.status}", task: @task %>
<% last_run = @task.last_run %>
<% if last_run.nil? || last_run.completed? %>
<%= form_with url: run_task_path(@task), method: :put do |form| %>
<% if @task.csv_task? %>
<div class="block">
<%= form.label :csv_file %>
<%= form.file_field :csv_file %>
</div>
<% end %>
<div class="block">
<%= form.submit 'Run', class: "button is-success", disabled: @task.deleted? %>
</div>
<% end %>
<% elsif last_run.cancelling? %>
<%= button_to 'Run', run_task_path(@task), method: :put, class: 'button is-success', disabled: true %>
<% if last_run.stuck? %>
<%= button_to 'Cancel', cancel_task_run_path(@task, last_run), method: :put, class: 'button is-danger', disabled: @task.deleted? %>
<% end %>
<% elsif last_run.pausing? %>
<%= button_to 'Pausing', pause_task_run_path(@task, last_run), method: :put, class: 'button is-warning', disabled: true %>
<%= button_to 'Cancel', cancel_task_run_path(@task, last_run), method: :put, class: 'button is-danger' %>
<% elsif last_run.paused? %>
<%= button_to 'Resume', run_task_path(@task), method: :put, class: 'button is-primary', disabled: @task.deleted? %>
<%= button_to 'Cancel', cancel_task_run_path(@task, last_run), method: :put, class: 'button is-danger' %>
<% else %>
<%= button_to 'Pause', pause_task_run_path(@task, last_run), method: :put, class: 'button is-warning', disabled: @task.deleted? %>
<%= button_to 'Cancel', cancel_task_run_path(@task, last_run), method: :put, class: 'button is-danger' %>
<% end%>
</div>

<% if (code = @task.code) %>
Expand Down

0 comments on commit d010302

Please sign in to comment.