1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { FavoritePanelItem } from './favorite-panel-item';
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
8 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
9 import { DispatchProp, connect } from 'react-redux';
10 import { DataColumns } from '~/components/data-table/data-table';
11 import { RouteComponentProps } from 'react-router';
12 import { RootState } from '~/store/store';
13 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
14 import { ContainerRequestState } from '~/models/container-request';
15 import { SortDirection } from '~/components/data-table/data-column';
16 import { ResourceKind } from '~/models/resource';
17 import { resourceLabel } from '~/common/labels';
18 import { ArvadosTheme } from '~/common/custom-theme';
19 import { renderName, renderStatus, renderType, renderOwner, renderFileSize, renderDate } from '~/views-components/data-explorer/renderers';
20 import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action";
21 import { FavoriteIcon } from '~/components/icon/icon';
23 type CssRules = "toolbar" | "button";
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 paddingBottom: theme.spacing.unit * 3,
31 marginLeft: theme.spacing.unit
35 export enum FavoritePanelColumnNames {
40 FILE_SIZE = "File size",
41 LAST_MODIFIED = "Last modified"
44 export interface FavoritePanelFilter extends DataTableFilterItem {
45 type: ResourceKind | ContainerRequestState;
48 export const columns: DataColumns<FavoritePanelItem, FavoritePanelFilter> = [
50 name: FavoritePanelColumnNames.NAME,
53 sortDirection: SortDirection.ASC,
63 name: ContainerRequestState.COMMITTED,
65 type: ContainerRequestState.COMMITTED
68 name: ContainerRequestState.FINAL,
70 type: ContainerRequestState.FINAL
73 name: ContainerRequestState.UNCOMMITTED,
75 type: ContainerRequestState.UNCOMMITTED
82 name: FavoritePanelColumnNames.TYPE,
87 name: resourceLabel(ResourceKind.COLLECTION),
89 type: ResourceKind.COLLECTION
92 name: resourceLabel(ResourceKind.PROCESS),
94 type: ResourceKind.PROCESS
97 name: resourceLabel(ResourceKind.PROJECT),
99 type: ResourceKind.PROJECT
102 render: item => renderType(item.kind),
106 name: FavoritePanelColumnNames.OWNER,
109 render: item => renderOwner(item.owner),
113 name: FavoritePanelColumnNames.FILE_SIZE,
116 render: item => renderFileSize(item.fileSize),
120 name: FavoritePanelColumnNames.LAST_MODIFIED,
123 sortDirection: SortDirection.NONE,
124 render: item => renderDate(item.lastModified),
129 interface FavoritePanelDataProps {
130 currentItemId: string;
133 interface FavoritePanelActionProps {
134 onItemClick: (item: FavoritePanelItem) => void;
135 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: FavoritePanelItem) => void;
136 onDialogOpen: (ownerUuid: string) => void;
137 onItemDoubleClick: (item: FavoritePanelItem) => void;
138 onItemRouteChange: (itemId: string) => void;
141 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
142 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
144 export const FavoritePanel = withStyles(styles)(
145 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
146 class extends React.Component<FavoritePanelProps> {
149 id={FAVORITE_PANEL_ID}
151 onRowClick={this.props.onItemClick}
152 onRowDoubleClick={this.props.onItemDoubleClick}
153 onContextMenu={this.props.onContextMenu}
154 extractKey={(item: FavoritePanelItem) => item.uuid}
155 defaultIcon={FavoriteIcon}
156 defaultMessages={['Your favorites list is empty.']}/>
160 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: FavoritePanelProps) {
161 if (match.params.id !== currentItemId) {
162 onItemRouteChange(match.params.id);