[ARVADOS-WORKBENCH2] created: 2.1.0-33-g6e79ab41

Git user git at public.arvados.org
Fri Oct 23 21:57:13 UTC 2020


        at  6e79ab41b81d172316afd5e0091175d7838d3f99 (commit)


commit 6e79ab41b81d172316afd5e0091175d7838d3f99
Author: Daniel Kutyła <daniel.kutyla at contractors.roche.com>
Date:   Sun Oct 18 23:51:10 2020 +0200

    16005: Added store saving and opening in new tab
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla at contractors.roche.com>

diff --git a/src/common/copy-store.ts b/src/common/copy-store.ts
new file mode 100644
index 00000000..9c7f3875
--- /dev/null
+++ b/src/common/copy-store.ts
@@ -0,0 +1,28 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+const STORE_COPY_KEY = 'storeCopy';
+
+export const copyStore = (store: any) => {
+    const { localStorage } = window;
+    const state = store.getState();
+    const storeCopy = JSON.parse(JSON.stringify(state));
+    storeCopy.router.location.pathname = '/';
+
+    if (localStorage) {
+        localStorage.setItem(STORE_COPY_KEY, JSON.stringify(storeCopy));
+    }
+};
+
+export const restoreStore = () => {
+    let storeCopy = null;
+    const { localStorage } = window;
+
+    if (localStorage && localStorage.getItem(STORE_COPY_KEY)) {
+        storeCopy = localStorage.getItem(STORE_COPY_KEY);
+        localStorage.removeItem(STORE_COPY_KEY);
+    }
+
+    return storeCopy;
+};
diff --git a/src/common/redirect-to.ts b/src/common/redirect-to.ts
index f5ece21b..11978569 100644
--- a/src/common/redirect-to.ts
+++ b/src/common/redirect-to.ts
@@ -5,14 +5,21 @@
 import { Config } from './config';
 
 const REDIRECT_TO_KEY = 'redirectTo';
+const REDIRECT_TO_APPLY_TO_PATH = 'redirectToApplyToPath';
+
+export const storeRedirects = (url?: string) => {
+    let redirectUrl = url;
+    const { location: { href }, localStorage } = window;
 
-export const storeRedirects = () => {
     if (window.location.href.indexOf(REDIRECT_TO_KEY) > -1) {
-        const { location: { href }, localStorage } = window;
-        const redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1];
+        redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1];
+    }
 
-        if (localStorage) {
-            localStorage.setItem(REDIRECT_TO_KEY, redirectUrl);
+    if (localStorage && redirectUrl) {
+        localStorage.setItem(REDIRECT_TO_KEY, redirectUrl);
+
+        if (url) {
+            localStorage.setItem(REDIRECT_TO_APPLY_TO_PATH, 'true');
         }
     }
 };
@@ -24,9 +31,18 @@ export const handleRedirects = (token: string, config: Config) => {
     if (localStorage && localStorage.getItem(REDIRECT_TO_KEY)) {
         const redirectUrl = localStorage.getItem(REDIRECT_TO_KEY);
         localStorage.removeItem(REDIRECT_TO_KEY);
+        const applyToPath = localStorage.getItem(REDIRECT_TO_APPLY_TO_PATH);
+
         if (redirectUrl) {
-            const sep = redirectUrl.indexOf("?") > -1 ? "&" : "?";
-            window.location.href = `${keepWebServiceUrl}${redirectUrl}${sep}api_token=${token}`;
+            if (applyToPath) {
+                localStorage.removeItem(REDIRECT_TO_APPLY_TO_PATH);
+                setTimeout(() => {
+                    window.location.pathname = redirectUrl;
+                }, 0);
+            } else {
+                const sep = redirectUrl.indexOf("?") > -1 ? "&" : "?";
+                window.location.href = `${keepWebServiceUrl}${redirectUrl}${sep}api_token=${token}`;
+            }
         }
     }
 };
diff --git a/src/store/open-in-new-tab/open-in-new-tab.actions.ts b/src/store/open-in-new-tab/open-in-new-tab.actions.ts
index 42bdc4cc..f4324c63 100644
--- a/src/store/open-in-new-tab/open-in-new-tab.actions.ts
+++ b/src/store/open-in-new-tab/open-in-new-tab.actions.ts
@@ -5,24 +5,27 @@
 import { Dispatch } from 'redux';
 import { ResourceKind } from '~/models/resource';
 import { unionize, ofType } from '~/common/unionize';
