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';
8 import { CustomStyleRulesCallback } from 'common/custom-theme';
9 import { WithStyles } from '@mui/styles';
10 import withStyles from '@mui/styles/withStyles';
11 import { RootState } from 'store/store';
12 import { ArvadosTheme } from 'common/custom-theme';
13 import { getPropertyChip } from '../resource-properties-form/property-chip';
14 import { removePropertyFromResourceForm } from 'store/resources/resources-actions';
15 import { formValueSelector } from 'redux-form';
17 type CssRules = 'tag';
19 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21 marginRight: theme.spacing(1),
22 marginBottom: theme.spacing(1)
26 interface ResourcePropertiesListDataProps {
27 properties: {[key: string]: string | string[]};
30 interface ResourcePropertiesListActionProps {
31 handleDelete: (key: string, value: string) => void;
34 type ResourcePropertiesListProps = ResourcePropertiesListDataProps &
35 ResourcePropertiesListActionProps & WithStyles<CssRules>;
37 const List = withStyles(styles)(
38 ({ classes, handleDelete, properties }: ResourcePropertiesListProps) =>
39 <div data-cy="resource-properties-list">
41 Object.keys(properties).map(k =>
42 Array.isArray(properties[k])
43 ? (properties[k] as string[]).map((v: string) =>
46 () => handleDelete(k, v),
49 k, (properties[k] as string),
50 () => handleDelete(k, (properties[k] as string)),
56 export const resourcePropertiesList = (formName: string) =>
58 (state: RootState): ResourcePropertiesListDataProps => ({
59 properties: formValueSelector(formName)(state, 'properties')
61 (dispatch: Dispatch): ResourcePropertiesListActionProps => ({
62 handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, formName))