X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2df6bac4eea43c9079641cd05262b29cbd285905..c6314ca47008f1ffd0fe70fe025a57475b64e773:/src/store/resources/resources-actions.ts diff --git a/src/store/resources/resources-actions.ts b/src/store/resources/resources-actions.ts index 36f99362cc..1de2feff8b 100644 --- a/src/store/resources/resources-actions.ts +++ b/src/store/resources/resources-actions.ts @@ -3,11 +3,31 @@ // SPDX-License-Identifier: AGPL-3.0 import { unionize, ofType, UnionOf } from '~/common/unionize'; -import { Resource } from '~/models/resource'; +import { extractUuidKind, Resource } from '~/models/resource'; +import { Dispatch } from 'redux'; +import { RootState } from '~/store/store'; +import { ServiceRepository } from '~/services/services'; +import { getResourceService } from '~/services/services'; export const resourcesActions = unionize({ SET_RESOURCES: ofType(), DELETE_RESOURCES: ofType() }); -export type ResourcesAction = UnionOf; \ No newline at end of file +export type ResourcesAction = UnionOf; + +export const updateResources = (resources: Resource[]) => resourcesActions.SET_RESOURCES(resources); + +export const loadResource = (uuid: string) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + try { + const kind = extractUuidKind(uuid); + const service = getResourceService(kind)(services); + if (service) { + const resource = await service.get(uuid); + dispatch(updateResources([resource])); + return resource; + } + } catch {} + return undefined; + };