Skip to content

Commit

Permalink
Improve page titles (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
majjikishore007 authored Dec 27, 2024
1 parent e3d74d3 commit dbf2645
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/controllers/signed_in_application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SignedInApplicationController < ApplicationController
before_action :require_login, unless: :authentication_controllers?
before_action :track_behaviour
before_action :set_app
before_action :set_page_name

helper_method :current_organization,
:current_user,
Expand All @@ -36,6 +37,27 @@ class SignedInApplicationController < ApplicationController

rescue_from NotAuthorizedError, with: :user_not_authorized

private

def set_page_name
user_facing_actions = %w[new index show edit]

if user_facing_actions.include?(params[:action])
controller_key = params[:controller].split("/").last
action = params[:action]
controller_name = I18n.t("page_titles.controllers.#{controller_key}.name", default: controller_key)
action_name = I18n.t("page_titles.controllers.#{controller_key}.actions.#{action}", default: action)
suffix = action_suffix?(action) ? action_name : controller_name
@page_name = suffix
else
@page_name = params[:action]
end
end

def action_suffix?(action)
%w[new edit].include?(action)
end

protected

def logout_path
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,16 @@ def duration_in_words(seconds)
return NOT_AVAILABLE unless seconds
distance_of_time_in_words(0, seconds, include_seconds: true)
end

def page_title(page_name, current_organization, app, release)
suffix = I18n.t("page_titles.default_suffix", default: "Tramline")
middle_section = app&.name || current_organization&.name
prefix = if release&.original_release_version.present?
release.original_release_version
else
page_name || middle_section
end

[prefix.titleize, middle_section.titleize, suffix.titleize].compact.join(" | ")
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/signed_in_application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html class="light">
<head>
<%= render partial: "shared/favicon" %>
<title><%= current_organization.name %> | Tramline</title>
<title><%= page_title(@page_name, current_organization, @app, @release) %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
Expand Down
80 changes: 80 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,84 @@
en:
page_titles:
default_suffix: "Tramline"
controllers:
apps:
name: "Apps"
actions:
index: "Apps" # "Apps | Ueno | Tramline"
show: "App Details" # "App Details | Ueno | Tramline"
new: "App New" # "App New | Ueno | Tramline" (instead of "New App")
edit: "App Edit" # "App Edit | Ueno | Tramline" (instead of "Edit App")
# Releases Controller
releases:
name: "Releases"
actions:
index: "Releases" # "Releases | Ueno | Tramline"
show: "Release Details" # "Release Details | Ueno | Tramline"
new: "Release New" # "Release New | Ueno | Tramline" (instead of "New Release")
edit: "Release Edit" # "Release Edit | Ueno | Tramline" (instead of "Edit Release")
# Trains Controller
trains:
name: "Trains"
actions:
index: "Trains" # "Trains | Ueno | Tramline"
show: "Train Details" # "Train Details | Ueno | Tramline"
new: "Train New" # "Train New | Ueno | Tramline" (instead of "New Train")
edit: "Train Edit" # "Train Edit | Ueno | Tramline" (instead of "Edit Train")
# Organizations Controller (Accounts::Organizations)
organizations:
name: "Organizations"
actions:
index: "Organizations"
show: "Organization Details"
new: "Organization New"
edit: "Organization Edit"
# Users Controller (Accounts::Users)
users:
name: "Users"
actions:
index: "Users"
show: "User Details"
new: "User New"
edit: "User Edit"
# Admin::SettingsController
settings:
name: "Settings"
actions:
index: "Settings"
show: "Setting Details"
new: "Setting New"
edit: "Setting Edit"
# Integrations Controller
integrations:
name: "Integrations"
actions:
index: "Integrations"
show: "Integration Details"
new: "Integration New"
edit: "Integration Edit"
# ReleaseHealthRules Controller
release_health_rules:
name: "Release Health Rules"
actions:
index: "Rules"
show: "Rule Details"
new: "Rule New"
edit: "Rule Edit"
release_indices:
name: "Reldex"
actions:
index: "Reldex"
show: "Reldex Details"
edit: "Reldex Edit"
store_submissions:
name: "Submissions"
actions:
index: "Submissions"
show: "Submission Details"
new: "Submission New"
edit: "Submission Edit"

config:
release_platforms:
success: "Platform configuration was successfully updated."
Expand Down

0 comments on commit dbf2645

Please sign in to comment.