+export const createCollectionTag = (data: TagProperty) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const item = getState().collectionPanel.item;
+ 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))}
+ }
+ );
+ item.properties = updatedCollection.properties;
+ dispatch(resourcesActions.SET_RESOURCES([updatedCollection]));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully added.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
+ return updatedCollection;
+ }
+ return;
+ } catch (e) {
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors[0], hideDuration: 2000, kind: SnackbarKind.ERROR }));
+ return;
+ }
+ };