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';
18 ResourceLastModifiedDate,
22 } from 'views-components/data-explorer/renderers';
23 import { PublicFavoriteIcon } from 'components/icon/icon';
24 import { Dispatch } from 'redux';
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 { RootState } from 'store/store';
33 import { createTree } from 'models/tree';
34 import { getSimpleObjectTypeFilters } from 'store/resource-type-filters/resource-type-filters';
35 import { PUBLIC_FAVORITE_PANEL_ID } from 'store/public-favorites-panel/public-favorites-action';
36 import { PublicFavoritesState } from 'store/public-favorites/public-favorites-reducer';
37 import { getResource, ResourcesState } from 'store/resources/resources';
38 import { GroupContentsResource } from 'services/groups-service/groups-service';
39 import { CollectionResource } from 'models/collection';
41 type CssRules = "toolbar" | "button" | "root";
43 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
45 paddingBottom: theme.spacing.unit * 3,
49 marginLeft: theme.spacing.unit
56 export enum PublicFavoritePanelColumnNames {
61 FILE_SIZE = "File size",
62 LAST_MODIFIED = "Last modified"
65 export interface FavoritePanelFilter extends DataTableFilterItem {
66 type: ResourceKind | ContainerRequestState;
69 export const publicFavoritePanelColumns: DataColumns<string> = [
71 name: PublicFavoritePanelColumnNames.NAME,
74 sortDirection: SortDirection.NONE,
75 filters: createTree(),
76 render: uuid => <ResourceName uuid={uuid} />
82 filters: createTree(),
83 render: uuid => <ProcessStatus uuid={uuid} />
86 name: PublicFavoritePanelColumnNames.TYPE,
89 filters: getSimpleObjectTypeFilters(),
90 render: uuid => <ResourceType uuid={uuid} />
93 name: PublicFavoritePanelColumnNames.OWNER,
96 filters: createTree(),
97 render: uuid => <ResourceOwnerWithName uuid={uuid} />
100 name: PublicFavoritePanelColumnNames.FILE_SIZE,
103 filters: createTree(),
104 render: uuid => <ResourceFileSize uuid={uuid} />
107 name: PublicFavoritePanelColumnNames.LAST_MODIFIED,
110 sortDirection: SortDirection.DESC,
111 filters: createTree(),
112 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
116 interface PublicFavoritePanelDataProps {
117 publicFavorites: PublicFavoritesState;
118 resources: ResourcesState;
121 interface PublicFavoritePanelActionProps {
122 onItemClick: (item: string) => void;
123 onContextMenu: (resources: ResourcesState) => (event: React.MouseEvent<HTMLElement>, item: string) => void;
124 onDialogOpen: (ownerUuid: string) => void;
125 onItemDoubleClick: (item: string) => void;
127 const mapStateToProps = ({ publicFavorites, resources }: RootState): PublicFavoritePanelDataProps => ({
132 const mapDispatchToProps = (dispatch: Dispatch): PublicFavoritePanelActionProps => ({
133 onContextMenu: (resources: ResourcesState) => (event, resourceUuid) => {
134 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
135 const kind = dispatch<any>(resourceUuidToContextMenuKind(resourceUuid));
136 if (kind && resource) {
137 dispatch<any>(openContextMenu(event, {
139 description: resource.description,
140 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
143 kind: ResourceKind.NONE,
147 dispatch<any>(loadDetailsPanel(resourceUuid));
149 onDialogOpen: (ownerUuid: string) => { return; },
150 onItemClick: (uuid: string) => {
151 dispatch<any>(loadDetailsPanel(uuid));
153 onItemDoubleClick: uuid => {
154 dispatch<any>(navigateTo(uuid));
158 type FavoritePanelProps = PublicFavoritePanelDataProps & PublicFavoritePanelActionProps & DispatchProp
159 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
161 export const PublicFavoritePanel = withStyles(styles)(
162 connect(mapStateToProps, mapDispatchToProps)(
163 class extends React.Component<FavoritePanelProps> {
165 return <div className={this.props.classes.root}><DataExplorer
166 id={PUBLIC_FAVORITE_PANEL_ID}
167 onRowClick={this.props.onItemClick}
168 onRowDoubleClick={this.props.onItemDoubleClick}
169 onContextMenu={this.props.onContextMenu(this.props.resources)}
170 contextMenuColumn={true}
171 defaultViewIcon={PublicFavoriteIcon}
172 defaultViewMessages={['Public favorites list is empty.']} />