1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { WithStyles } from '@mui/styles';
8 import withStyles from '@mui/styles/withStyles';
9 import { DataExplorer } from "views-components/data-explorer/data-explorer";
10 import { connect, DispatchProp } from 'react-redux';
11 import { DataColumns } from 'components/data-table/data-column';
12 import { RouteComponentProps } from 'react-router';
13 import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters';
14 import { ResourceKind } from 'models/resource';
15 import { ArvadosTheme } from 'common/custom-theme';
16 import { FAVORITE_PANEL_ID } from "store/favorite-panel/favorite-panel-action";
20 ResourceLastModifiedDate,
22 ResourceOwnerWithName,
24 } from 'views-components/data-explorer/renderers';
25 import { FavoriteIcon } from 'components/icon/icon';
28 resourceUuidToContextMenuKind
29 } from 'store/context-menu/context-menu-actions';
30 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
31 import { navigateTo } from 'store/navigation/navigation-action';
32 import { ContainerRequestState } from "models/container-request";
33 import { FavoritesState } from 'store/favorites/favorites-reducer';
34 import { RootState } from 'store/store';
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';
43 import { toggleOne, deselectAllOthers } from 'store/multiselect/multiselect-actions';
45 type CssRules = "toolbar" | "button" | "root";
47 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
49 paddingBottom: theme.spacing(3),
53 marginLeft: theme.spacing(1)
60 export enum FavoritePanelColumnNames {
65 FILE_SIZE = "File size",
66 LAST_MODIFIED = "Last modified"
69 export interface FavoritePanelFilter extends DataTableFilterItem {
70 type: ResourceKind | ContainerRequestState;
73 export const favoritePanelColumns: DataColumns<string, GroupContentsResource> = [
75 name: FavoritePanelColumnNames.NAME,
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 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>(toggleOne(uuid))
178 this.props.dispatch<any>(deselectAllOthers(uuid))
179 this.props.dispatch<any>(loadDetailsPanel(uuid));
183 return <div className={this.props.classes.root}><DataExplorer
184 id={FAVORITE_PANEL_ID}
185 onRowClick={this.handleRowClick}
186 onRowDoubleClick={this.handleRowDoubleClick}
187 onContextMenu={this.handleContextMenu}
188 contextMenuColumn={false}
189 defaultViewIcon={FavoriteIcon}
190 defaultViewMessages={['Your favorites list is empty.']} />