15781: Adds support for multi-value property additions on collections.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 30 Jan 2020 21:05:45 +0000 (18:05 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 30 Jan 2020 21:05:45 +0000 (18:05 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/store/collection-panel/collection-panel-action.ts

index 122fc5e393b164974cb8f6698b9f3e13003ffae1..f4244389fdf22ab2a2b0f5f7546dda687636bd9c 100644 (file)
@@ -45,12 +45,22 @@ export const createCollectionTag = (data: TagProperty) =>
         const uuid = item ? item.uuid : '';
         try {
             if (item) {
+                const key = data.keyID || data.key;
+                const value = data.valueID || data.value;
+                if (item.properties[key]) {
+                    if (Array.isArray(item.properties[key])) {
+                        item.properties[key] = [...item.properties[key], value];
+                        // Remove potential duplicates
+                        item.properties[key] = Array.from(new Set(item.properties[key]));
+                    } else {
+                        item.properties[key] = [item.properties[key], value];
+                    }
+                } else {
+                    item.properties[key] = value;
+                }
                 const updatedCollection = await services.collectionService.update(
                     uuid, {
-                        properties: {
-                            ...JSON.parse(JSON.stringify(item.properties)),
-                            [data.keyID || data.key]: data.valueID || data.value
-                        }
+                        properties: {...JSON.parse(JSON.stringify(item.properties))}
                     }
                 );
                 item.properties = updatedCollection.properties;