Skip to content

Commit

Permalink
Extract sidebar buttons creation to a helper
Browse files Browse the repository at this point in the history
For editions not in the "published" state.
  • Loading branch information
mtaylorgds committed Feb 27, 2025
1 parent 939b95f commit 40f99d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 11 additions & 0 deletions app/helpers/editions_sidebar_buttons_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ def published_sidebar_buttons(edition)
end
buttons << link_to("View on GOV.UK (opens in new tab)", view_homepage_path, rel:"noreferrer noopener", target:"_blank", class: "govuk-link")
end

def non_published_sidebar_buttons(edition)
buttons = []
if current_user.has_editor_permissions?(edition) && !edition.retired_format?
buttons << (render "govuk_publishing_components/components/button", {
text: "Save",
margin_bottom: 3,
})
end
buttons << link_to("Preview (opens in new tab)", preview_edition_path(edition), target: "_blank", rel: "noopener", class: "govuk-link")
end
end
8 changes: 1 addition & 7 deletions app/views/editions/secondary_nav_tabs/_edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@
} %>

<%= render "govuk_publishing_components/components/list", {
items: [
(render "govuk_publishing_components/components/button", {
text: "Save",
margin_bottom: 3,
} if current_user.has_editor_permissions?(@resource) && !@resource.retired_format?),
link_to("Preview (opens in new tab)", preview_edition_path(@resource), target: "_blank", rel: "noopener", class: "govuk-link"),
],
items: non_published_sidebar_buttons(@resource),
} %>
</div>
</div>
Expand Down

0 comments on commit 40f99d6

Please sign in to comment.