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 { ArvadosTheme } from '~/common/custom-theme';
15 import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action";
19 ResourceLastModifiedDate,
23 } from '~/views-components/data-explorer/renderers';
24 import { FavoriteIcon } from '~/components/icon/icon';
25 import { Dispatch } from 'redux';
26 import { openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
27 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
28 import { navigateTo } from '~/store/navigation/navigation-action';
29 import { ContainerRequestState } from "~/models/container-request";
30 import { FavoritesState } from '~/store/favorites/favorites-reducer';
31 import { RootState } from '~/store/store';
32 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
33 import { createTree } from '~/models/tree';
34 import { getSimpleObjectTypeFilters } from '~/store/resource-type-filters/resource-type-filters';
36 type CssRules = "toolbar" | "button";
38 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 paddingBottom: theme.spacing.unit * 3,
44 marginLeft: theme.spacing.unit
48 export enum FavoritePanelColumnNames {
53 FILE_SIZE = "File size",
54 LAST_MODIFIED = "Last modified"
57 export interface FavoritePanelFilter extends DataTableFilterItem {
58 type: ResourceKind | ContainerRequestState;
61 export const favoritePanelColumns: DataColumns<string> = [
63 name: FavoritePanelColumnNames.NAME,
66 sortDirection: SortDirection.ASC,
67 filters: createTree(),
68 render: uuid => <ResourceName uuid={uuid} />
74 filters: createTree(),
75 render: uuid => <ProcessStatus uuid={uuid} />
78 name: FavoritePanelColumnNames.TYPE,
81 filters: getSimpleObjectTypeFilters(),
82 render: uuid => <ResourceType uuid={uuid} />
85 name: FavoritePanelColumnNames.OWNER,
88 filters: createTree(),
89 render: uuid => <ResourceOwner uuid={uuid} />
92 name: FavoritePanelColumnNames.FILE_SIZE,
95 filters: createTree(),
96 render: uuid => <ResourceFileSize uuid={uuid} />
99 name: FavoritePanelColumnNames.LAST_MODIFIED,
102 sortDirection: SortDirection.NONE,
103 filters: createTree(),
104 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
108 interface FavoritePanelDataProps {
109 favorites: FavoritesState;
112 interface FavoritePanelActionProps {
113 onItemClick: (item: string) => void;
114 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
115 onDialogOpen: (ownerUuid: string) => void;
116 onItemDoubleClick: (item: string) => void;
118 const mapStateToProps = ({ favorites }: RootState): FavoritePanelDataProps => ({
122 const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({
123 onContextMenu: (event, resourceUuid) => {
124 const kind = resourceKindToContextMenuKind(resourceUuid);
126 dispatch<any>(openContextMenu(event, {
130 kind: ResourceKind.NONE,
134 dispatch<any>(loadDetailsPanel(resourceUuid));
136 onDialogOpen: (ownerUuid: string) => { return; },
137 onItemClick: (resourceUuid: string) => {
138 dispatch<any>(loadDetailsPanel(resourceUuid));
140 onItemDoubleClick: uuid => {
141 dispatch<any>(navigateTo(uuid));
145 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
146 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
148 export const FavoritePanel = withStyles(styles)(
149 connect(mapStateToProps, mapDispatchToProps)(
150 class extends React.Component<FavoritePanelProps> {
153 id={FAVORITE_PANEL_ID}
154 onRowClick={this.props.onItemClick}
155 onRowDoubleClick={this.props.onItemDoubleClick}
156 onContextMenu={this.props.onContextMenu}
157 contextMenuColumn={true}
158 dataTableDefaultView={
159 <DataTableDefaultView
161 messages={['Your favorites list is empty.']}