From: Stephen Smith Date: Thu, 25 Aug 2022 14:29:42 +0000 (-0400) Subject: 19421: Redirect old "redirectTo" url param to "redirectToPreview" X-Git-Tag: 2.5.0~40^2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/98d3f7708860701b02055643da4ba9412720bf4b 19421: Redirect old "redirectTo" url param to "redirectToPreview" Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- diff --git a/src/common/redirect-to.ts b/src/common/redirect-to.ts index d8fecde4..73c94843 100644 --- a/src/common/redirect-to.ts +++ b/src/common/redirect-to.ts @@ -7,6 +7,7 @@ import { Config } from './config'; export const REDIRECT_TO_DOWNLOAD_KEY = 'redirectToDownload'; export const REDIRECT_TO_PREVIEW_KEY = 'redirectToPreview'; +export const REDIRECT_TO_KEY = 'redirectTo'; const getRedirectKeyFromUrl = (href: string): string | null => { switch (true) { @@ -14,6 +15,8 @@ const getRedirectKeyFromUrl = (href: string): string | null => { return REDIRECT_TO_DOWNLOAD_KEY; case href.indexOf(REDIRECT_TO_PREVIEW_KEY) > -1: return REDIRECT_TO_PREVIEW_KEY; + case href.indexOf(`${REDIRECT_TO_KEY}=`) > -1: + return REDIRECT_TO_KEY; default: return null; } @@ -32,8 +35,11 @@ export const storeRedirects = () => { const { location: { href }, localStorage } = window; const redirectKey = getRedirectKeyFromUrl(href); - if (localStorage && redirectKey) { - localStorage.setItem(redirectKey, href.split(`${redirectKey}=`)[1]); + // Change old redirectTo -> redirectToPreview when storing redirect + const redirectStoreKey = redirectKey === REDIRECT_TO_KEY ? REDIRECT_TO_PREVIEW_KEY : redirectKey; + + if (localStorage && redirectKey && redirectStoreKey) { + localStorage.setItem(redirectStoreKey, href.split(`${redirectKey}=`)[1]); } };