Merge branch '14470-replace-tree-pickers'
[arvados.git] / src / store / details-panel / details-panel-action.ts
index cb5a709e3ffe861c36656b84f726b25cc367cf0e..0f13286535630a46b479d5a31e2423908513d249 100644 (file)
@@ -2,41 +2,25 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { unionize, ofType, UnionOf } from "unionize";
-import { CommonResourceService } from "../../common/api/common-resource-service";
-import { Dispatch } from "redux";
-import { Resource, ResourceKind } from "../../models/resource";
-import { RootState } from "../store";
-import { ServiceRepository } from "../../services/services";
+import { unionize, ofType, UnionOf } from '~/common/unionize';
+import { Dispatch } from 'redux';
+
+export const SLIDE_TIMEOUT = 500;
 
 export const detailsPanelActions = unionize({
     TOGGLE_DETAILS_PANEL: ofType<{}>(),
-    LOAD_DETAILS: ofType<{ uuid: string, kind: ResourceKind }>(),
-    LOAD_DETAILS_SUCCESS: ofType<{ item: Resource }>(),
-}, { tag: 'type', value: 'payload' });
+    LOAD_DETAILS_PANEL: ofType<string>()
+});
 
 export type DetailsPanelAction = UnionOf<typeof detailsPanelActions>;
 
-export const loadDetails = (uuid: string, kind: ResourceKind) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(detailsPanelActions.LOAD_DETAILS({ uuid, kind }));
-        getService(services, kind)
-            .get(uuid)
-            .then(project => {
-                dispatch(detailsPanelActions.LOAD_DETAILS_SUCCESS({ item: project }));
-            });
-    };
+export const loadDetailsPanel = (uuid: string) => detailsPanelActions.LOAD_DETAILS_PANEL(uuid);
 
-const getService = (services: ServiceRepository, kind: ResourceKind) => {
-    switch (kind) {
-        case ResourceKind.PROJECT:
-            return services.projectService;
-        case ResourceKind.COLLECTION:
-            return services.collectionService;
-        default:
-            return services.projectService;
-    }
+export const toggleDetailsPanel = () => (dispatch: Dispatch) => {
+    // because of material-ui issue resizing details panel breaks tabs.
+    // triggering window resize event fixes that.
+    setTimeout(() => {
+        window.dispatchEvent(new Event('resize'));
+    }, SLIDE_TIMEOUT);
+    dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
 };
-
-
-