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 } from "../../store/navigation/navigation-action";
16 import { DataColumns } from '../../components/data-table/data-table';
17 import { ResourceKind } from "../../models/resource";
19 export const PROJECT_PANEL_ID = "projectPanel";
20 class ProjectPanel extends React.Component<DispatchProp & WithStyles<CssRules>> {
23 <div className={this.props.classes.toolbar}>
24 <Button color="primary" variant="raised" className={this.props.classes.button}>
27 <Button color="primary" variant="raised" className={this.props.classes.button}>
30 <Button color="primary" variant="raised" className={this.props.classes.button}>
36 contextActions={contextMenuActions}
37 onColumnToggle={this.toggleColumn}
38 onFiltersChange={this.changeFilters}
39 onRowClick={this.openProject}
40 onSortToggle={this.toggleSort}
41 onSearch={this.search}
42 onContextAction={this.executeAction}
43 onChangePage={this.changePage}
44 onChangeRowsPerPage={this.changeRowsPerPage} />;
49 this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
52 toggleColumn = (toggledColumn: DataColumn<ProjectPanelItem>) => {
53 this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name }));
56 toggleSort = (column: DataColumn<ProjectPanelItem>) => {
57 this.props.dispatch(actions.TOGGLE_SORT({ id: PROJECT_PANEL_ID, columnName: column.name }));
60 changeFilters = (filters: DataTableFilterItem[], column: DataColumn<ProjectPanelItem>) => {
61 this.props.dispatch(actions.SET_FILTERS({ id: PROJECT_PANEL_ID, columnName: column.name, filters }));
64 executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
65 alert(`Executing ${action.name} on ${item.name}`);
68 search = (searchValue: string) => {
69 this.props.dispatch(actions.SET_SEARCH_VALUE({ id: PROJECT_PANEL_ID, searchValue }));
72 changePage = (page: number) => {
73 this.props.dispatch(actions.SET_PAGE({ id: PROJECT_PANEL_ID, page }));
76 changeRowsPerPage = (rowsPerPage: number) => {
77 this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_PANEL_ID, rowsPerPage }));
80 openProject = (item: ProjectPanelItem) => {
81 this.props.dispatch<any>(setProjectItem(item.uuid));
85 type CssRules = "toolbar" | "button";
87 const styles: StyleRulesCallback<CssRules> = theme => ({
89 paddingBottom: theme.spacing.unit * 3,
93 marginLeft: theme.spacing.unit
97 const renderName = (item: ProjectPanelItem) =>
107 <Typography color="primary">
114 const renderIcon = (item: ProjectPanelItem) => {
116 case ResourceKind.LEVEL_UP:
117 return <i className="icon-level-up" style={{ fontSize: "1rem" }} />;
118 case ResourceKind.PROJECT:
119 return <i className="fas fa-folder fa-lg" />;
120 case ResourceKind.COLLECTION:
121 return <i className="fas fa-th fa-lg" />;
127 const renderDate = (date: string) =>
132 const renderFileSize = (fileSize?: number) =>
134 {formatFileSize(fileSize)}
137 const renderOwner = (owner: string) =>
138 <Typography noWrap color="primary">
142 const renderType = (type: string) =>
147 const renderStatus = (item: ProjectPanelItem) =>
148 <Typography noWrap align="center">
152 const columns: DataColumns<ProjectPanelItem> = [{
155 sortDirection: "desc",
161 render: renderStatus,
173 render: item => renderType(item.kind),
178 render: item => renderOwner(item.owner),
183 render: item => renderFileSize(item.fileSize),
186 name: "Last modified",
188 sortDirection: "none",
189 render: item => renderDate(item.lastModified),
193 const contextMenuActions = [[{
194 icon: "fas fa-users fa-fw",
197 icon: "fas fa-sign-out-alt fa-fw",
200 icon: "fas fa-star fa-fw",
201 name: "Add to favourite"
203 icon: "fas fa-edit fa-fw",
206 icon: "fas fa-copy fa-fw",
209 icon: "fas fa-download fa-fw",
212 icon: "fas fa-trash-alt fa-fw",
217 export default withStyles(styles)(connect()(ProjectPanel));