1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export const deleteProperty = (properties: any, key: string, value: string) => {
6 if (Array.isArray(properties[key])) {
7 properties[key] = properties[key].filter((v: string) => v !== value);
8 if (properties[key].length === 1) {
9 properties[key] = properties[key][0];
10 } else if (properties[key].length === 0) {
11 delete properties[key];
13 } else if (properties[key] === value) {
14 delete properties[key];
19 export const addProperty = (properties: any, key: string, value: string) => {
20 if (properties[key]) {
21 if (Array.isArray(properties[key])) {
22 properties[key] = [...properties[key], value];
24 properties[key] = [properties[key], value];
26 // Remove potential duplicate and save as single value if needed
27 properties[key] = Array.from(new Set(properties[key]));
28 if (properties[key].length === 1) {
29 properties[key] = properties[key][0];
32 properties[key] = value;