This is consistent to what we usually do. Also, we're applying the same
criteria mentioned in commit 72704d776:
> We're also making these actions idempotent, so sending many requests
> to the same action will get the same result, which wasn't the case
> with the `toggle` action. Although it's a low probability case, the
> `toggle` action could result in [selecting an investment] when trying
> to [deselect] it if someone else has [deselected it] it between the
> time the page loaded and the time the admin clicked on the
> "[Selected]" button.
50 lines
1.0 KiB
Ruby
50 lines
1.0 KiB
Ruby
class Admin::BudgetInvestments::ToggleSelectionComponent < ApplicationComponent
|
|
attr_reader :investment
|
|
use_helpers :can?
|
|
delegate :selected?, to: :investment
|
|
|
|
def initialize(investment)
|
|
@investment = investment
|
|
end
|
|
|
|
private
|
|
|
|
def selected_text
|
|
t("admin.budget_investments.index.selected")
|
|
end
|
|
|
|
def action
|
|
if selected?
|
|
:deselect
|
|
else
|
|
:select
|
|
end
|
|
end
|
|
|
|
def path
|
|
url_for({
|
|
controller: "admin/budget_investments",
|
|
action: action,
|
|
budget_id: investment.budget,
|
|
id: investment,
|
|
filter: params[:filter],
|
|
sort_by: params[:sort_by],
|
|
min_total_supports: params[:min_total_supports],
|
|
max_total_supports: params[:max_total_supports],
|
|
advanced_filters: params[:advanced_filters],
|
|
page: params[:page]
|
|
})
|
|
end
|
|
|
|
def options
|
|
{
|
|
"aria-label": label,
|
|
path: path
|
|
}
|
|
end
|
|
|
|
def label
|
|
t("admin.actions.label", action: t("admin.actions.select"), name: investment.title)
|
|
end
|
|
end
|