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 removePropertyFromCreateCollectionForm,
16 COLLECTION_CREATE_FORM_SELECTOR,
18 } from 'store/collections/collection-create-actions';
19 import { ArvadosTheme } from 'common/custom-theme';
20 import { getPropertyChip } from '../resource-properties-form/property-chip';
22 type CssRules = 'tag';
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 marginRight: theme.spacing.unit,
27 marginBottom: theme.spacing.unit
31 interface CreateCollectionPropertiesListDataProps {
32 properties: CollectionProperties;
35 interface CreateCollectionPropertiesListActionProps {
36 handleDelete: (key: string, value: string) => void;
39 const mapStateToProps = (state: RootState): CreateCollectionPropertiesListDataProps => {
40 const properties = COLLECTION_CREATE_FORM_SELECTOR(state, 'properties');
41 return { properties };
44 const mapDispatchToProps = (dispatch: Dispatch): CreateCollectionPropertiesListActionProps => ({
45 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromCreateCollectionForm(key, value))
48 type CreateCollectionPropertiesListProps = CreateCollectionPropertiesListDataProps &
49 CreateCollectionPropertiesListActionProps & WithStyles<CssRules>;
51 const List = withStyles(styles)(
52 ({ classes, handleDelete, properties }: CreateCollectionPropertiesListProps) =>
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 CreateCollectionPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);