1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Dispatch } from "redux";
7 import { connect } from "react-redux";
8 import { RootState } from 'store/store';
9 import { withDialog, WithDialogProps } from "store/dialog/with-dialog";
10 import { RESOURCE_PROPERTIES_DIALOG_NAME } from 'store/details-panel/details-panel-action';
20 } from '@material-ui/core';
21 import { ArvadosTheme } from 'common/custom-theme';
22 import { ResourcePropertiesDialogForm } from 'views-components/resource-properties-dialog/resource-properties-dialog-form';
23 import { getResource } from 'store/resources/resources';
24 import { getPropertyChip } from "../resource-properties-form/property-chip";
25 import { deleteResourceProperty } from "store/resources/resources-actions";
26 import { ResourceWithProperties } from "models/resource";
28 type CssRules = 'tag';
30 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 marginRight: theme.spacing.unit,
33 marginBottom: theme.spacing.unit
37 interface ResourcePropertiesDialogDataProps {
38 resource: ResourceWithProperties;
41 interface ResourcePropertiesDialogActionProps {
42 handleDelete: (uuid: string, key: string, value: string) => void;
45 const mapStateToProps = ({ detailsPanel, resources, properties }: RootState): ResourcePropertiesDialogDataProps => ({
46 resource: getResource(detailsPanel.resourceUuid)(resources) as ResourceWithProperties,
49 const mapDispatchToProps = (dispatch: Dispatch): ResourcePropertiesDialogActionProps => ({
50 handleDelete: (uuid: string, key: string, value: string) => () => dispatch<any>(deleteResourceProperty(uuid, key, value)),
53 type ResourcePropertiesDialogProps = ResourcePropertiesDialogDataProps & ResourcePropertiesDialogActionProps & WithDialogProps<{}> & WithStyles<CssRules>;
55 export const ResourcePropertiesDialog = connect(mapStateToProps, mapDispatchToProps)(
57 withDialog(RESOURCE_PROPERTIES_DIALOG_NAME)(
58 ({ classes, open, closeDialog, handleDelete, resource }: ResourcePropertiesDialogProps) =>
63 <div data-cy='resource-properties-dialog'>
64 <DialogTitle>Edit properties</DialogTitle>
66 <ResourcePropertiesDialogForm uuid={resource ? resource.uuid : ''} />
67 {resource && resource.properties &&
68 Object.keys(resource.properties).map(k =>
69 Array.isArray(resource.properties[k])
70 ? resource.properties[k].map((v: string) =>
73 handleDelete(resource.uuid, k, v),
76 k, resource.properties[k],
77 handleDelete(resource.uuid, k, resource.properties[k]),
84 data-cy='close-dialog-btn'
87 onClick={closeDialog}>