1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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';
14 import { removePropertyFromCreateProjectForm, PROJECT_CREATE_FORM_SELECTOR, ProjectProperties } from '~/store/projects/project-create-actions';
15 import { ArvadosTheme } from '~/common/custom-theme';
16 import { getPropertyChip } from '../resource-properties-form/property-chip';
18 type CssRules = 'tag';
20 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22 marginRight: theme.spacing.unit,
23 marginBottom: theme.spacing.unit
27 interface CreateProjectPropertiesListDataProps {
28 properties: ProjectProperties;
31 interface CreateProjectPropertiesListActionProps {
32 handleDelete: (key: string, value: string) => void;
35 const mapStateToProps = (state: RootState): CreateProjectPropertiesListDataProps => {
36 const properties = PROJECT_CREATE_FORM_SELECTOR(state, 'properties');
37 return { properties };
40 const mapDispatchToProps = (dispatch: Dispatch): CreateProjectPropertiesListActionProps => ({
41 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromCreateProjectForm(key, value))
44 type CreateProjectPropertiesListProps = CreateProjectPropertiesListDataProps &
45 CreateProjectPropertiesListActionProps & WithStyles<CssRules>;
47 const List = withStyles(styles)(
48 ({ classes, handleDelete, properties }: CreateProjectPropertiesListProps) =>
51 Object.keys(properties).map(k =>
52 Array.isArray(properties[k])
53 ? (properties[k] as string[]).map((v: string) =>
56 () => handleDelete(k, v),
59 k, (properties[k] as string),
60 () => handleDelete(k, (properties[k] as string)),
66 export const CreateProjectPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);