1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
7 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
8 import { DispatchProp, connect } from 'react-redux';
9 import { DataColumns } from '~/components/data-table/data-table';
10 import { RouteComponentProps } from 'react-router';
11 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
12 import { ContainerRequestState } from '~/models/container-request';
13 import { SortDirection } from '~/components/data-table/data-column';
14 import { ResourceKind } from '~/models/resource';
15 import { resourceLabel } from '~/common/labels';
16 import { ArvadosTheme } from '~/common/custom-theme';
17 import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action";
18 import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner, ResourceName } from '~/views-components/data-explorer/renderers';
19 import { FavoriteIcon } from '~/components/icon/icon';
20 import { Dispatch } from 'redux';
21 import { contextMenuActions, openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
22 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
23 import { loadDetailsPanel } from '../../store/details-panel/details-panel-action';
24 import { navigateTo } from '~/store/navigation/navigation-action';
26 type CssRules = "toolbar" | "button";
28 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
30 paddingBottom: theme.spacing.unit * 3,
34 marginLeft: theme.spacing.unit
38 export enum FavoritePanelColumnNames {
43 FILE_SIZE = "File size",
44 LAST_MODIFIED = "Last modified"
47 export interface FavoritePanelFilter extends DataTableFilterItem {
48 type: ResourceKind | ContainerRequestState;
51 export const favoritePanelColumns: DataColumns<string, FavoritePanelFilter> = [
53 name: FavoritePanelColumnNames.NAME,
56 sortDirection: SortDirection.ASC,
58 render: uuid => <ResourceName uuid={uuid} />,
65 sortDirection: SortDirection.NONE,
68 name: ContainerRequestState.COMMITTED,
70 type: ContainerRequestState.COMMITTED
73 name: ContainerRequestState.FINAL,
75 type: ContainerRequestState.FINAL
78 name: ContainerRequestState.UNCOMMITTED,
80 type: ContainerRequestState.UNCOMMITTED
83 render: uuid => <ProcessStatus uuid={uuid} />,
87 name: FavoritePanelColumnNames.TYPE,
90 sortDirection: SortDirection.NONE,
93 name: resourceLabel(ResourceKind.COLLECTION),
95 type: ResourceKind.COLLECTION
98 name: resourceLabel(ResourceKind.PROCESS),
100 type: ResourceKind.PROCESS
103 name: resourceLabel(ResourceKind.PROJECT),
105 type: ResourceKind.PROJECT
108 render: uuid => <ResourceType uuid={uuid} />,
112 name: FavoritePanelColumnNames.OWNER,
115 sortDirection: SortDirection.NONE,
117 render: uuid => <ResourceOwner uuid={uuid} />,
121 name: FavoritePanelColumnNames.FILE_SIZE,
124 sortDirection: SortDirection.NONE,
126 render: uuid => <ResourceFileSize uuid={uuid} />,
130 name: FavoritePanelColumnNames.LAST_MODIFIED,
133 sortDirection: SortDirection.NONE,
135 render: uuid => <ResourceLastModifiedDate uuid={uuid} />,
140 interface FavoritePanelDataProps {
141 currentItemId: string;
144 interface FavoritePanelActionProps {
145 onItemClick: (item: string) => void;
146 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
147 onDialogOpen: (ownerUuid: string) => void;
148 onItemDoubleClick: (item: string) => void;
151 const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({
152 onContextMenu: (event, resourceUuid) => {
153 const kind = resourceKindToContextMenuKind(resourceUuid);
155 dispatch<any>(openContextMenu(event, { name: '', uuid: resourceUuid, kind }));
158 onDialogOpen: (ownerUuid: string) => { return; },
159 onItemClick: (resourceUuid: string) => {
160 dispatch<any>(loadDetailsPanel(resourceUuid));
162 onItemDoubleClick: uuid => {
163 dispatch<any>(navigateTo(uuid));
167 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
168 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
170 export const FavoritePanel = withStyles(styles)(
171 connect(undefined, mapDispatchToProps)(
172 class extends React.Component<FavoritePanelProps> {
175 id={FAVORITE_PANEL_ID}
176 onRowClick={this.props.onItemClick}
177 onRowDoubleClick={this.props.onItemDoubleClick}
178 onContextMenu={this.props.onContextMenu}
179 defaultIcon={FavoriteIcon}
180 defaultMessages={['Your favorites list is empty.']} />;