Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / resources / resources-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { sanitizeHTML } from 'common/html-sanitize';
6 import { ResourcesState, setResource, deleteResource } from './resources';
7 import { ResourcesAction, resourcesActions } from './resources-actions';
8
9 export const resourcesReducer = (state: ResourcesState = {}, action: ResourcesAction) => {
10     if (Array.isArray(action.payload)) {
11         for (const item of action.payload) {
12             if (typeof item === 'object' && item.description) {
13                 item.description = sanitizeHTML(item.description);
14             }
15         }
16     }
17
18     return resourcesActions.match(action, {
19         SET_RESOURCES: resources => resources.reduce((state, resource) => setResource(resource.uuid, resource)(state), state),
20         DELETE_RESOURCES: ids => ids.reduce((state, id) => deleteResource(id)(state), state),
21         default: () => state,
22     });
23 };