1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
7 import { Resource, ResourceKind } from "~/models/resource";
8 import { RootState } from "../store";
9 import { ServiceRepository } from "~/services/services";
11 export const detailsPanelActions = unionize({
12 TOGGLE_DETAILS_PANEL: ofType<{}>(),
13 LOAD_DETAILS: ofType<{ uuid: string, kind: ResourceKind }>(),
14 LOAD_DETAILS_SUCCESS: ofType<{ item: Resource }>(),
15 UPDATE_DETAILS: ofType<{ item: Resource }>()
16 }, { tag: 'type', value: 'payload' });
18 export type DetailsPanelAction = UnionOf<typeof detailsPanelActions>;
20 export const loadDetails = (uuid: string, kind: ResourceKind) =>
21 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
22 dispatch(detailsPanelActions.LOAD_DETAILS({ uuid, kind }));
23 const item = await getService(services, kind).get(uuid);
24 dispatch(detailsPanelActions.LOAD_DETAILS_SUCCESS({ item }));
27 export const updateDetails = (item: Resource) =>
28 async (dispatch: Dispatch, getState: () => RootState) => {
29 const currentItem = getState().detailsPanel.item;
30 if (currentItem && (currentItem.uuid === item.uuid)) {
31 dispatch(detailsPanelActions.UPDATE_DETAILS({ item }));
32 dispatch(detailsPanelActions.LOAD_DETAILS_SUCCESS({ item }));
37 const getService = (services: ServiceRepository, kind: ResourceKind) => {
39 case ResourceKind.PROJECT:
40 return services.projectService;
41 case ResourceKind.COLLECTION:
42 return services.collectionService;
44 return services.projectService;