1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { unionize, ofType, UnionOf } from '~/common/unionize';
6 import { extractUuidKind, Resource } from '~/models/resource';
7 import { Dispatch } from 'redux';
8 import { RootState } from '~/store/store';
9 import { ServiceRepository } from '~/services/services';
10 import { getResourceService } from '~/services/services';
12 export const resourcesActions = unionize({
13 SET_RESOURCES: ofType<Resource[]>(),
14 DELETE_RESOURCES: ofType<string[]>()
17 export type ResourcesAction = UnionOf<typeof resourcesActions>;
19 export const updateResources = (resources: Resource[]) => resourcesActions.SET_RESOURCES(resources);
21 export const loadResource = (uuid: string) =>
22 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24 const kind = extractUuidKind(uuid);
25 const service = getResourceService(kind)(services);
27 const resource = await service.get(uuid);
28 dispatch<any>(updateResources([resource]));