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/
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
<div class="budgets-links">
|
<div class="budgets-links">
|
||||||
<% if can?(:read_results, budget) %>
|
<% if can?(:read_results, budget) %>
|
||||||
<%= action(:results, text: results_text, path: budget_results_path(budget)) %>
|
<%= action(:results, text: results_text, path: budget_results_path(budget)) %>
|
||||||
|
<% else %>
|
||||||
|
<%= action(:preview, text: preview_text, path: budget_path(budget)) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= action(:preview, text: t("admin.budgets.actions.preview"), path: budget_path(budget), target: "_blank") %>
|
|
||||||
|
|
||||||
<%= action(:edit, text: t("admin.budgets.actions.edit")) %>
|
<%= action(:edit, text: t("admin.budgets.actions.edit")) %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,4 +19,12 @@ class Admin::Budgets::LinksComponent < ApplicationComponent
|
|||||||
t("admin.budgets.actions.preview_results")
|
t("admin.budgets.actions.preview_results")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def preview_text
|
||||||
|
if budget.published?
|
||||||
|
t("admin.shared.view")
|
||||||
|
else
|
||||||
|
t("admin.budgets.actions.preview")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do
|
|||||||
|
|
||||||
expect(page).to have_link "Preview results"
|
expect(page).to have_link "Preview results"
|
||||||
expect(page).not_to have_link "See results"
|
expect(page).not_to have_link "See results"
|
||||||
|
expect(page).not_to have_link "View"
|
||||||
|
expect(page).not_to have_link "Preview"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not shown while balloting" do
|
it "is not shown while balloting" do
|
||||||
@@ -56,4 +58,24 @@ describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "preview/view link" do
|
||||||
|
it "shows a link to preview an unpublished budget" do
|
||||||
|
budget = create(:budget, :drafting)
|
||||||
|
|
||||||
|
render_inline Admin::Budgets::LinksComponent.new(budget)
|
||||||
|
|
||||||
|
expect(page).to have_link "Preview"
|
||||||
|
expect(page).not_to have_link "View"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows a link to view a published budget" do
|
||||||
|
budget = create(:budget, :informing)
|
||||||
|
|
||||||
|
render_inline Admin::Budgets::LinksComponent.new(budget)
|
||||||
|
|
||||||
|
expect(page).to have_link "View"
|
||||||
|
expect(page).not_to have_link "Preview"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -115,13 +115,12 @@ describe "Admin budgets", :admin do
|
|||||||
|
|
||||||
scenario "Can preview budget before it is published" do
|
scenario "Can preview budget before it is published" do
|
||||||
visit admin_budget_path(budget)
|
visit admin_budget_path(budget)
|
||||||
|
click_link "Preview"
|
||||||
|
|
||||||
within_window(window_opened_by { click_link "Preview" }) do
|
|
||||||
expect(page).to have_current_path budget_path(budget)
|
expect(page).to have_current_path budget_path(budget)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Can preview a budget after it is published" do
|
scenario "Can view a budget after it is published" do
|
||||||
visit admin_budget_path(budget)
|
visit admin_budget_path(budget)
|
||||||
|
|
||||||
accept_confirm { click_button "Publish budget" }
|
accept_confirm { click_button "Publish budget" }
|
||||||
@@ -130,11 +129,11 @@ describe "Admin budgets", :admin do
|
|||||||
expect(page).not_to have_content "This participatory budget is in draft mode"
|
expect(page).not_to have_content "This participatory budget is in draft mode"
|
||||||
expect(page).not_to have_button "Publish budget"
|
expect(page).not_to have_button "Publish budget"
|
||||||
|
|
||||||
within_window(window_opened_by { click_link "Preview" }) do
|
click_link "View"
|
||||||
|
|
||||||
expect(page).to have_current_path budget_path(budget)
|
expect(page).to have_current_path budget_path(budget)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "Destroy" do
|
context "Destroy" do
|
||||||
let!(:budget) { create(:budget) }
|
let!(:budget) { create(:budget) }
|
||||||
|
|||||||
Reference in New Issue
Block a user