Merge branch 'main' into 21224-project-details
[arvados.git] / services / workbench2 / src / store / details-panel / details-panel-action.ts
index bdfeaa18c1df60832eb5609b198cdf6533e9b5ad..ca2db7217f25e77075ff38377a406184f20ab906 100644 (file)
@@ -15,6 +15,7 @@ import { CollectionResource } from 'models/collection';
 import { extractUuidKind, ResourceKind } from 'models/resource';
 
 export const SLIDE_TIMEOUT = 500;
+export const CLOSE_DRAWER = 'CLOSE_DRAWER'
 
 export const detailsPanelActions = unionize({
     TOGGLE_DETAILS_PANEL: ofType<{}>(),
@@ -67,21 +68,20 @@ export const refreshCollectionVersionsList = (uuid: string) =>
     };
 
 export const toggleDetailsPanel = (uuid: string = '') => (dispatch: Dispatch, getState: () => RootState) => {
-    const { detailsPanel, router }= getState()
-    const currentRoute = router.location?.pathname.split('/') || [];
-    const currentItemUuid = currentRoute[currentRoute.length - 1];
-    // because of material-ui issue resizing details panel breaks tabs.
-    // triggering window resize event fixes that.
-    if(uuid !== detailsPanel.resourceUuid  && (detailsPanel.isOpened || uuid === currentItemUuid)){
+    const { detailsPanel }= getState()
+    const isTargetUuidNew = uuid !== detailsPanel.resourceUuid
+    if(isTargetUuidNew && uuid !== CLOSE_DRAWER && detailsPanel.isOpened){
         dispatch<any>(loadDetailsPanel(uuid));
     } else {
+        // because of material-ui issue resizing details panel breaks tabs.
+        // triggering window resize event fixes that.
         setTimeout(() => {
             window.dispatchEvent(new Event('resize'));
         }, SLIDE_TIMEOUT);
         startDetailsPanelTransition(dispatch)
         dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
         if (getState().detailsPanel.isOpened) {
-            dispatch<any>(loadDetailsPanel(getState().detailsPanel.resourceUuid));
+            dispatch<any>(loadDetailsPanel(isTargetUuidNew ? uuid : detailsPanel.resourceUuid));
         }
     }
     };