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, Chip, 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';
17 type CssRules = 'tag';
19 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21 marginRight: theme.spacing.unit,
22 marginBottom: theme.spacing.unit
26 interface ProjectPropertiesDialogDataProps {
27 project: ProjectResource;
30 interface ProjectPropertiesDialogActionProps {
31 handleDelete: (key: string) => void;
34 const mapStateToProps = ({ detailsPanel, resources }: RootState): ProjectPropertiesDialogDataProps => {
35 const project = getResource(detailsPanel.resourceUuid)(resources) as ProjectResource;
39 const mapDispatchToProps = (dispatch: Dispatch): ProjectPropertiesDialogActionProps => ({
40 handleDelete: (key: string) => dispatch<any>(deleteProjectProperty(key))
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 return <Chip key={k} className={classes.tag}
59 onDelete={() => handleDelete(k)}
60 label={`${k}: ${project.properties[k]}`} />;
68 onClick={closeDialog}>