projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Create composable helper for setting constant pickerId
[arvados-workbench2.git]
/
src
/
store
/
resources
/
resources.ts
diff --git
a/src/store/resources/resources.ts
b/src/store/resources/resources.ts
index 7f21332969113f7c66c0809e8f50c03a0dfd5df8..e7153decd70af11a91131c8f8009a26a74df73eb 100644
(file)
--- a/
src/store/resources/resources.ts
+++ b/
src/store/resources/resources.ts
@@
-3,13
+3,13
@@
// SPDX-License-Identifier: AGPL-3.0
import { Resource } from "~/models/resource";
// SPDX-License-Identifier: AGPL-3.0
import { Resource } from "~/models/resource";
-import { ResourceKind } from '
../..
/models/resource';
+import { ResourceKind } from '
~
/models/resource';
export type ResourcesState = { [key: string]: Resource };
export type ResourcesState = { [key: string]: Resource };
-export const getResource = <T extends Resource>(id: string) =>
- (state: ResourcesState):
Resource
| undefined =>
- state[id];
+export const getResource = <T extends Resource
= Resource
>(id: string) =>
+ (state: ResourcesState):
T
| undefined =>
+ state[id]
as T
;
export const setResource = <T extends Resource>(id: string, data: T) =>
(state: ResourcesState) => ({
export const setResource = <T extends Resource>(id: string, data: T) =>
(state: ResourcesState) => ({
@@
-19,7
+19,7
@@
export const setResource = <T extends Resource>(id: string, data: T) =>
export const deleteResource = (id: string) =>
(state: ResourcesState) => {
export const deleteResource = (id: string) =>
(state: ResourcesState) => {
- const newState = {
...state
};
+ const newState = {
...state
};
delete newState[id];
return newState;
};
delete newState[id];
return newState;
};
@@
-28,10
+28,14
@@
export const filterResources = (filter: (resource: Resource) => boolean) =>
(state: ResourcesState) =>
Object
.keys(state)
(state: ResourcesState) =>
Object
.keys(state)
- .map(id => getResource(id)(state))
+ .reduce((resources, id) => {
+ const resource = getResource(id)(state);
+ return resource
+ ? [...resources, resource]
+ : resources;
+ }, [])
.filter(filter);
export const filterResourcesByKind = (kind: ResourceKind) =>
(state: ResourcesState) =>
filterResources(resource => resource.kind === kind)(state);
.filter(filter);
export const filterResourcesByKind = (kind: ResourceKind) =>
(state: ResourcesState) =>
filterResources(resource => resource.kind === kind)(state);
-