1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Resource } from "~/models/resource";
6 import { ResourceKind } from '../../models/resource';
8 export type ResourcesState = { [key: string]: Resource };
10 export const getResource = <T extends Resource = Resource>(id: string) =>
11 (state: ResourcesState): T | undefined =>
14 export const setResource = <T extends Resource>(id: string, data: T) =>
15 (state: ResourcesState) => ({
20 export const deleteResource = (id: string) =>
21 (state: ResourcesState) => {
22 const newState = { ...state };
27 export const filterResources = (filter: (resource: Resource) => boolean) =>
28 (state: ResourcesState) =>
31 .reduce((resources, id) => {
32 const resource = getResource(id)(state);
34 ? [...resources, resource]
39 export const filterResourcesByKind = (kind: ResourceKind) =>
40 (state: ResourcesState) =>
41 filterResources(resource => resource.kind === kind)(state);