19421: Redirect old "redirectTo" url param to "redirectToPreview"
[arvados-workbench2.git] / src / common / redirect-to.ts
index d8fecde4e9262fd24c4a3cfc73d9706427dc9153..73c9484323a76169dc43f60bd210f16dfcf2e679 100644 (file)
@@ -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]);
     }
 };