From c352d4cd2cd565c29ccf0d3fec8f5fbf69a8fb36 Mon Sep 17 00:00:00 2001 From: Kalvin <82277+kalvinwang@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:47:48 -0400 Subject: [PATCH 1/2] Look for environment-specific UIO landing URLs first --- README.md | 1 + components/TransLine.tsx | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ea99029d..81535979 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ relates to weekly certification - CERTIFICATE_DIR: The path to the client certificate (certificate must be in PFX/P12 format) - PFX_FILE: The name of the client certificate file - (Optional) PFX_PASSPHRASE: The import passphrase for the client certificate if there is one +- (Optional) URL_UIO_LANDING, URL_UIOMOBILE_LANDING: The environment-specific links to the UIO landing page For local development: diff --git a/components/TransLine.tsx b/components/TransLine.tsx index fca41aab..36400c61 100644 --- a/components/TransLine.tsx +++ b/components/TransLine.tsx @@ -15,7 +15,11 @@ export interface TransLineProps extends TransLineContent { function resolveUrl(link: I18nString, userArrivedFromUioMobile: boolean) { // Special case for UIO homepage links. if (link === 'uio-home') { - const uioHomeLink = userArrivedFromUioMobile ? getUrl('uio-home-url-mobile') : getUrl('uio-home-url-desktop') + // Optional environment-specific links back to the UIO landing page, used by EDD testing + const uioLandingUrl = process.env.URL_UIO_LANDING ?? getUrl('uio-home-url-desktop') + const uioMobileLandingUrl = process.env.URL_UIOMOBILE_LANDING ?? getUrl('uio-home-url-mobile') + + const uioHomeLink = userArrivedFromUioMobile ? uioMobileLandingUrl : uioLandingUrl if (uioHomeLink) { // If the link is for UIO homepage, do a direct getUrl() lookup. // Do not pass the looked up url through t() because t() will mangle the url. From dcd54209015a78610c9d77ed3ae50ee7a7cc2efe Mon Sep 17 00:00:00 2001 From: Kalvin <82277+kalvinwang@users.noreply.github.com> Date: Thu, 19 Aug 2021 17:06:34 -0400 Subject: [PATCH 2/2] refactor --- README.md | 2 +- components/TransLine.tsx | 6 +----- utils/getUrl.ts | 4 ++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 81535979..c6ff6a90 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ relates to weekly certification - CERTIFICATE_DIR: The path to the client certificate (certificate must be in PFX/P12 format) - PFX_FILE: The name of the client certificate file - (Optional) PFX_PASSPHRASE: The import passphrase for the client certificate if there is one -- (Optional) URL_UIO_LANDING, URL_UIOMOBILE_LANDING: The environment-specific links to the UIO landing page +- (Optional) URL_UIO_LANDING, URL_UIOMOBILE_LANDING: The environment-specific links to the UIO and UIO Mobile landing pages For local development: diff --git a/components/TransLine.tsx b/components/TransLine.tsx index 36400c61..fca41aab 100644 --- a/components/TransLine.tsx +++ b/components/TransLine.tsx @@ -15,11 +15,7 @@ export interface TransLineProps extends TransLineContent { function resolveUrl(link: I18nString, userArrivedFromUioMobile: boolean) { // Special case for UIO homepage links. if (link === 'uio-home') { - // Optional environment-specific links back to the UIO landing page, used by EDD testing - const uioLandingUrl = process.env.URL_UIO_LANDING ?? getUrl('uio-home-url-desktop') - const uioMobileLandingUrl = process.env.URL_UIOMOBILE_LANDING ?? getUrl('uio-home-url-mobile') - - const uioHomeLink = userArrivedFromUioMobile ? uioMobileLandingUrl : uioLandingUrl + const uioHomeLink = userArrivedFromUioMobile ? getUrl('uio-home-url-mobile') : getUrl('uio-home-url-desktop') if (uioHomeLink) { // If the link is for UIO homepage, do a direct getUrl() lookup. // Do not pass the looked up url through t() because t() will mangle the url. diff --git a/utils/getUrl.ts b/utils/getUrl.ts index 69721f10..e6be0497 100644 --- a/utils/getUrl.ts +++ b/utils/getUrl.ts @@ -11,6 +11,10 @@ export type UrlType = keyof typeof urls * Get url from urls.json */ export default function getUrl(linkKey: string): string | undefined { + // Optional environment-specific links back to the UIO landing page, used by EDD testing + if (linkKey === 'uio-home-url-desktop' && process.env.URL_UIO_LANDING) return process.env.URL_UIO_LANDING + if (linkKey === 'uio-home-url-mobile' && process.env.URL_UIOMOBILE_LANDING) return process.env.URL_UIOMOBILE_LANDING + // Explicitly cast to one of the allowed keys in urls.json. // If the key does not exist in urls.json, this function will return undefined. const key = linkKey as UrlType