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 = { onItemClick: (item: ProjectPanelItem) => void }
24 & WithStyles<CssRules>;
25 class ProjectPanel extends React.Component<ProjectPanelProps> {
28 <div className={this.props.classes.toolbar}>
29 <Button color="primary" variant="raised" className={this.props.classes.button}>
32 <Button color="primary" variant="raised" className={this.props.classes.button}>
35 <Button color="primary" variant="raised" className={this.props.classes.button}>
41 contextActions={contextMenuActions}
42 onColumnToggle={this.toggleColumn}
43 onFiltersChange={this.changeFilters}
44 onRowClick={this.props.onItemClick}
45 onSortToggle={this.toggleSort}
46 onSearch={this.search}
47 onContextAction={this.executeAction}
48 onChangePage={this.changePage}
49 onChangeRowsPerPage={this.changeRowsPerPage} />;
54 this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
57 toggleColumn = (toggledColumn: DataColumn<ProjectPanelItem>) => {
58 this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name }));
61 toggleSort = (column: DataColumn<ProjectPanelItem>) => {
62 this.props.dispatch(actions.TOGGLE_SORT({ id: PROJECT_PANEL_ID, columnName: column.name }));
65 changeFilters = (filters: DataTableFilterItem[], column: DataColumn<ProjectPanelItem>) => {
66 this.props.dispatch(actions.SET_FILTERS({ id: PROJECT_PANEL_ID, columnName: column.name, filters }));
69 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
70 alert(`Executing ${action.name} on ${item.name}`);
73 search = (searchValue: string) => {
74 this.props.dispatch(actions.SET_SEARCH_VALUE({ id: PROJECT_PANEL_ID, searchValue }));
77 changePage = (page: number) => {
78 this.props.dispatch(actions.SET_PAGE({ id: PROJECT_PANEL_ID, page }));
81 changeRowsPerPage = (rowsPerPage: number) => {
82 this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_PANEL_ID, rowsPerPage }));
86 type CssRules = "toolbar" | "button";
88 const styles: StyleRulesCallback<CssRules> = theme => ({
90 paddingBottom: theme.spacing.unit * 3,
94 marginLeft: theme.spacing.unit
98 const renderName = (item: ProjectPanelItem) =>
108 <Typography color="primary">
115 const renderIcon = (item: ProjectPanelItem) => {
117 case ResourceKind.PROJECT:
118 return <i className="fas fa-folder fa-lg" />;
119 case ResourceKind.COLLECTION:
120 return <i className="fas fa-th fa-lg" />;
126 const renderDate = (date: string) =>
131 const renderFileSize = (fileSize?: number) =>
133 {formatFileSize(fileSize)}
136 const renderOwner = (owner: string) =>
137 <Typography noWrap color="primary">
141 const renderType = (type: string) =>
146 const renderStatus = (item: ProjectPanelItem) =>
147 <Typography noWrap align="center">
151 const columns: DataColumns<ProjectPanelItem> = [{
154 sortDirection: "desc",
160 render: renderStatus,
172 render: item => renderType(item.kind),
177 render: item => renderOwner(item.owner),
182 render: item => renderFileSize(item.fileSize),
185 name: "Last modified",
187 sortDirection: "none",
188 render: item => renderDate(item.lastModified),
192 const contextMenuActions = [[{
193 icon: "fas fa-users fa-fw",
196 icon: "fas fa-sign-out-alt fa-fw",
199 icon: "fas fa-star fa-fw",
200 name: "Add to favourite"
202 icon: "fas fa-edit fa-fw",
205 icon: "fas fa-copy fa-fw",
208 icon: "fas fa-download fa-fw",
211 icon: "fas fa-trash-alt fa-fw",
216 export default withStyles(styles)(connect()(ProjectPanel));