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,
150 onDialogOpen: (ownerUuid: string) => { return; },
151 onItemClick: (resourceUuid: string) => {
152 dispatch<any>(loadDetailsPanel(resourceUuid));
154 onItemDoubleClick: uuid => {
155 dispatch<any>(navigateTo(uuid));
159 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
160 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
162 export const FavoritePanel = withStyles(styles)(
163 connect(mapStateToProps, mapDispatchToProps)(
164 class extends React.Component<FavoritePanelProps> {
167 id={FAVORITE_PANEL_ID}
168 onRowClick={this.props.onItemClick}
169 onRowDoubleClick={this.props.onItemDoubleClick}
170 onContextMenu={this.props.onContextMenu}
171 contextMenuColumn={true}
172 dataTableDefaultView={
173 <DataTableDefaultView
175 messages={['Your favorites list is empty.']}