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 { connect, DispatchProp } 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 { SortDirection } from '~/components/data-table/data-column';
13 import { ResourceKind } from '~/models/resource';
14 import { resourceLabel } from '~/common/labels';
15 import { ArvadosTheme } from '~/common/custom-theme';
16 import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action";
20 ResourceLastModifiedDate,
24 } from '~/views-components/data-explorer/renderers';
25 import { FavoriteIcon } from '~/components/icon/icon';
26 import { Dispatch } from 'redux';
27 import { openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
28 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
29 import { navigateTo } from '~/store/navigation/navigation-action';
30 import { ContainerRequestState } from "~/models/container-request";
31 import { FavoritesState } from '../../store/favorites/favorites-reducer';
32 import { RootState } from '~/store/store';
33 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
35 type CssRules = "toolbar" | "button";
37 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
39 paddingBottom: theme.spacing.unit * 3,
43 marginLeft: theme.spacing.unit
47 export enum FavoritePanelColumnNames {
52 FILE_SIZE = "File size",
53 LAST_MODIFIED = "Last modified"
56 export interface FavoritePanelFilter extends DataTableFilterItem {
57 type: ResourceKind | ContainerRequestState;
60 export const favoritePanelColumns: DataColumns<string, FavoritePanelFilter> = [
62 name: FavoritePanelColumnNames.NAME,
65 sortDirection: SortDirection.ASC,
67 render: uuid => <ResourceName uuid={uuid} />
74 render: uuid => <ProcessStatus uuid={uuid} />
77 name: FavoritePanelColumnNames.TYPE,
82 name: resourceLabel(ResourceKind.COLLECTION),
84 type: ResourceKind.COLLECTION
87 name: resourceLabel(ResourceKind.PROCESS),
89 type: ResourceKind.PROCESS
92 name: resourceLabel(ResourceKind.PROJECT),
94 type: ResourceKind.PROJECT
97 render: uuid => <ResourceType uuid={uuid} />
100 name: FavoritePanelColumnNames.OWNER,
104 render: uuid => <ResourceOwner uuid={uuid} />
107 name: FavoritePanelColumnNames.FILE_SIZE,
111 render: uuid => <ResourceFileSize uuid={uuid} />
114 name: FavoritePanelColumnNames.LAST_MODIFIED,
117 sortDirection: SortDirection.NONE,
119 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
123 interface FavoritePanelDataProps {
124 favorites: FavoritesState;
127 interface FavoritePanelActionProps {
128 onItemClick: (item: string) => void;
129 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
130 onDialogOpen: (ownerUuid: string) => void;
131 onItemDoubleClick: (item: string) => void;
133 const mapStateToProps = ({ favorites }: RootState): FavoritePanelDataProps => ({
137 const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({
138 onContextMenu: (event, resourceUuid) => {
139 const kind = resourceKindToContextMenuKind(resourceUuid);
141 dispatch<any>(openContextMenu(event, {
145 kind: ResourceKind.NONE,
149 dispatch<any>(loadDetailsPanel(resourceUuid));
151 onDialogOpen: (ownerUuid: string) => { return; },
152 onItemClick: (resourceUuid: string) => {
153 dispatch<any>(loadDetailsPanel(resourceUuid));
155 onItemDoubleClick: uuid => {
156 dispatch<any>(navigateTo(uuid));
160 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
161 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
163 export const FavoritePanel = withStyles(styles)(
164 connect(mapStateToProps, mapDispatchToProps)(
165 class extends React.Component<FavoritePanelProps> {
168 id={FAVORITE_PANEL_ID}
169 onRowClick={this.props.onItemClick}
170 onRowDoubleClick={this.props.onItemDoubleClick}
171 onContextMenu={this.props.onContextMenu}
172 contextMenuColumn={true}
173 dataTableDefaultView={
174 <DataTableDefaultView
176 messages={['Your favorites list is empty.']}