Merge branch '21898-info-button-behavior'
[arvados.git] / services / workbench2 / src / views-components / details-panel / root-project-details.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { connect } from 'react-redux';
7 import { ProjectsIcon } from 'components/icon/icon';
8 import { formatDate } from 'common/formatters';
9 import { DetailsData } from "./details-data";
10 import { DetailsAttribute } from "components/details-attribute/details-attribute";
11 import { withStyles, StyleRulesCallback, WithStyles } from '@material-ui/core';
12 import { ArvadosTheme } from 'common/custom-theme';
13 import { Dispatch } from 'redux';
14 import { openProjectUpdateDialog, ProjectUpdateFormDialogData } from 'store/projects/project-update-actions';
15 import { RootState } from 'store/store';
16 import { ResourcesState } from 'store/resources/resources';
17 import { UserResource } from 'models/user';
18 import { UserResourceFullName } from 'views-components/data-explorer/renderers';
19
20 export class RootProjectDetails extends DetailsData<UserResource> {
21     getIcon(className?: string) {
22         return <ProjectsIcon className={className} />;
23     }
24
25     getDetails() {
26         return <RootProjectDetailsComponent rootProject={this.item} />;
27     }
28 }
29
30 type CssRules = 'tag' | 'editIcon' | 'editButton';
31
32 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33     tag: {
34         marginRight: theme.spacing.unit / 2,
35         marginBottom: theme.spacing.unit / 2,
36     },
37     editIcon: {
38         paddingRight: theme.spacing.unit / 2,
39         fontSize: '1.125rem',
40     },
41     editButton: {
42         boxShadow: 'none',
43         padding: '2px 10px 2px 5px',
44         fontSize: '0.75rem'
45     },
46 });
47
48 interface RootProjectDetailsComponentDataProps {
49     rootProject: any;
50 }
51
52 const mapStateToProps = (state: RootState): { resources: ResourcesState } => {
53     return {
54         resources: state.resources
55     };
56 };
57
58 const mapDispatchToProps = (dispatch: Dispatch) => ({
59     onClick: (prj: ProjectUpdateFormDialogData) =>
60         () => dispatch<any>(openProjectUpdateDialog(prj)),
61 });
62
63 type RootProjectDetailsComponentProps = RootProjectDetailsComponentDataProps & WithStyles<CssRules>;
64
65 const RootProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
66     withStyles(styles)(
67         ({ rootProject}: RootProjectDetailsComponentProps & { resources: ResourcesState }) => <div>
68             <DetailsAttribute label='Type' value="Root Project" />
69             <DetailsAttribute label='User' />
70             <UserResourceFullName uuid={rootProject.uuid} link={true} />
71             <DetailsAttribute label='Created at' value={formatDate(rootProject.createdAt)} />
72             <DetailsAttribute label='UUID' linkToUuid={rootProject.uuid} value={rootProject.uuid} />
73         </div>
74     ));