X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f5e55e7a71f2fc2390d392af752c61b4d3135cb6..fbec771115f1872bdadc0572a5c5059be68f1aca:/src/store/details-panel/details-panel-action.ts diff --git a/src/store/details-panel/details-panel-action.ts b/src/store/details-panel/details-panel-action.ts index ffa66b69..cb5a709e 100644 --- a/src/store/details-panel/details-panel-action.ts +++ b/src/store/details-panel/details-panel-action.ts @@ -3,40 +3,38 @@ // SPDX-License-Identifier: AGPL-3.0 import { unionize, ofType, UnionOf } from "unionize"; -import CommonResourceService, { Resource } from "../../common/api/common-resource-service"; -import { ResourceKind } from "../../models/kinds"; +import { CommonResourceService } from "../../common/api/common-resource-service"; import { Dispatch } from "redux"; -import { groupsService } from "../../services/services"; -import { serverApi } from "../../common/api/server-api"; +import { Resource, ResourceKind } from "../../models/resource"; +import { RootState } from "../store"; +import { ServiceRepository } from "../../services/services"; -const actions = unionize({ +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' }); -export default actions; - -export type DetailsPanelAction = UnionOf; +export type DetailsPanelAction = UnionOf; export const loadDetails = (uuid: string, kind: ResourceKind) => - (dispatch: Dispatch) => { - dispatch(actions.LOAD_DETAILS({ uuid, kind })); - getService(kind) + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(detailsPanelActions.LOAD_DETAILS({ uuid, kind })); + getService(services, kind) .get(uuid) .then(project => { - dispatch(actions.LOAD_DETAILS_SUCCESS({ item: project })); + dispatch(detailsPanelActions.LOAD_DETAILS_SUCCESS({ item: project })); }); }; -const getService = (kind: ResourceKind) => { +const getService = (services: ServiceRepository, kind: ResourceKind) => { switch (kind) { - case ResourceKind.Project: - return new CommonResourceService(serverApi, "groups"); - case ResourceKind.Collection: - return new CommonResourceService(serverApi, "collections"); + case ResourceKind.PROJECT: + return services.projectService; + case ResourceKind.COLLECTION: + return services.collectionService; default: - return new CommonResourceService(serverApi, ""); + return services.projectService; } };