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 { createTree } from 'models/tree';
35 import { getSimpleObjectTypeFilters } from 'store/resource-type-filters/resource-type-filters';
36 import { getResource, ResourcesState } from 'store/resources/resources';
37 import { GroupContentsResource } from 'services/groups-service/groups-service';
38 import { GroupClass, GroupResource } from 'models/group';
39 import { getProperty } from 'store/properties/properties';
40 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
41 import { CollectionResource } from 'models/collection';
43 type CssRules = "toolbar" | "button" | "root";
45 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
47 paddingBottom: theme.spacing.unit * 3,
51 marginLeft: theme.spacing.unit
58 export enum FavoritePanelColumnNames {
63 FILE_SIZE = "File size",
64 LAST_MODIFIED = "Last modified"
67 export interface FavoritePanelFilter extends DataTableFilterItem {
68 type: ResourceKind | ContainerRequestState;
71 export const favoritePanelColumns: DataColumns<string> = [
73 name: FavoritePanelColumnNames.NAME,
76 sortDirection: SortDirection.NONE,
77 filters: createTree(),
78 render: uuid => <ResourceName uuid={uuid} />
84 filters: createTree(),
85 render: uuid => <ProcessStatus uuid={uuid} />
88 name: FavoritePanelColumnNames.TYPE,
91 filters: getSimpleObjectTypeFilters(),
92 render: uuid => <ResourceType uuid={uuid} />
95 name: FavoritePanelColumnNames.OWNER,
98 filters: createTree(),
99 render: uuid => <ResourceOwnerWithName uuid={uuid} />
102 name: FavoritePanelColumnNames.FILE_SIZE,
105 filters: createTree(),
106 render: uuid => <ResourceFileSize uuid={uuid} />
109 name: FavoritePanelColumnNames.LAST_MODIFIED,
112 sortDirection: SortDirection.DESC,
113 filters: createTree(),
114 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
118 interface FavoritePanelDataProps {
120 favorites: FavoritesState;
121 resources: ResourcesState;
125 interface FavoritePanelActionProps {
126 onItemClick: (item: string) => void;
127 onDialogOpen: (ownerUuid: string) => void;
128 onItemDoubleClick: (item: string) => void;
130 const mapStateToProps = (state : RootState): FavoritePanelDataProps => ({
131 favorites: state.favorites,
132 resources: state.resources,
133 userUuid: state.auth.user!.uuid,
134 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
137 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
138 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
140 export const FavoritePanel = withStyles(styles)(
141 connect(mapStateToProps)(
142 class extends React.Component<FavoritePanelProps> {
144 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
145 const { resources } = this.props;
146 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
148 let readonly = false;
149 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
151 if (project && project.groupClass === GroupClass.FILTER) {
155 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
157 if (menuKind && resource) {
158 this.props.dispatch<any>(openContextMenu(event, {
161 ownerUuid: resource.ownerUuid,
162 isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
165 description: resource.description,
166 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
169 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
172 handleRowDoubleClick = (uuid: string) => {
173 this.props.dispatch<any>(navigateTo(uuid));
176 handleRowClick = (uuid: string) => {
177 this.props.dispatch<any>(loadDetailsPanel(uuid));
181 return <div className={this.props.classes.root}><DataExplorer
182 id={FAVORITE_PANEL_ID}
183 onRowClick={this.handleRowClick}
184 onRowDoubleClick={this.handleRowDoubleClick}
185 onContextMenu={this.handleContextMenu}
186 contextMenuColumn={true}
187 defaultViewIcon={FavoriteIcon}
188 defaultViewMessages={['Your favorites list is empty.']} />