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 COLLECTION_UPDATE_FORM_SELECTOR,
16 COLLECTION_UPDATE_FORM_NAME,
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';
21 import { removePropertyFromResourceForm } from 'store/resources/resources-actions';
23 type CssRules = 'tag';
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 marginRight: theme.spacing.unit,
28 marginBottom: theme.spacing.unit
32 interface UpdateCollectionPropertiesListDataProps {
33 properties: CollectionProperties;
36 interface UpdateCollectionPropertiesListActionProps {
37 handleDelete: (key: string, value: string) => void;
40 const mapStateToProps = (state: RootState): UpdateCollectionPropertiesListDataProps => {
41 const properties = COLLECTION_UPDATE_FORM_SELECTOR(state, 'properties');
42 return { properties };
45 const mapDispatchToProps = (dispatch: Dispatch): UpdateCollectionPropertiesListActionProps => ({
46 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, COLLECTION_UPDATE_FORM_NAME))
49 type UpdateCollectionPropertiesListProps = UpdateCollectionPropertiesListDataProps &
50 UpdateCollectionPropertiesListActionProps & WithStyles<CssRules>;
52 const List = withStyles(styles)(
53 ({ classes, handleDelete, properties }: UpdateCollectionPropertiesListProps) =>
56 Object.keys(properties).map(k =>
57 Array.isArray(properties[k])
58 ? (properties[k] as string[]).map((v: string) =>
61 () => handleDelete(k, v),
64 k, (properties[k] as string),
65 () => handleDelete(k, (properties[k] as string)),
71 export const UpdateCollectionPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);