1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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,
21 ResourceOwnerWithName,
23 } from 'views-components/data-explorer/renderers';
24 import { FavoriteIcon } from 'components/icon/icon';
27 resourceUuidToContextMenuKind
28 } from 'store/context-menu/context-menu-actions';
29 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
30 import { navigateTo } from 'store/navigation/navigation-action';
31 import { ContainerRequestState } from "models/container-request";
32 import { FavoritesState } from 'store/favorites/favorites-reducer';
33 import { RootState } from 'store/store';
34 import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
35 import { createTree } from 'models/tree';
36 import { getSimpleObjectTypeFilters } from 'store/resource-type-filters/resource-type-filters';
37 import { getResource, ResourcesState } from 'store/resources/resources';
38 import { GroupContentsResource } from 'services/groups-service/groups-service';
39 import { GroupClass, GroupResource } from 'models/group';
40 import { getProperty } from 'store/properties/properties';
41 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
42 import { CollectionResource } from 'models/collection';
44 type CssRules = "toolbar" | "button" | "root";
46 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
48 paddingBottom: theme.spacing.unit * 3,
52 marginLeft: theme.spacing.unit
59 export enum FavoritePanelColumnNames {
64 FILE_SIZE = "File size",
65 LAST_MODIFIED = "Last modified"
68 export interface FavoritePanelFilter extends DataTableFilterItem {
69 type: ResourceKind | ContainerRequestState;
72 export const favoritePanelColumns: DataColumns<string> = [
74 name: FavoritePanelColumnNames.NAME,
77 sortDirection: SortDirection.NONE,
78 filters: createTree(),
79 render: uuid => <ResourceName uuid={uuid} />
85 filters: createTree(),
86 render: uuid => <ProcessStatus uuid={uuid} />
89 name: FavoritePanelColumnNames.TYPE,
92 filters: getSimpleObjectTypeFilters(),
93 render: uuid => <ResourceType uuid={uuid} />
96 name: FavoritePanelColumnNames.OWNER,
99 filters: createTree(),
100 render: uuid => <ResourceOwnerWithName uuid={uuid} />
103 name: FavoritePanelColumnNames.FILE_SIZE,
106 filters: createTree(),
107 render: uuid => <ResourceFileSize uuid={uuid} />
110 name: FavoritePanelColumnNames.LAST_MODIFIED,
113 sortDirection: SortDirection.DESC,
114 filters: createTree(),
115 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
119 interface FavoritePanelDataProps {
121 favorites: FavoritesState;
122 resources: ResourcesState;
126 interface FavoritePanelActionProps {
127 onItemClick: (item: string) => void;
128 onDialogOpen: (ownerUuid: string) => void;
129 onItemDoubleClick: (item: string) => void;
131 const mapStateToProps = (state : RootState): FavoritePanelDataProps => ({
132 favorites: state.favorites,
133 resources: state.resources,
134 userUuid: state.auth.user!.uuid,
135 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
138 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
139 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
141 export const FavoritePanel = withStyles(styles)(
142 connect(mapStateToProps)(
143 class extends React.Component<FavoritePanelProps> {
145 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
146 const { resources } = this.props;
147 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
149 let readonly = false;
150 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
152 if (project && project.groupClass === GroupClass.FILTER) {
156 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
158 if (menuKind && resource) {
159 this.props.dispatch<any>(openContextMenu(event, {
162 ownerUuid: resource.ownerUuid,
163 isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
166 description: resource.description,
167 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
170 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
173 handleRowDoubleClick = (uuid: string) => {
174 this.props.dispatch<any>(navigateTo(uuid));
177 handleRowClick = (uuid: string) => {
178 this.props.dispatch<any>(loadDetailsPanel(uuid));
182 return <div className={this.props.classes.root}><DataExplorer
183 id={FAVORITE_PANEL_ID}
184 onRowClick={this.handleRowClick}
185 onRowDoubleClick={this.handleRowDoubleClick}
186 onContextMenu={this.handleContextMenu}
187 contextMenuColumn={true}
188 dataTableDefaultView={
189 <DataTableDefaultView
191 messages={['Your favorites list is empty.']}