Skip to content

Commit

Permalink
Use keyword arguments in private helper method
Browse files Browse the repository at this point in the history
This makes it a bit clearer what the various passed in strings are for
  • Loading branch information
yndajas committed Oct 3, 2024
1 parent b2ff29e commit de5061b
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions app/helpers/application_table_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ def grant_access_link(application, user = nil)
path,
class: "govuk-button govuk-!-margin-0",
data: { module: "govuk-button" },
) { button_or_link_content("Grant", "access to", application.name) }
) do
button_or_link_content(
visible_text: "Grant",
visually_hidden_text: "access to #{application.name}",
)
end
end

def remove_access_link(application, user = nil)
Expand All @@ -83,7 +88,12 @@ def remove_access_link(application, user = nil)
path,
class: "govuk-button govuk-button--warning govuk-!-margin-0 applications-table__remove_access_link",
data: { module: "govuk-button" },
) { button_or_link_content("Remove", "access to", application.name) }
) do
button_or_link_content(
visible_text: "Remove",
visually_hidden_text: "access to #{application.name}",
)
end
end

def view_permissions_link(application, user = nil)
Expand All @@ -93,7 +103,12 @@ def view_permissions_link(application, user = nil)
account_application_permissions_path(application)
end

link_to(path, class: "govuk-link") { button_or_link_content("View", "permissions for", application.name) }
link_to(path, class: "govuk-link") do
button_or_link_content(
visible_text: "View",
visually_hidden_text: "permissions for #{application.name}",
)
end
end

def update_permissions_link(application, user = nil)
Expand All @@ -111,13 +126,18 @@ def update_permissions_link(application, user = nil)
edit_user_application_permissions_path(user, application)
end

link_to(path, class: "govuk-link") { button_or_link_content("Update", "permissions for", application.name) }
link_to(path, class: "govuk-link") do
button_or_link_content(
visible_text: "Update",
visually_hidden_text: "permissions for #{application.name}",
)
end
end

def button_or_link_content(visible_text, visually_hidden_join_word, application_name)
def button_or_link_content(visible_text:, visually_hidden_text:)
safe_join([
visible_text,
content_tag(:span, " #{visually_hidden_join_word} #{application_name}", class: "govuk-visually-hidden"),
content_tag(:span, " #{visually_hidden_text.strip}", class: "govuk-visually-hidden"),
])
end
end

0 comments on commit de5061b

Please sign in to comment.