1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { connect } from 'react-redux';
7 import { Dispatch } from 'redux';
12 } from '@material-ui/core';
13 import { RootState } from 'store/store';
15 removePropertyFromUpdateCollectionForm,
16 COLLECTION_UPDATE_FORM_SELECTOR,
17 } from 'store/collections/collection-update-actions';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import { getPropertyChip } from '../resource-properties-form/property-chip';
20 import { CollectionProperties } from 'store/collections/collection-create-actions';
22 type CssRules = 'tag';
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 marginRight: theme.spacing.unit,
27 marginBottom: theme.spacing.unit
31 interface UpdateCollectionPropertiesListDataProps {
32 properties: CollectionProperties;
35 interface UpdateCollectionPropertiesListActionProps {
36 handleDelete: (key: string, value: string) => void;
39 const mapStateToProps = (state: RootState): UpdateCollectionPropertiesListDataProps => {
40 const properties = COLLECTION_UPDATE_FORM_SELECTOR(state, 'properties');
41 return { properties };
44 const mapDispatchToProps = (dispatch: Dispatch): UpdateCollectionPropertiesListActionProps => ({
45 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromUpdateCollectionForm(key, value))
48 type UpdateCollectionPropertiesListProps = UpdateCollectionPropertiesListDataProps &
49 UpdateCollectionPropertiesListActionProps & WithStyles<CssRules>;
51 const List = withStyles(styles)(
52 ({ classes, handleDelete, properties }: UpdateCollectionPropertiesListProps) =>
55 Object.keys(properties).map(k =>
56 Array.isArray(properties[k])
57 ? (properties[k] as string[]).map((v: string) =>
60 () => handleDelete(k, v),
63 k, (properties[k] as string),
64 () => handleDelete(k, (properties[k] as string)),
70 export const UpdateCollectionPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);