1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { ProjectPanelItem } from './project-panel-item';
7 import { Grid, Typography, Button, Toolbar, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
8 import { formatDate, formatFileSize } from '../../common/formatters';
9 import DataExplorer from "../../views-components/data-explorer/data-explorer";
10 import { DataColumn, toggleSortDirection } from '../../components/data-table/data-column';
11 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
12 import { ContextMenuAction } from '../../components/context-menu/context-menu';
13 import { DispatchProp, connect } from 'react-redux';
14 import actions from "../../store/data-explorer/data-explorer-action";
15 import { setProjectItem, ItemMode } from "../../store/navigation/navigation-action";
16 import { DataColumns } from '../../components/data-table/data-table';
17 import { ResourceKind } from "../../models/resource";
18 import { RouteComponentProps } from 'react-router';
20 export const PROJECT_PANEL_ID = "projectPanel";
22 type ProjectPanelProps = { onItemOpen: (itemId: string) => void }
24 & WithStyles<CssRules>
25 & RouteComponentProps<{ id: string }>;
26 class ProjectPanel extends React.Component<ProjectPanelProps> {
29 <div className={this.props.classes.toolbar}>
30 <Button color="primary" variant="raised" className={this.props.classes.button}>
33 <Button color="primary" variant="raised" className={this.props.classes.button}>
36 <Button color="primary" variant="raised" className={this.props.classes.button}>
42 contextActions={contextMenuActions}
43 onColumnToggle={this.toggleColumn}
44 onFiltersChange={this.changeFilters}
45 onRowClick={this.openProject}
46 onSortToggle={this.toggleSort}
47 onSearch={this.search}
48 onContextAction={this.executeAction}
49 onChangePage={this.changePage}
50 onChangeRowsPerPage={this.changeRowsPerPage} />;
55 this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
58 componentWillReceiveProps(nextProps: ProjectPanelProps) {
59 if (this.props.match.params.id !== nextProps.match.params.id) {
60 this.props.onItemOpen(nextProps.match.params.id);
64 toggleColumn = (toggledColumn: DataColumn<ProjectPanelItem>) => {
65 this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name }));
68 toggleSort = (column: DataColumn<ProjectPanelItem>) => {
69 this.props.dispatch(actions.TOGGLE_SORT({ id: PROJECT_PANEL_ID, columnName: column.name }));
72 changeFilters = (filters: DataTableFilterItem[], column: DataColumn<ProjectPanelItem>) => {
73 this.props.dispatch(actions.SET_FILTERS({ id: PROJECT_PANEL_ID, columnName: column.name, filters }));
76 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
77 alert(`Executing ${action.name} on ${item.name}`);
80 search = (searchValue: string) => {
81 this.props.dispatch(actions.SET_SEARCH_VALUE({ id: PROJECT_PANEL_ID, searchValue }));
84 changePage = (page: number) => {
85 this.props.dispatch(actions.SET_PAGE({ id: PROJECT_PANEL_ID, page }));
88 changeRowsPerPage = (rowsPerPage: number) => {
89 this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_PANEL_ID, rowsPerPage }));
92 openProject = (item: ProjectPanelItem) => {
93 this.props.onItemOpen(item.uuid);
97 type CssRules = "toolbar" | "button";
99 const styles: StyleRulesCallback<CssRules> = theme => ({
101 paddingBottom: theme.spacing.unit * 3,
105 marginLeft: theme.spacing.unit
109 const renderName = (item: ProjectPanelItem) =>
119 <Typography color="primary">
126 const renderIcon = (item: ProjectPanelItem) => {
128 case ResourceKind.PROJECT:
129 return <i className="fas fa-folder fa-lg" />;
130 case ResourceKind.COLLECTION:
131 return <i className="fas fa-th fa-lg" />;
137 const renderDate = (date: string) =>
142 const renderFileSize = (fileSize?: number) =>
144 {formatFileSize(fileSize)}
147 const renderOwner = (owner: string) =>
148 <Typography noWrap color="primary">
152 const renderType = (type: string) =>
157 const renderStatus = (item: ProjectPanelItem) =>
158 <Typography noWrap align="center">
162 const columns: DataColumns<ProjectPanelItem> = [{
165 sortDirection: "desc",
171 render: renderStatus,
183 render: item => renderType(item.kind),
188 render: item => renderOwner(item.owner),
193 render: item => renderFileSize(item.fileSize),
196 name: "Last modified",
198 sortDirection: "none",
199 render: item => renderDate(item.lastModified),
203 const contextMenuActions = [[{
204 icon: "fas fa-users fa-fw",
207 icon: "fas fa-sign-out-alt fa-fw",
210 icon: "fas fa-star fa-fw",
211 name: "Add to favourite"
213 icon: "fas fa-edit fa-fw",
216 icon: "fas fa-copy fa-fw",
219 icon: "fas fa-download fa-fw",
222 icon: "fas fa-trash-alt fa-fw",
227 export default withStyles(styles)(connect()(ProjectPanel));