Files
nairobi/app/components/admin/budgets/actions_component.rb
Javi Martín 51a0bce58c Add information about budget actions
Both the calculate winners and delete actions benefit from some kind of
hint.

The "calculate winners" hint informs administrators that results won't
be publicly available unless the "show results" option is enabled.

The delete action was redirecting with an error message when the budget
couldn't be deleted; IMHO it's better to disable it and inform
administrators why it's disabled. Alternatively we could remove the
button completely; however, users might be looking for a way to delete a
budget and wouldn't find any hint about it.

We're now removing the "Delete" action from the budgets index table,
since most of the time it isn't possible to delete a budget and so the
action takes up space and we get little gain in return. We could keep
the "Delete" icon just for budgets which can be deleted; however, the
alignment of the table rows would suffer, making it harder to find the
intended action.
2021-10-25 18:34:17 +02:00

62 lines
1.5 KiB
Ruby

class Admin::Budgets::ActionsComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def action(action_name, **options)
render Admin::ActionComponent.new(
action_name,
budget,
"aria-describedby": true,
**options
)
end
def actions
@actions ||= {
calculate_winners: {
hint: winners_hint,
html: winners_action
},
destroy: {
hint: destroy_hint,
html: destroy_action
}
}.select { |_, button| button[:html].present? }
end
def winners_action
render Admin::Budgets::CalculateWinnersButtonComponent.new(budget)
end
def winners_hint
t("admin.budgets.actions.descriptions.calculate_winners", phase: t("budgets.phase.finished"))
end
def destroy_action
action(:destroy,
text: t("admin.budgets.edit.delete"),
method: :delete,
confirm: t("admin.budgets.actions.confirm.destroy"),
disabled: budget.investments.any? || budget.poll)
end
def destroy_hint
if budget.investments.any?
t("admin.budgets.destroy.unable_notice")
elsif budget.poll
t("admin.budgets.destroy.unable_notice_polls")
else
t("admin.budgets.actions.descriptions.destroy")
end
end
def descriptor_id(action_name)
"#{dom_id(budget, action_name)}_descriptor"
end
end