Files
nairobi/app/components/admin/budgets/links_component.rb
Javi Martín 0cc3f04096 Don't show preview link for budgets with results
We currently don't have any links in the public area pointing to past
budgets, so having links in the admin section to both the budget and its
results seemed a bit redundant. We're going to add more links to the
budget actions soon, so we need to make room for them; otherwise we'll
have too many.

We're also changing the "Preview" text for a published budget. Since the
budget is already public, we aren't previewing it anymore but simply
viewing it.

And, to be consistent with the "See results" link, we're opening the
"Preview" link in the current tab. Opening links in a new tab is
generally a bad idea because takes control away from users, breaks the
back button and makes navigation particularly hard on mobile browsers.
It could be argued that in this case it's useful when users are editing
the budget in one tab and previewing it in another one, so we might add
this behavior back as long as we make it clear that the link opens in a
new tab [1].

[1] https://www.nngroup.com/articles/new-browser-windows-and-tabs/
2021-10-25 18:01:47 +02:00

31 lines
664 B
Ruby

class Admin::Budgets::LinksComponent < ApplicationComponent
attr_reader :budget
delegate :can?, to: :helpers
def initialize(budget)
@budget = budget
end
private
def action(action_name, **options)
render Admin::ActionComponent.new(action_name, budget, **options)
end
def results_text
if Abilities::Everyone.new(User.new).can?(:read_results, budget)
t("budgets.show.see_results")
else
t("admin.budgets.actions.preview_results")
end
end
def preview_text
if budget.published?
t("admin.shared.view")
else
t("admin.budgets.actions.preview")
end
end
end