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';
14 import { ArvadosTheme } from 'common/custom-theme';
15 import { getPropertyChip } from '../resource-properties-form/property-chip';
16 import { removePropertyFromResourceForm } from 'store/resources/resources-actions';
17 import { formValueSelector } from 'redux-form';
19 type CssRules = 'tag';
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23 marginRight: theme.spacing.unit,
24 marginBottom: theme.spacing.unit
28 interface ResourcePropertiesListDataProps {
29 properties: {[key: string]: string | string[]};
32 interface ResourcePropertiesListActionProps {
33 handleDelete: (key: string, value: string) => void;
36 type ResourcePropertiesListProps = ResourcePropertiesListDataProps &
37 ResourcePropertiesListActionProps & WithStyles<CssRules>;
39 const List = withStyles(styles)(
40 ({ classes, handleDelete, properties }: ResourcePropertiesListProps) =>
43 Object.keys(properties).map(k =>
44 Array.isArray(properties[k])
45 ? (properties[k] as string[]).map((v: string) =>
48 () => handleDelete(k, v),
51 k, (properties[k] as string),
52 () => handleDelete(k, (properties[k] as string)),
58 export const resourcePropertiesList = (formName: string) =>
60 (state: RootState): ResourcePropertiesListDataProps => ({
61 properties: formValueSelector(formName)(state, 'properties')
63 (dispatch: Dispatch): ResourcePropertiesListActionProps => ({
64 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, formName))