1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
7 import { DispatchProp, connect } from 'react-redux';
8 import { DataColumns } from '~/components/data-table/data-table';
9 import { RouteComponentProps } from 'react-router';
10 import { RootState } from '~/store/store';
11 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
12 import { ContainerRequestState } from '~/models/container-request';
13 import { SortDirection } from '~/components/data-table/data-column';
14 import { ResourceKind, Resource } from '~/models/resource';
15 import { resourceLabel } from '~/common/labels';
16 import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner } from '~/views-components/data-explorer/renderers';
17 import { ProjectIcon } from '~/components/icon/icon';
18 import { ResourceName } from '~/views-components/data-explorer/renderers';
19 import { ResourcesState, getResource } from '~/store/resources/resources';
20 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
21 import { resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions';
22 import { ProjectResource } from '~/models/project';
23 import { navigateTo } from '~/store/navigation/navigation-action';
24 import { getProperty } from '~/store/properties/properties';
25 import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action';
26 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
27 import { StyleRulesCallback, WithStyles } from "@material-ui/core";
28 import { ArvadosTheme } from "~/common/custom-theme";
29 import withStyles from "@material-ui/core/styles/withStyles";
31 type CssRules = 'root' | "button";
33 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 marginLeft: theme.spacing.unit
44 export enum ProjectPanelColumnNames {
49 FILE_SIZE = "File size",
50 LAST_MODIFIED = "Last modified"
53 export interface ProjectPanelFilter extends DataTableFilterItem {
54 type: ResourceKind | ContainerRequestState;
57 export const projectPanelColumns: DataColumns<string, ProjectPanelFilter> = [
59 name: ProjectPanelColumnNames.NAME,
62 sortDirection: SortDirection.ASC,
64 render: uuid => <ResourceName uuid={uuid} />
71 render: uuid => <ProcessStatus uuid={uuid} />,
74 name: ProjectPanelColumnNames.TYPE,
79 name: resourceLabel(ResourceKind.COLLECTION),
81 type: ResourceKind.COLLECTION
84 name: resourceLabel(ResourceKind.PROCESS),
86 type: ResourceKind.PROCESS
89 name: resourceLabel(ResourceKind.PROJECT),
91 type: ResourceKind.PROJECT
94 render: uuid => <ResourceType uuid={uuid} />
97 name: ProjectPanelColumnNames.OWNER,
101 render: uuid => <ResourceOwner uuid={uuid} />
104 name: ProjectPanelColumnNames.FILE_SIZE,
108 render: uuid => <ResourceFileSize uuid={uuid} />
111 name: ProjectPanelColumnNames.LAST_MODIFIED,
114 sortDirection: SortDirection.NONE,
116 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
120 export const PROJECT_PANEL_ID = "projectPanel";
122 interface ProjectPanelDataProps {
123 currentItemId: string;
124 resources: ResourcesState;
127 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
128 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
130 export const ProjectPanel = withStyles(styles)(
131 connect((state: RootState) => ({
132 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
133 resources: state.resources
135 class extends React.Component<ProjectPanelProps> {
137 const { classes } = this.props;
138 return <div className={classes.root}>
140 id={PROJECT_PANEL_ID}
141 onRowClick={this.handleRowClick}
142 onRowDoubleClick={this.handleRowDoubleClick}
143 onContextMenu={this.handleContextMenu}
144 contextMenuColumn={true}
145 dataTableDefaultView={
146 <DataTableDefaultView
149 'Your project is empty.',
150 'Please create a project or create a collection and upload a data.'
156 isCurrentItemChild = (resource: Resource) => {
157 return resource.ownerUuid === this.props.currentItemId;
160 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
161 const menuKind = resourceKindToContextMenuKind(resourceUuid);
162 const resource = getResource<ProjectResource>(resourceUuid)(this.props.resources);
163 if (menuKind && resource) {
164 this.props.dispatch<any>(openContextMenu(event, {
167 ownerUuid: resource.ownerUuid,
168 isTrashed: resource.isTrashed,
175 handleRowDoubleClick = (uuid: string) => {
176 this.props.dispatch<any>(navigateTo(uuid));
179 handleRowClick = (uuid: string) => {
180 this.props.dispatch(loadDetailsPanel(uuid));