+import { storeRedirects } from '~/common/redirect-to';
 
 export const openInNewTabActions = unionize({
     COPY_STORE: ofType<{}>(),
-    OPEN_COLLECTION_IN_NEW_TAB: ofType<string>(),
-    OPEN_PROJECT_IN_NEW_TAB: ofType<string>()
 });
 
 export const openInNewTabAction = (resource: any) => (dispatch: Dispatch) => {
+    let url = null;
     const { uuid, kind } = resource;
-
+    
     dispatch(openInNewTabActions.COPY_STORE());
 
     if (kind === ResourceKind.COLLECTION) {
-        dispatch(openInNewTabActions.OPEN_COLLECTION_IN_NEW_TAB(uuid));
+        url = `/collections/${uuid}`;
     }
     if (kind === ResourceKind.PROJECT) {
-        dispatch(openInNewTabActions.OPEN_PROJECT_IN_NEW_TAB(uuid));
+        url = `/projects/${uuid}`;
     }
 
-    console.log(uuid);
+    if (url) {
+        storeRedirects(url);
+        window.open(window.location.origin, '_blank');
+    }
 };
\ No newline at end of file
diff --git a/src/store/store.ts b/src/store/store.ts
index 7beb099c..beb5295f 100644
--- a/src/store/store.ts
+++ b/src/store/store.ts
@@ -70,6 +70,8 @@ import { SubprocessMiddlewareService } from '~/store/subprocess-panel/subprocess
 import { SUBPROCESS_PANEL_ID } from '~/store/subprocess-panel/subprocess-panel-actions';
 import { ALL_PROCESSES_PANEL_ID } from './all-processes-panel/all-processes-panel-action';
 import { Config } from '~/common/config';
