Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / resources / resources-reducer.ts
index 22108e04a78ff8f9822800a8e1c52f49a40c1acb..02b8f38f4c8eec3dc1698d6c689cc9b9931dfc12 100644 (file)
@@ -2,12 +2,22 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { sanitizeHTML } from 'common/html-sanitize';
 import { ResourcesState, setResource, deleteResource } from './resources';
 import { ResourcesAction, resourcesActions } from './resources-actions';
 
-export const resourcesReducer = (state: ResourcesState = {}, action: ResourcesAction) =>
-    resourcesActions.match(action, {
+export const resourcesReducer = (state: ResourcesState = {}, action: ResourcesAction) => {
+    if (Array.isArray(action.payload)) {
+        for (const item of action.payload) {
+            if (typeof item === 'object' && item.description) {
+                item.description = sanitizeHTML(item.description);
+            }
+        }
+    }
+
+    return resourcesActions.match(action, {
         SET_RESOURCES: resources => resources.reduce((state, resource) => setResource(resource.uuid, resource)(state), state),
         DELETE_RESOURCES: ids => ids.reduce((state, id) => deleteResource(id)(state), state),
         default: () => state,
-    });
\ No newline at end of file
+    });
+};
\ No newline at end of file