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";
32 type CssRules = "toolbar" | "button";
34 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
36 paddingBottom: theme.spacing.unit * 3,
40 marginLeft: theme.spacing.unit
44 export enum FavoritePanelColumnNames {
49 FILE_SIZE = "File size",
50 LAST_MODIFIED = "Last modified"
53 export interface FavoritePanelFilter extends DataTableFilterItem {
54 type: ResourceKind | ContainerRequestState;
57 export const favoritePanelColumns: DataColumns<string, FavoritePanelFilter> = [
59 name: FavoritePanelColumnNames.NAME,
62 sortDirection: SortDirection.ASC,
64 render: uuid => <ResourceName uuid={uuid} />,
71 sortDirection: SortDirection.NONE,
74 name: ContainerRequestState.COMMITTED,
76 type: ContainerRequestState.COMMITTED
79 name: ContainerRequestState.FINAL,
81 type: ContainerRequestState.FINAL
84 name: ContainerRequestState.UNCOMMITTED,
86 type: ContainerRequestState.UNCOMMITTED
89 render: uuid => <ProcessStatus uuid={uuid} />,
93 name: FavoritePanelColumnNames.TYPE,
96 sortDirection: SortDirection.NONE,
99 name: resourceLabel(ResourceKind.COLLECTION),
101 type: ResourceKind.COLLECTION
104 name: resourceLabel(ResourceKind.PROCESS),
106 type: ResourceKind.PROCESS
109 name: resourceLabel(ResourceKind.PROJECT),
111 type: ResourceKind.PROJECT
114 render: uuid => <ResourceType uuid={uuid} />,
118 name: FavoritePanelColumnNames.OWNER,
121 sortDirection: SortDirection.NONE,
123 render: uuid => <ResourceOwner uuid={uuid} />,
127 name: FavoritePanelColumnNames.FILE_SIZE,
130 sortDirection: SortDirection.NONE,
132 render: uuid => <ResourceFileSize uuid={uuid} />,
136 name: FavoritePanelColumnNames.LAST_MODIFIED,
139 sortDirection: SortDirection.NONE,
141 render: uuid => <ResourceLastModifiedDate uuid={uuid} />,
146 interface FavoritePanelDataProps {
147 currentItemId: string;
150 interface FavoritePanelActionProps {
151 onItemClick: (item: string) => void;
152 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
153 onDialogOpen: (ownerUuid: string) => void;
154 onItemDoubleClick: (item: string) => void;
157 const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({
158 onContextMenu: (event, resourceUuid) => {
159 const kind = resourceKindToContextMenuKind(resourceUuid);
161 dispatch<any>(openContextMenu(event, {
165 kind: ResourceKind.NONE,
170 onDialogOpen: (ownerUuid: string) => { return; },
171 onItemClick: (resourceUuid: string) => {
172 dispatch<any>(loadDetailsPanel(resourceUuid));
174 onItemDoubleClick: uuid => {
175 dispatch<any>(navigateTo(uuid));
179 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
180 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
182 export const FavoritePanel = withStyles(styles)(
183 connect(undefined, mapDispatchToProps)(
184 class extends React.Component<FavoritePanelProps> {
187 id={FAVORITE_PANEL_ID}
188 onRowClick={this.props.onItemClick}
189 onRowDoubleClick={this.props.onItemDoubleClick}
190 onContextMenu={this.props.onContextMenu}
191 defaultIcon={FavoriteIcon}
192 defaultMessages={['Your favorites list is empty.']}
193 contextMenuColumn={true}/>;