From 9b7098115d8979f1905080b3e92a649bbc1f89d2 Mon Sep 17 00:00:00 2001 From: Paul Sarando Date: Wed, 25 Oct 2023 20:57:30 -0700 Subject: [PATCH] CORE-1968 Add dynamic titles to some pages Set the path/file/folder in the page title for the data listing page, app category name in the app listing page, team/collection name in the teams/collections pages, and the search term in the subscriptions and search pages. --- public/static/locales/en/collections.json | 1 + public/static/locales/en/data.json | 1 + public/static/locales/en/search.json | 1 + public/static/locales/en/subscriptions.json | 1 + public/static/locales/en/teams.json | 1 + src/pages/admin/subscriptions.js | 12 ++++++++++-- src/pages/apps.js | 10 ++++++++-- src/pages/collections/[collectionName].js | 11 +++++++++-- src/pages/data/ds/[...pathItems].js | 13 +++++++++++-- src/pages/search.js | 12 ++++++++++-- src/pages/teams/[teamName].js | 9 +++++++-- 11 files changed, 60 insertions(+), 12 deletions(-) diff --git a/public/static/locales/en/collections.json b/public/static/locales/en/collections.json index 83fe5b1b6..db32e6475 100644 --- a/public/static/locales/en/collections.json +++ b/public/static/locales/en/collections.json @@ -27,6 +27,7 @@ "noCollections": "No $t(featureName_plural)", "noExternalApps": "Adding Agave/HPC apps is not currently supported", "noExternalAppsNote": "NOTE: $t(noExternalApps).", + "pageTitle": "Collection - {{name}}", "remove": "Remove", "retagApps": "Re-tag Apps", "retagAppsMessage": "{{name}} currently has apps associated with it. Renaming the $t(featureName) will cause all the currently tagged apps to be re-tagged with the new $t(featureName) name. Do you wish to continue?", diff --git a/public/static/locales/en/data.json b/public/static/locales/en/data.json index 8139a0826..762074cad 100644 --- a/public/static/locales/en/data.json +++ b/public/static/locales/en/data.json @@ -100,6 +100,7 @@ "noContent": "No content to display.", "ok": "OK", "own": "Own", + "pageTitle": "Data - {{path}}", "path": "Path", "pathCopied": "Path copied.", "pathCopyError": "Unable to copy path.", diff --git a/public/static/locales/en/search.json b/public/static/locales/en/search.json index 50e0f89b6..c2645b8ea 100644 --- a/public/static/locales/en/search.json +++ b/public/static/locales/en/search.json @@ -21,6 +21,7 @@ "noResults": "No results to display.", "own": "Own", "owner": "Owner", + "pageTitle": "Search - {{searchTerm}}", "path": "Path", "pathPlaceholder": "/iplant/home/me", "permissions": "Permissions", diff --git a/public/static/locales/en/subscriptions.json b/public/static/locales/en/subscriptions.json index ecb6d8ea9..335540a8d 100644 --- a/public/static/locales/en/subscriptions.json +++ b/public/static/locales/en/subscriptions.json @@ -38,6 +38,7 @@ "noSubscriptions": "No subscriptions", "noUsages": "No usages", "paid": "Paid", + "pageTitle": "Subscriptions - {{searchTerm}}", "planName": "Plan Name", "quota": "Quota", "quotas": "Quotas", diff --git a/public/static/locales/en/teams.json b/public/static/locales/en/teams.json index 0abdc0aaa..428b78b63 100644 --- a/public/static/locales/en/teams.json +++ b/public/static/locales/en/teams.json @@ -27,6 +27,7 @@ "myTeams": "My Teams", "name": "Name", "noTeams": "No teams", + "pageTitle": "Team - {{name}}", "privilege": "Privilege", "publicTeam": "Public Team", "publicTeamHelp": "Making your team public allows your team to be discoverable to other CyVerse users who are not members of your team. Allowing users to discover your team will enable them to view the team and request to join. A team can be updated from public to private and vice versa any time.", diff --git a/src/pages/admin/subscriptions.js b/src/pages/admin/subscriptions.js index 578b6be56..22025157a 100644 --- a/src/pages/admin/subscriptions.js +++ b/src/pages/admin/subscriptions.js @@ -157,8 +157,16 @@ export default function Subscriptions() { } } -export async function getServerSideProps({ locale }) { - const title = i18n.t("subscriptions"); +export async function getServerSideProps(context) { + const { + locale, + query: { searchTerm }, + } = context; + + let title = i18n.t("subscriptions"); + if (searchTerm) { + title = i18n.t("subscriptions:pageTitle", { searchTerm }); + } return { props: { diff --git a/src/pages/apps.js b/src/pages/apps.js index 6709f1fab..6bfea2a75 100644 --- a/src/pages/apps.js +++ b/src/pages/apps.js @@ -79,8 +79,14 @@ export default function Apps() { } export async function getServerSideProps(context) { - const { locale } = context; - const title = i18n.t("apps"); + const { locale, query } = context; + + let selectedCategory; + if (query.selectedCategory) { + selectedCategory = JSON.parse(query.selectedCategory).name; + } + + const title = selectedCategory || i18n.t("apps"); return { props: { diff --git a/src/pages/collections/[collectionName].js b/src/pages/collections/[collectionName].js index e0c3523e6..5b7f995bd 100644 --- a/src/pages/collections/[collectionName].js +++ b/src/pages/collections/[collectionName].js @@ -31,8 +31,15 @@ export default function EditCollection() { ); } -export async function getServerSideProps({ locale }) { - const title = i18n.t("collections:featureName"); +export async function getServerSideProps(context) { + const { + locale, + params: { collectionName }, + } = context; + + const title = i18n.t("collections:pageTitle", { + name: collectionName, + }); return { props: { diff --git a/src/pages/data/ds/[...pathItems].js b/src/pages/data/ds/[...pathItems].js index 52e40c60e..3c220d55a 100644 --- a/src/pages/data/ds/[...pathItems].js +++ b/src/pages/data/ds/[...pathItems].js @@ -188,8 +188,17 @@ export default function DataStore() { ); } -export async function getServerSideProps({ locale }) { - const title = i18n.t("data"); +export async function getServerSideProps(context) { + const { + locale, + params: { pathItems }, + } = context; + + // Display the full path up to 3 items deep, otherwise only the last item. + const path = + pathItems.length <= 3 ? "/" + pathItems.join("/") : pathItems.at(-1); + + const title = i18n.t("data:pageTitle", { path }); return { props: { diff --git a/src/pages/search.js b/src/pages/search.js index b0c68f24f..5d086bd2a 100644 --- a/src/pages/search.js +++ b/src/pages/search.js @@ -57,8 +57,16 @@ export default function Search() { ); } -export async function getServerSideProps({ locale }) { - const title = i18n.t("search"); +export async function getServerSideProps(context) { + const { + locale, + query: { searchTerm }, + } = context; + + let title = i18n.t("search"); + if (searchTerm) { + title = i18n.t("search:pageTitle", { searchTerm }); + } return { props: { diff --git a/src/pages/teams/[teamName].js b/src/pages/teams/[teamName].js index debb72517..71a72350a 100644 --- a/src/pages/teams/[teamName].js +++ b/src/pages/teams/[teamName].js @@ -31,8 +31,13 @@ export default function EditTeam() { ); } -export async function getServerSideProps({ locale }) { - const title = i18n.t("teams"); +export async function getServerSideProps(context) { + const { + locale, + params: { teamName }, + } = context; + + const title = i18n.t("teams:pageTitle", { name: teamName }); return { props: {