}
};
-export const deleteCollectionTag = (key: string) =>
+export const deleteCollectionTag = (key: string, value: string) =>
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
const item = getState().collectionPanel.item;
const uuid = item ? item.uuid : '';
try {
if (item) {
- delete item.properties[key];
+ if (Array.isArray(item.properties[key])) {
+ item.properties[key] = item.properties[key].filter((v: string) => v !== value);
+ if (item.properties[key].length === 1) {
+ item.properties[key] = item.properties[key][0];
+ } else if (item.properties[key].length === 0) {
+ delete item.properties[key];
+ }
+ } else if (item.properties[key] === value) {
+ delete item.properties[key];
+ }
+
const updatedCollection = await services.collectionService.update(
uuid, {
properties: {...item.properties}
</Grid>
<Grid item xs={12}>
{Object.keys(item.properties).map(k =>
- <PropertyChipComponent
- key={k} className={classes.tag}
- onDelete={this.handleDelete(k)}
- propKey={k} propValue={item.properties[k]} />
+ Array.isArray(item.properties[k])
+ ? item.properties[k].map((v: string) =>
+ getPropertyChip(k, v, this.handleDelete, classes.tag))
+ : getPropertyChip(k, item.properties[k], this.handleDelete, classes.tag)
)}
</Grid>
</Grid>
kind: SnackbarKind.SUCCESS
}))
- handleDelete = (key: string) => () => {
- this.props.dispatch<any>(deleteCollectionTag(key));
+ handleDelete = (key: string, value: string) => () => {
+ this.props.dispatch<any>(deleteCollectionTag(key, value));
}
openCollectionDetails = () => {
}
)
);
+
+const getPropertyChip = (k:string, v:string, handleDelete:any, className:string) =>
+ <PropertyChipComponent
+ key={k} className={className}
+ onDelete={handleDelete(k, v)}
+ propKey={k} propValue={v} />;
+