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 { RootState } from '~/store/store';
12 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
13 import { ContainerRequestState } from '~/models/container-request';
14 import { SortDirection } from '~/components/data-table/data-column';
15 import { ResourceKind } from '~/models/resource';
16 import { resourceLabel } from '~/common/labels';
17 import { ArvadosTheme } from '~/common/custom-theme';
18 import { FAVORITE_PANEL_ID, loadFavoritePanel } from "~/store/favorite-panel/favorite-panel-action";
19 import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner, ResourceName } from '~/views-components/data-explorer/renderers';
20 import { FavoriteIcon } from '~/components/icon/icon';
21 import { Dispatch } from 'redux';
22 import { contextMenuActions } from '~/store/context-menu/context-menu-actions';
23 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
24 import { loadDetailsPanel } from '../../store/details-panel/details-panel-action';
25 import { navigateToResource } from '~/store/navigation/navigation-action';
27 type CssRules = "toolbar" | "button";
29 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
31 paddingBottom: theme.spacing.unit * 3,
35 marginLeft: theme.spacing.unit
39 export enum FavoritePanelColumnNames {
44 FILE_SIZE = "File size",
45 LAST_MODIFIED = "Last modified"
48 export interface FavoritePanelFilter extends DataTableFilterItem {
49 type: ResourceKind | ContainerRequestState;
52 export const columns: DataColumns<string, FavoritePanelFilter> = [
54 name: FavoritePanelColumnNames.NAME,
57 sortDirection: SortDirection.ASC,
59 render: uuid => <ResourceName uuid={uuid} />,
66 sortDirection: SortDirection.NONE,
69 name: ContainerRequestState.COMMITTED,
71 type: ContainerRequestState.COMMITTED
74 name: ContainerRequestState.FINAL,
76 type: ContainerRequestState.FINAL
79 name: ContainerRequestState.UNCOMMITTED,
81 type: ContainerRequestState.UNCOMMITTED
84 render: uuid => <ProcessStatus uuid={uuid} />,
88 name: FavoritePanelColumnNames.TYPE,
91 sortDirection: SortDirection.NONE,
94 name: resourceLabel(ResourceKind.COLLECTION),
96 type: ResourceKind.COLLECTION
99 name: resourceLabel(ResourceKind.PROCESS),
101 type: ResourceKind.PROCESS
104 name: resourceLabel(ResourceKind.PROJECT),
106 type: ResourceKind.PROJECT
109 render: uuid => <ResourceType uuid={uuid} />,
113 name: FavoritePanelColumnNames.OWNER,
116 sortDirection: SortDirection.NONE,
118 render: uuid => <ResourceOwner uuid={uuid} />,
122 name: FavoritePanelColumnNames.FILE_SIZE,
125 sortDirection: SortDirection.NONE,
127 render: uuid => <ResourceFileSize uuid={uuid} />,
131 name: FavoritePanelColumnNames.LAST_MODIFIED,
134 sortDirection: SortDirection.NONE,
136 render: uuid => <ResourceLastModifiedDate uuid={uuid} />,
141 interface FavoritePanelDataProps {
142 currentItemId: string;
145 interface FavoritePanelActionProps {
146 onItemClick: (item: string) => void;
147 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
148 onDialogOpen: (ownerUuid: string) => void;
149 onItemDoubleClick: (item: string) => void;
153 const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({
154 onContextMenu: (event, resourceUuid) => {
155 event.preventDefault();
157 contextMenuActions.OPEN_CONTEXT_MENU({
158 position: { x: event.clientX, y: event.clientY },
159 resource: { name: '', uuid: resourceUuid, kind: ContextMenuKind.RESOURCE }
163 onDialogOpen: (ownerUuid: string) => { return; },
164 onItemClick: (resourceUuid: string) => {
165 dispatch<any>(loadDetailsPanel(resourceUuid));
167 onItemDoubleClick: uuid => {
168 dispatch<any>(navigateToResource(uuid));
171 dispatch(loadFavoritePanel());
175 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
176 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
178 export const FavoritePanel = withStyles(styles)(
179 connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }), mapDispatchToProps)(
180 class extends React.Component<FavoritePanelProps> {
183 id={FAVORITE_PANEL_ID}
185 onRowClick={this.props.onItemClick}
186 onRowDoubleClick={this.props.onItemDoubleClick}
187 onContextMenu={this.props.onContextMenu}
188 defaultIcon={FavoriteIcon}
189 defaultMessages={['Your favorites list is empty.']} />;
192 componentDidMount() {
193 this.props.onMount();