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 a proposal] 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.
32 lines
500 B
Ruby
32 lines
500 B
Ruby
class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
|
|
attr_reader :proposal
|
|
|
|
def initialize(proposal)
|
|
@proposal = proposal
|
|
end
|
|
|
|
private
|
|
|
|
def action
|
|
if selected?
|
|
:deselect
|
|
else
|
|
:select
|
|
end
|
|
end
|
|
|
|
def selected?
|
|
proposal.selected?
|
|
end
|
|
|
|
def options
|
|
{
|
|
"aria-label": label
|
|
}
|
|
end
|
|
|
|
def label
|
|
t("admin.actions.label", action: t("admin.actions.select"), name: proposal.title)
|
|
end
|
|
end
|