Post merge fixes
[arvados-workbench2.git] / src / views / project-panel / project-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
7 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
8 import { DispatchProp, connect } from 'react-redux';
9 import { DataColumns } from '~/components/data-table/data-table';
10 import { RouteComponentProps } from 'react-router';
11 import { RootState } from '~/store/store';
12 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
13 import { SortDirection } from '~/components/data-table/data-column';
14 import { ResourceKind } from '~/models/resource';
15 import { resourceLabel } from '~/common/labels';
16 import { ArvadosTheme } from '~/common/custom-theme';
17 import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner } from '~/views-components/data-explorer/renderers';
18 import { ProjectIcon } from '~/components/icon/icon';
19 import { ResourceName } from '~/views-components/data-explorer/renderers';
20 import { ResourcesState } from '~/store/resources/resources';
21 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
22 import { resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions';
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 { openCollectionCreateDialog } from '../../store/collections/collection-create-actions';
27 import { openProjectCreateDialog } from '~/store/projects/project-create-actions';
28 import { ContainerRequestState } from "~/models/container-request";
29
30 type CssRules = 'root' | "toolbar" | "button";
31
32 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33     root: {
34         position: 'relative',
35         width: '100%',
36         height: '100%'
37     },
38     toolbar: {
39         paddingBottom: theme.spacing.unit * 3,
40         textAlign: "right"
41     },
42     button: {
43         marginLeft: theme.spacing.unit
44     },
45 });
46
47 export enum ProjectPanelColumnNames {
48     NAME = "Name",
49     STATUS = "Status",
50     TYPE = "Type",
51     OWNER = "Owner",
52     FILE_SIZE = "File size",
53     LAST_MODIFIED = "Last modified"
54 }
55
56 export interface ProjectPanelFilter extends DataTableFilterItem {
57     type: ResourceKind | ContainerRequestState;
58 }
59
60 export const projectPanelColumns: DataColumns<string, ProjectPanelFilter> = [
61     {
62         name: ProjectPanelColumnNames.NAME,
63         selected: true,
64         configurable: true,
65         sortDirection: SortDirection.ASC,
66         filters: [],
67         render: uuid => <ResourceName uuid={uuid} />,
68         width: "450px"
69     },
70     {
71         name: "Status",
72         selected: true,
73         configurable: true,
74         sortDirection: SortDirection.NONE,
75         filters: [
76             {
77                 name: ContainerRequestState.COMMITTED,
78                 selected: true,
79                 type: ContainerRequestState.COMMITTED
80             },
81             {
82                 name: ContainerRequestState.FINAL,
83                 selected: true,
84                 type: ContainerRequestState.FINAL
85             },
86             {
87                 name: ContainerRequestState.UNCOMMITTED,
88                 selected: true,
89                 type: ContainerRequestState.UNCOMMITTED
90             }
91         ],
92         render: uuid => <ProcessStatus uuid={uuid} />,
93         width: "75px"
94     },
95     {
96         name: ProjectPanelColumnNames.TYPE,
97         selected: true,
98         configurable: true,
99         sortDirection: SortDirection.NONE,
100         filters: [
101             {
102                 name: resourceLabel(ResourceKind.COLLECTION),
103                 selected: true,
104                 type: ResourceKind.COLLECTION
105             },
106             {
107                 name: resourceLabel(ResourceKind.PROCESS),
108                 selected: true,
109                 type: ResourceKind.PROCESS
110             },
111             {
112                 name: resourceLabel(ResourceKind.PROJECT),
113                 selected: true,
114                 type: ResourceKind.PROJECT
115             }
116         ],
117         render: uuid => <ResourceType uuid={uuid} />,
118         width: "125px"
119     },
120     {
121         name: ProjectPanelColumnNames.OWNER,
122         selected: true,
123         configurable: true,
124         sortDirection: SortDirection.NONE,
125         filters: [],
126         render: uuid => <ResourceOwner uuid={uuid} />,
127         width: "200px"
128     },
129     {
130         name: ProjectPanelColumnNames.FILE_SIZE,
131         selected: true,
132         configurable: true,
133         sortDirection: SortDirection.NONE,
134         filters: [],
135         render: uuid => <ResourceFileSize uuid={uuid} />,
136         width: "50px"
137     },
138     {
139         name: ProjectPanelColumnNames.LAST_MODIFIED,
140         selected: true,
141         configurable: true,
142         sortDirection: SortDirection.NONE,
143         filters: [],
144         render: uuid => <ResourceLastModifiedDate uuid={uuid} />,
145         width: "150px"
146     }
147 ];
148
149 export const PROJECT_PANEL_ID = "projectPanel";
150
151 interface ProjectPanelDataProps {
152     currentItemId: string;
153     resources: ResourcesState;
154 }
155
156 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
157     & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
158
159 export const ProjectPanel = withStyles(styles)(
160     connect((state: RootState) => ({
161         currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
162         resources: state.resources
163     }))(
164         class extends React.Component<ProjectPanelProps> {
165             render() {
166                 const { classes } = this.props;
167                 return <div className={classes.root}>
168                     <div className={classes.toolbar}>
169                         <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
170                             Create a collection
171                         </Button>
172                         <Button color="primary" variant="raised" className={classes.button}>
173                             Run a process
174                         </Button>
175                         <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
176                             New project
177                         </Button>
178                     </div>
179                     <DataExplorer
180                         id={PROJECT_PANEL_ID}
181                         onRowClick={this.handleRowClick}
182                         onRowDoubleClick={this.handleRowDoubleClick}
183                         onContextMenu={this.handleContextMenu}
184                         defaultIcon={ProjectIcon}
185                         defaultMessages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']} />
186                 </div>;
187             }
188
189             handleNewProjectClick = () => {
190                 this.props.dispatch<any>(openProjectCreateDialog(this.props.currentItemId));
191             }
192
193             handleNewCollectionClick = () => {
194                 this.props.dispatch<any>(openCollectionCreateDialog(this.props.currentItemId));
195             }
196
197             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
198                 const kind = resourceKindToContextMenuKind(resourceUuid);
199                 if (kind) {
200                     this.props.dispatch<any>(openContextMenu(event, { name: '', uuid: resourceUuid, kind }));
201                 }
202             }
203
204             handleRowDoubleClick = (uuid: string) => {
205                 this.props.dispatch<any>(navigateTo(uuid));
206             }
207
208             handleRowClick = (uuid: string) => {
209                 this.props.dispatch(loadDetailsPanel(uuid));
210             }
211
212         }
213     )
214 );