Move phases and actions out of the budget form

Having links in the middle of a form distracts users from the task of
filling in the form, and following a link before submitting the form
will mean whatever has been filled in is lost.

And the budgets form is already very long and hard to fill in. Having
the phases table in the middle of it made it even harder. And, since
we're planning to add the option to manage groups and headings from the
same page, it's better to have a dedicated page for the form.
This commit is contained in:
Javi Martín
2021-08-23 01:00:05 +02:00
parent 8aa6f29d6b
commit 349dbb74d7
22 changed files with 158 additions and 73 deletions

View File

@@ -1,12 +1,5 @@
<div class="budgets-actions">
<%= render Admin::Budgets::CalculateWinnersButtonComponent.new(budget) %>
<% if budget.has_winning_investments? %>
<%= link_to t("budgets.show.see_results"),
budget_results_path(budget),
class: "button hollow" %>
<% end %>
<%= link_to t("admin.budgets.actions.preview"), budget_path(budget), class: "preview-link", target: "_blank" %>
<%= action(:destroy,
text: t("admin.budgets.edit.delete"),

View File

@@ -21,10 +21,6 @@ class Admin::Budgets::CalculateWinnersButtonComponent < ApplicationComponent
end
def html_class
if from_investments
"button hollow float-right clear"
else
"button hollow"
end
"button hollow float-right clear" if from_investments
end
end

View File

@@ -39,6 +39,12 @@
</div>
</div>
<% unless wizard? %>
<div class="small-12 medium-6 column">
<%= f.select :phase, phases_select_options %>
</div>
<% end %>
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "/images/nested_image", f: f %>
@@ -64,15 +70,6 @@
</fieldset>
<% unless wizard? %>
<fieldset>
<legend><%= t("admin.budgets.edit.info.phases_settings") %></legend>
<div class="small-12 medium-6 column">
<%= f.select :phase, phases_select_options %>
</div>
<%= render Admin::BudgetPhases::PhasesComponent.new(budget) %>
</fieldset>
<%= render "admin/shared/show_results_fields", form: f %>
<% end %>

View File

@@ -0,0 +1,11 @@
<div class="budgets-links">
<% if budget.has_winning_investments? %>
<%= action(:results,
text: t("budgets.show.see_results"),
path: budget_results_path(budget)) %>
<% end %>
<%= action(:preview, text: t("admin.budgets.actions.preview"), path: budget_path(budget), target: "_blank") %>
<%= action(:edit, text: t("admin.budgets.actions.edit")) %>
</div>

View File

@@ -0,0 +1,13 @@
class Admin::Budgets::LinksComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def action(action_name, **options)
render Admin::ActionComponent.new(action_name, budget, **options)
end
end

View File

@@ -0,0 +1,18 @@
<main class="admin-budgets-show">
<%= back_link_to admin_budgets_path %>
<%= header %>
<%= render Admin::Budgets::DraftingComponent.new(budget) %>
<%= render Admin::Budgets::LinksComponent.new(budget) %>
<section aria-labelledby="phases_header">
<h3 id="phases_header"><%= t("admin.budgets.edit.phases_caption") %></h3>
<%= render Admin::BudgetPhases::PhasesComponent.new(budget) %>
</section>
<section aria-labelledby="actions_header">
<h3 id="actions_header"><%= t("admin.budgets.edit.actions") %></h3>
<%= render Admin::Budgets::ActionsComponent.new(budget) %>
</section>
</main>

View File

@@ -0,0 +1,14 @@
class Admin::Budgets::ShowComponent < ApplicationComponent
include Header
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def title
budget.name
end
end

View File

@@ -1,4 +1,4 @@
<%= render Admin::TableActionsComponent.new(budget) do |actions| %>
<%= render Admin::TableActionsComponent.new(budget, edit_path: admin_budget_path(budget)) do |actions| %>
<%= actions.action(:investments,
text: t("admin.budgets.index.budget_investments"),
path: admin_budget_budget_investments_path(budget_id: budget.id)) %>