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 { ResourceKind } from 'models/resource';
13 import { ArvadosTheme } from 'common/custom-theme';
14 import { FAVORITE_PANEL_ID } from "store/favorite-panel/favorite-panel-action";
18 ResourceLastModifiedDate,
20 ResourceOwnerWithName,
22 } from 'views-components/data-explorer/renderers';
23 import { FavoriteIcon } from 'components/icon/icon';
26 resourceUuidToContextMenuKind
27 } 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";
31 import { FavoritesState } from 'store/favorites/favorites-reducer';
32 import { RootState } from 'store/store';
33 import { createTree } from 'models/tree';
34 import { getSimpleObjectTypeFilters } from 'store/resource-type-filters/resource-type-filters';
35 import { getResource, ResourcesState } from 'store/resources/resources';
36 import { GroupContentsResource } from 'services/groups-service/groups-service';
37 import { GroupClass, GroupResource } from 'models/group';
38 import { getProperty } from 'store/properties/properties';
39 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
40 import { CollectionResource } from 'models/collection';
41 import { toggleOne } from 'store/multiselect/multiselect-actions';
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, GroupContentsResource> = [
73 name: FavoritePanelColumnNames.NAME,
76 filters: createTree(),
77 render: uuid => <ResourceName uuid={uuid} />
83 filters: createTree(),
84 render: uuid => <ProcessStatus uuid={uuid} />
87 name: FavoritePanelColumnNames.TYPE,
90 filters: getSimpleObjectTypeFilters(),
91 render: uuid => <ResourceType uuid={uuid} />
94 name: FavoritePanelColumnNames.OWNER,
97 filters: createTree(),
98 render: uuid => <ResourceOwnerWithName uuid={uuid} />
101 name: FavoritePanelColumnNames.FILE_SIZE,
104 filters: createTree(),
105 render: uuid => <ResourceFileSize uuid={uuid} />
108 name: FavoritePanelColumnNames.LAST_MODIFIED,
111 filters: createTree(),
112 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
116 interface FavoritePanelDataProps {
118 favorites: FavoritesState;
119 resources: ResourcesState;
123 interface FavoritePanelActionProps {
124 onItemClick: (item: string) => void;
125 onDialogOpen: (ownerUuid: string) => void;
126 onItemDoubleClick: (item: string) => void;
128 const mapStateToProps = (state : RootState): FavoritePanelDataProps => ({
129 favorites: state.favorites,
130 resources: state.resources,
131 userUuid: state.auth.user!.uuid,
132 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
135 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
136 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
138 export const FavoritePanel = withStyles(styles)(
139 connect(mapStateToProps)(
140 class extends React.Component<FavoritePanelProps> {
142 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
143 const { resources } = this.props;
144 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
146 let readonly = false;
147 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
149 if (project && project.groupClass === GroupClass.FILTER) {
153 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
155 if (menuKind && resource) {
156 this.props.dispatch<any>(openContextMenu(event, {
159 ownerUuid: resource.ownerUuid,
160 isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
163 description: resource.description,
164 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
167 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
170 handleRowDoubleClick = (uuid: string) => {
171 this.props.dispatch<any>(navigateTo(uuid));
174 handleRowClick = (uuid: string) => {
175 this.props.dispatch<any>(toggleOne(uuid))
176 this.props.dispatch<any>(loadDetailsPanel(uuid));
180 return <div className={this.props.classes.root}><DataExplorer
181 id={FAVORITE_PANEL_ID}
182 onRowClick={this.handleRowClick}
183 onRowDoubleClick={this.handleRowDoubleClick}
184 onContextMenu={this.handleContextMenu}
185 contextMenuColumn={true}
186 defaultViewIcon={FavoriteIcon}
187 defaultViewMessages={['Your favorites list is empty.']} />