+import { openInNewTabActions } from './open-in-new-tab/open-in-new-tab.actions';
+import { copyStore, restoreStore } from '~/common/copy-store';
 
 const composeEnhancers =
     (process.env.NODE_ENV === 'development' &&
@@ -132,6 +134,16 @@ export function configureStore(history: History, services: ServiceRepository, co
     const subprocessMiddleware = dataExplorerMiddleware(
         new SubprocessMiddlewareService(services, SUBPROCESS_PANEL_ID)
     );
+    const saveStoreMiddleware = (store: RootStore) => (next: Function) => (action: any) => {
+        openInNewTabActions.match(action, {
+            default: () => {},
+            COPY_STORE: () => {
+                copyStore(store);
+            }
+        });
+
+        return next(action);
+    };
     const redirectToMiddleware = (store: any) => (next: any) => (action: any) => {
         const state = store.getState();
 
@@ -163,8 +175,10 @@ export function configureStore(history: History, services: ServiceRepository, co
         collectionsContentAddress,
         subprocessMiddleware,
     ];
-    const enhancer = composeEnhancers(applyMiddleware(redirectToMiddleware, ...middlewares));
-    return createStore(rootReducer, enhancer);
+
+    const enhancer = composeEnhancers(applyMiddleware(saveStoreMiddleware, redirectToMiddleware, ...middlewares));
+    const initialState: any = restoreStore();
+    return initialState ? createStore(rootReducer, initialState, enhancer) : createStore(rootReducer, enhancer);
 }
 
 const createRootReducer = (services: ServiceRepository) => combineReducers({
diff --git a/src/views-components/context-menu/action-sets/collection-action-set.ts b/src/views-components/context-menu/action-sets/collection-action-set.ts
index fba2a53a..3514d2c1 100644
--- a/src/views-components/context-menu/action-sets/collection-action-set.ts
+++ b/src/views-components/context-menu/action-sets/collection-action-set.ts
@@ -5,7 +5,7 @@
 import { ContextMenuActionSet } from "../context-menu-action-set";
 import { ToggleFavoriteAction } from "../actions/favorite-action";
 import { toggleFavorite } from "~/store/favorites/favorites-actions";
-import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, AdvancedIcon } from "~/components/icon/icon";
+import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, AdvancedIcon, OpenIcon } from "~/components/icon/icon";
 import { openCollectionUpdateDialog } from "~/store/collections/collection-update-actions";
 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
 import { openMoveCollectionDialog } from '~/store/collections/collection-move-actions';
@@ -15,6 +15,7 @@ import { toggleCollectionTrashed } from "~/store/trash/trash-actions";
 import { openSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
 import { openAdvancedTabDialog } from "~/store/advanced-tab/advanced-tab";
 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
+import { openInNewTabAction } from "~/store/open-in-new-tab/open-in-new-tab.actions";
 
 export const readOnlyCollectionActionSet: ContextMenuActionSet = [[
     {
@@ -25,6 +26,13 @@ export const readOnlyCollectionActionSet: ContextMenuActionSet = [[
             });
         }
     },
+    {
+        icon: OpenIcon,
+        name: "Open in new tab",
+        execute: (dispatch, resource) => {
+            dispatch<any>(openInNewTabAction(resource));
+        }
+    },
     {
         icon: CopyIcon,
         name: "Copy to project",
diff --git a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts
index 5e367906..5bd362f5 100644
--- a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts
+++ b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts
@@ -6,7 +6,7 @@ import { ContextMenuActionSet } from "../context-menu-action-set";
 import { ToggleFavoriteAction } from "../actions/favorite-action";
 import { ToggleTrashAction } from "~/views-components/context-menu/actions/trash-action";
 import { toggleFavorite } from "~/store/favorites/favorites-actions";
-import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, AdvancedIcon } from '~/components/icon/icon';
+import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, AdvancedIcon, OpenIcon } from '~/components/icon/icon';
 import { openCollectionUpdateDialog } from "~/store/collections/collection-update-actions";
 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
 import { openMoveCollectionDialog } from '~/store/collections/collection-move-actions';
@@ -15,6 +15,7 @@ import { toggleCollectionTrashed } from "~/store/trash/trash-actions";
 import { openSharingDialog } from "~/store/sharing-dialog/sharing-dialog-actions";
 import { openAdvancedTabDialog } from '~/store/advanced-tab/advanced-tab';
 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
+import { openInNewTabAction } from "~/store/open-in-new-tab/open-in-new-tab.actions";
 
 export const collectionResourceActionSet: ContextMenuActionSet = [[
     {
@@ -39,6 +40,13 @@ export const collectionResourceActionSet: ContextMenuActionSet = [[
             });
         }
     },
+    {
+        icon: OpenIcon,
+        name: "Open in new tab",
+        execute: (dispatch, resource) => {
+            dispatch<any>(openInNewTabAction(resource));
+        }
+    },
     {
         icon: MoveToIcon,
         name: "Move to",
diff --git a/src/views-components/context-menu/action-sets/project-action-set.ts b/src/views-components/context-menu/action-sets/project-action-set.ts
index 4f92aeb8..94ab286f 100644
--- a/src/views-components/context-menu/action-sets/project-action-set.ts
+++ b/src/views-components/context-menu/action-sets/project-action-set.ts
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { ContextMenuActionSet } from "../context-menu-action-set";
-import { NewProjectIcon, RenameIcon, MoveToIcon, DetailsIcon, AdvancedIcon } from '~/components/icon/icon';
+import { NewProjectIcon, RenameIcon, MoveToIcon, DetailsIcon, AdvancedIcon, OpenIcon } from '~/components/icon/icon';
 import { ToggleFavoriteAction } from "../actions/favorite-action";
 import { toggleFavorite } from "~/store/favorites/favorites-actions";
 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
@@ -16,6 +16,7 @@ import { ShareIcon } from '~/components/icon/icon';
 import { openSharingDialog } from "~/store/sharing-dialog/sharing-dialog-actions";
 import { openAdvancedTabDialog } from "~/store/advanced-tab/advanced-tab";
 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
+import { openInNewTabAction } from "~/store/open-in-new-tab/open-in-new-tab.actions";
 
 export const readOnlyProjectActionSet: ContextMenuActionSet = [[
     {
@@ -26,6 +27,13 @@ export const readOnlyProjectActionSet: ContextMenuActionSet = [[
             });
         }
     },
+    {
+        icon: OpenIcon,
+        name: "Open in new tab",
+        execute: (dispatch, resource) => {
+            dispatch<any>(openInNewTabAction(resource));
+        }
+    },
     {
         icon: DetailsIcon,
         name: "View details",

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list