1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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 { ProjectResource } from '~/models/project';
11 import { PROJECT_PROPERTIES_DIALOG_NAME, deleteProjectProperty } from '~/store/details-panel/details-panel-action';
12 import { Dialog, DialogTitle, DialogContent, DialogActions, Button, withStyles, StyleRulesCallback, WithStyles } from '@material-ui/core';
13 import { ArvadosTheme } from '~/common/custom-theme';
14 import { ProjectPropertiesForm } from '~/views-components/project-properties-dialog/project-properties-form';
15 import { getResource } from '~/store/resources/resources';
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 ProjectPropertiesDialogDataProps {
28 project: ProjectResource;
31 interface ProjectPropertiesDialogActionProps {
32 handleDelete: (key: string, value: string) => void;
35 const mapStateToProps = ({ detailsPanel, resources, properties }: RootState): ProjectPropertiesDialogDataProps => ({
36 project: getResource(detailsPanel.resourceUuid)(resources) as ProjectResource,
39 const mapDispatchToProps = (dispatch: Dispatch): ProjectPropertiesDialogActionProps => ({
40 handleDelete: (key: string, value: string) => () => dispatch<any>(deleteProjectProperty(key, value)),
43 type ProjectPropertiesDialogProps = ProjectPropertiesDialogDataProps & ProjectPropertiesDialogActionProps & WithDialogProps<{}> & WithStyles<CssRules>;
45 export const ProjectPropertiesDialog = connect(mapStateToProps, mapDispatchToProps)(
47 withDialog(PROJECT_PROPERTIES_DIALOG_NAME)(
48 ({ classes, open, closeDialog, handleDelete, project }: ProjectPropertiesDialogProps) =>
53 <DialogTitle>Properties</DialogTitle>
55 <ProjectPropertiesForm />
56 {project && project.properties &&
57 Object.keys(project.properties).map(k =>
58 Array.isArray(project.properties[k])
59 ? project.properties[k].map((v: string) =>
65 k, project.properties[k],
66 handleDelete(k, project.properties[k]),
75 onClick={closeDialog}>