1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect } from 'react-redux';
7 import { RootState } from '~/store/store';
8 import { openProjectPropertiesDialog } from '~/store/details-panel/details-panel-action';
9 import { ProjectIcon, RenameIcon } from '~/components/icon/icon';
10 import { ProjectResource } from '~/models/project';
11 import { formatDate } from '~/common/formatters';
12 import { ResourceKind } from '~/models/resource';
13 import { resourceLabel } from '~/common/labels';
14 import { DetailsData } from "./details-data";
15 import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
16 import { RichTextEditorLink } from '~/components/rich-text-editor-link/rich-text-editor-link';
17 import { withStyles, StyleRulesCallback, Chip, WithStyles } from '@material-ui/core';
18 import { ArvadosTheme } from '~/common/custom-theme';
19 import * as CopyToClipboard from 'react-copy-to-clipboard';
20 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
21 import { getTagValueLabel, getTagKeyLabel, Vocabulary } from '~/models/vocabulary';
22 import { getVocabulary } from "~/store/vocabulary/vocabulary-selectors";
23 import { Dispatch } from 'redux';
25 export class ProjectDetails extends DetailsData<ProjectResource> {
26 getIcon(className?: string) {
27 return <ProjectIcon className={className} />;
31 return <ProjectDetailsComponent project={this.item} />;
35 type CssRules = 'tag' | 'editIcon';
37 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
39 marginRight: theme.spacing.unit,
40 marginBottom: theme.spacing.unit
49 interface ProjectDetailsComponentDataProps {
50 project: ProjectResource;
51 vocabulary: Vocabulary;
54 interface ProjectDetailsComponentActionProps {
56 onCopy: (message: string) => void;
59 const mapStateToProps = ({ properties }: RootState) => ({
60 vocabulary: getVocabulary(properties),
63 const mapDispatchToProps = (dispatch: Dispatch) => ({
64 onClick: () => dispatch<any>(openProjectPropertiesDialog()),
65 onCopy: (message: string) => dispatch(snackbarActions.OPEN_SNACKBAR({
68 kind: SnackbarKind.SUCCESS
72 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
74 const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
76 ({ classes, project, onClick, vocabulary, onCopy }: ProjectDetailsComponentProps) => <div>
77 <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
79 <DetailsAttribute label='Size' value='---' />
80 <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid} lowercaseValue={true} />
81 <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
82 <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
83 <DetailsAttribute label='Project UUID' linkToUuid={project.uuid} value={project.uuid} />
85 {/*<DetailsAttribute label='File size' value='1.4 GB' />*/}
86 <DetailsAttribute label='Description'>
87 {project.description ?
89 title={`Description of ${project.name}`}
90 content={project.description}
91 label='Show full description' />
95 <DetailsAttribute label='Properties'>
96 <div onClick={onClick}>
97 <RenameIcon className={classes.editIcon} />
101 Object.keys(project.properties).map(k => {
102 const label = `${getTagKeyLabel(k, vocabulary)}: ${getTagValueLabel(k, project.properties[k], vocabulary)}`;
104 <CopyToClipboard key={k} text={label} onCopy={() => onCopy("Copied")}>
105 <Chip key={k} className={classes.tag} label={label} />