Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / resources / resources-reducer.ts
index bb0cd383d8f6f7f7741506b9a2a0cbf8735f6980..02b8f38f4c8eec3dc1698d6c689cc9b9931dfc12 100644 (file)
@@ -2,16 +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, {
-        SET_RESOURCES: resources => resources.reduce(
-            (state, resource) => setResource(resource.uuid, resource)(state),
-            state),
-        DELETE_RESOURCES: ids => ids.reduce(
-            (state, id) => deleteResource(id)(state),
-            state),
+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