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,
62 sortDirection: SortDirection.NONE,
65 name: ContainerRequestState.COMMITTED,
67 type: ContainerRequestState.COMMITTED
70 name: ContainerRequestState.FINAL,
72 type: ContainerRequestState.FINAL
75 name: ContainerRequestState.UNCOMMITTED,
77 type: ContainerRequestState.UNCOMMITTED
84 name: FavoritePanelColumnNames.TYPE,
87 sortDirection: SortDirection.NONE,
90 name: resourceLabel(ResourceKind.COLLECTION),
92 type: ResourceKind.COLLECTION
95 name: resourceLabel(ResourceKind.PROCESS),
97 type: ResourceKind.PROCESS
100 name: resourceLabel(ResourceKind.PROJECT),
102 type: ResourceKind.PROJECT
105 render: item => renderType(item.kind),
109 name: FavoritePanelColumnNames.OWNER,
112 sortDirection: SortDirection.NONE,
114 render: item => renderOwner(item.owner),
118 name: FavoritePanelColumnNames.FILE_SIZE,
121 sortDirection: SortDirection.NONE,
123 render: item => renderFileSize(item.fileSize),
127 name: FavoritePanelColumnNames.LAST_MODIFIED,
130 sortDirection: SortDirection.NONE,
132 render: item => renderDate(item.lastModified),
137 interface FavoritePanelDataProps {
138 currentItemId: string;
141 interface FavoritePanelActionProps {
142 onItemClick: (item: FavoritePanelItem) => void;
143 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: FavoritePanelItem) => void;
144 onDialogOpen: (ownerUuid: string) => void;
145 onItemDoubleClick: (item: FavoritePanelItem) => void;
146 onItemRouteChange: (itemId: string) => void;
149 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
150 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
152 export const FavoritePanel = withStyles(styles)(
153 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
154 class extends React.Component<FavoritePanelProps> {
157 id={FAVORITE_PANEL_ID}
159 onRowClick={this.props.onItemClick}
160 onRowDoubleClick={this.props.onItemDoubleClick}
161 onContextMenu={this.props.onContextMenu}
162 extractKey={(item: FavoritePanelItem) => item.uuid}
163 defaultIcon={FavoriteIcon}
164 defaultMessages={['Your favorites list is empty.']}/>
168 componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: FavoritePanelProps) {
169 if (match.params.id !== currentItemId) {
170 onItemRouteChange(match.params.id);