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 removePropertyFromUpdateProjectForm,
16 PROJECT_UPDATE_FORM_SELECTOR,
17 } from 'store/projects/project-update-actions';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import { getPropertyChip } from '../resource-properties-form/property-chip';
20 import { ProjectProperties } from 'store/projects/project-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 UpdateProjectPropertiesListDataProps {
32 properties: ProjectProperties;
35 interface UpdateProjectPropertiesListActionProps {
36 handleDelete: (key: string, value: string) => void;
39 const mapStateToProps = (state: RootState): UpdateProjectPropertiesListDataProps => {
40 const properties = PROJECT_UPDATE_FORM_SELECTOR(state, 'properties');
41 return { properties };
44 const mapDispatchToProps = (dispatch: Dispatch): UpdateProjectPropertiesListActionProps => ({
45 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromUpdateProjectForm(key, value))
48 type UpdateProjectPropertiesListProps = UpdateProjectPropertiesListDataProps &
49 UpdateProjectPropertiesListActionProps & WithStyles<CssRules>;
51 const List = withStyles(styles)(
52 ({ classes, handleDelete, properties }: UpdateProjectPropertiesListProps) =>
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 UpdateProjectPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);