Merge remote-tracking branch 'origin/main' into 18207-Workbench2-is-not-clearing...
[arvados-workbench2.git] / src / views-components / details-panel / project-details.tsx
index 7db4df7be7d4eb83706fb186928c029ee3a24aae..41ba6f00f154f2a5f3b9bf1f4fb2a8eb28b9f7e4 100644 (file)
@@ -2,28 +2,29 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import React from 'react';
 import { connect } from 'react-redux';
-import { RootState } from '~/store/store';
-import { openProjectPropertiesDialog } from '~/store/details-panel/details-panel-action';
-import { ProjectIcon, RenameIcon } from '~/components/icon/icon';
-import { ProjectResource } from '~/models/project';
-import { formatDate } from '~/common/formatters';
-import { ResourceKind } from '~/models/resource';
-import { resourceLabel } from '~/common/labels';
+import { openProjectPropertiesDialog } from 'store/details-panel/details-panel-action';
+import { ProjectIcon, RenameIcon, FilterGroupIcon } from 'components/icon/icon';
+import { ProjectResource } from 'models/project';
+import { formatDate } from 'common/formatters';
+import { ResourceKind } from 'models/resource';
+import { resourceLabel } from 'common/labels';
 import { DetailsData } from "./details-data";
-import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
-import { RichTextEditorLink } from '~/components/rich-text-editor-link/rich-text-editor-link';
-import { withStyles, StyleRulesCallback, Chip, WithStyles } from '@material-ui/core';
-import { ArvadosTheme } from '~/common/custom-theme';
-import * as CopyToClipboard from 'react-copy-to-clipboard';
-import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
-import { getTagValueLabel, getTagKeyLabel, Vocabulary } from '~/models/vocabulary';
-import { getVocabulary } from "~/store/vocabulary/vocabulary-selectors";
+import { DetailsAttribute } from "components/details-attribute/details-attribute";
+import { RichTextEditorLink } from 'components/rich-text-editor-link/rich-text-editor-link';
+import { withStyles, StyleRulesCallback, WithStyles } from '@material-ui/core';
+import { ArvadosTheme } from 'common/custom-theme';
 import { Dispatch } from 'redux';
+import { getPropertyChip } from '../resource-properties-form/property-chip';
+import { ResourceOwnerWithName } from '../data-explorer/renderers';
+import { GroupClass } from "models/group";
 
 export class ProjectDetails extends DetailsData<ProjectResource> {
     getIcon(className?: string) {
+        if (this.item.groupClass === GroupClass.FILTER) {
+            return <FilterGroupIcon className={className} />;
+        }
         return <ProjectIcon className={className} />;
     }
 
@@ -45,44 +46,29 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
-
 interface ProjectDetailsComponentDataProps {
     project: ProjectResource;
-    vocabulary: Vocabulary;
 }
 
 interface ProjectDetailsComponentActionProps {
     onClick: () => void;
-    onCopy: (message: string) => void;
 }
 
-const mapStateToProps = ({ properties }: RootState) => ({
-    vocabulary: getVocabulary(properties),
-});
-
 const mapDispatchToProps = (dispatch: Dispatch) => ({
     onClick: () => dispatch<any>(openProjectPropertiesDialog()),
-    onCopy: (message: string) => dispatch(snackbarActions.OPEN_SNACKBAR({
-        message,
-        hideDuration: 2000,
-        kind: SnackbarKind.SUCCESS
-    }))
 });
 
 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
 
-const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
+const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
     withStyles(styles)(
-        ({ classes, project, onClick, vocabulary, onCopy }: ProjectDetailsComponentProps) => <div>
-            <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
-            {/* Missing attr */}
-            <DetailsAttribute label='Size' value='---' />
-            <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid} lowercaseValue={true} />
+        ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
+            <DetailsAttribute label='Type' value={project.groupClass === GroupClass.FILTER ? 'Filter group' : resourceLabel(ResourceKind.PROJECT)} />
+            <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid}
+                uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
             <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
             <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
-            <DetailsAttribute label='Project UUID' linkToUuid={project.uuid} value={project.uuid} />
-            {/* Missing attr */}
-            {/*<DetailsAttribute label='File size' value='1.4 GB' />*/}
+            <DetailsAttribute label='UUID' linkToUuid={project.uuid} value={project.uuid} />
             <DetailsAttribute label='Description'>
                 {project.description ?
                     <RichTextEditorLink
@@ -93,19 +79,20 @@ const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
                 }
             </DetailsAttribute>
             <DetailsAttribute label='Properties'>
-                <div onClick={onClick}>
-                    <RenameIcon className={classes.editIcon} />
-                </div>
+                {project.groupClass !== GroupClass.FILTER ?
+                    <div onClick={onClick}>
+                        <RenameIcon className={classes.editIcon} />
+                    </div>
+                    : ''
+                }
             </DetailsAttribute>
             {
-                Object.keys(project.properties).map(k => {
-                    const label = `${getTagKeyLabel(k, vocabulary)}: ${getTagValueLabel(k, project.properties[k], vocabulary)}`;
-                    return (
-                        <CopyToClipboard key={k} text={label} onCopy={() => onCopy("Copied")}>
-                            <Chip key={k} className={classes.tag} label={label} />
-                        </CopyToClipboard>
-                    );
-                })
+                Object.keys(project.properties).map(k =>
+                    Array.isArray(project.properties[k])
+                    ? project.properties[k].map((v: string) =>
+                        getPropertyChip(k, v, undefined, classes.tag))
+                    : getPropertyChip(k, project.properties[k], undefined, classes.tag)
+                )
             }
         </div>
     ));