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, EditableResource } 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 { openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
26 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
27 import { navigateTo } from '~/store/navigation/navigation-action';
28 import { ContainerRequestState } from "~/models/container-request";
29 import { FavoritesState } from '~/store/favorites/favorites-reducer';
30 import { RootState } from '~/store/store';
31 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
32 import { createTree } from '~/models/tree';
33 import { getSimpleObjectTypeFilters } from '~/store/resource-type-filters/resource-type-filters';
34 import { getResourceWithEditableStatus, ResourcesState } from '~/store/resources/resources';
35 import { ProjectResource } from '~/models/project';
37 type CssRules = "toolbar" | "button";
39 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
41 paddingBottom: theme.spacing.unit * 3,
45 marginLeft: theme.spacing.unit
49 export enum FavoritePanelColumnNames {
54 FILE_SIZE = "File size",
55 LAST_MODIFIED = "Last modified"
58 export interface FavoritePanelFilter extends DataTableFilterItem {
59 type: ResourceKind | ContainerRequestState;
62 export const favoritePanelColumns: DataColumns<string> = [
64 name: FavoritePanelColumnNames.NAME,
67 sortDirection: SortDirection.NONE,
68 filters: createTree(),
69 render: uuid => <ResourceName uuid={uuid} />
75 filters: createTree(),
76 render: uuid => <ProcessStatus uuid={uuid} />
79 name: FavoritePanelColumnNames.TYPE,
82 filters: getSimpleObjectTypeFilters(),
83 render: uuid => <ResourceType uuid={uuid} />
86 name: FavoritePanelColumnNames.OWNER,
89 filters: createTree(),
90 render: uuid => <ResourceOwner uuid={uuid} />
93 name: FavoritePanelColumnNames.FILE_SIZE,
96 filters: createTree(),
97 render: uuid => <ResourceFileSize uuid={uuid} />
100 name: FavoritePanelColumnNames.LAST_MODIFIED,
103 sortDirection: SortDirection.DESC,
104 filters: createTree(),
105 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
109 interface FavoritePanelDataProps {
110 favorites: FavoritesState;
111 resources: ResourcesState;
116 interface FavoritePanelActionProps {
117 onItemClick: (item: string) => void;
118 onDialogOpen: (ownerUuid: string) => void;
119 onItemDoubleClick: (item: string) => void;
121 const mapStateToProps = (state : RootState): FavoritePanelDataProps => ({
122 favorites: state.favorites,
123 resources: state.resources,
124 isAdmin: state.auth.user!.isAdmin,
125 userUuid: state.auth.user!.uuid,
128 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
129 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
131 export const FavoritePanel = withStyles(styles)(
132 connect(mapStateToProps)(
133 class extends React.Component<FavoritePanelProps> {
135 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
136 const { isAdmin, userUuid, resources } = this.props;
137 const resource = getResourceWithEditableStatus<ProjectResource & EditableResource>(resourceUuid, userUuid)(resources);
138 const menuKind = resourceKindToContextMenuKind(resourceUuid, isAdmin, (resource || {} as EditableResource).isEditable);
140 this.props.dispatch<any>(openContextMenu(event, {
144 kind: ResourceKind.NONE,
148 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
151 handleRowDoubleClick = (uuid: string) => {
152 this.props.dispatch<any>(navigateTo(uuid));
155 handleRowClick = (uuid: string) => {
156 this.props.dispatch(loadDetailsPanel(uuid));
161 id={FAVORITE_PANEL_ID}
162 onRowClick={this.handleRowClick}
163 onRowDoubleClick={this.handleRowDoubleClick}
164 onContextMenu={this.handleContextMenu}
165 contextMenuColumn={true}
166 dataTableDefaultView={
167 <DataTableDefaultView
169 messages={['Your favorites list is empty.']}