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-table';
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';
19 ResourceLastModifiedDate,
23 } from 'views-components/data-explorer/renderers';
24 import { PublicFavoriteIcon } from 'components/icon/icon';
25 import { Dispatch } from 'redux';
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 { RootState } from 'store/store';
34 import { createTree } from 'models/tree';
35 import { getSimpleObjectTypeFilters } from 'store/resource-type-filters/resource-type-filters';
36 import { PUBLIC_FAVORITE_PANEL_ID } from 'store/public-favorites-panel/public-favorites-action';
37 import { PublicFavoritesState } from 'store/public-favorites/public-favorites-reducer';
38 import { getResource, ResourcesState } from 'store/resources/resources';
39 import { GroupContentsResource } from 'services/groups-service/groups-service';
40 import { CollectionResource } from 'models/collection';
41 import { toggleOne, deselectAllOthers } from 'store/multiselect/multiselect-actions';
43 type CssRules = "toolbar" | "button" | "root";
45 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
47 paddingBottom: theme.spacing(3),
51 marginLeft: theme.spacing(1)
58 export enum PublicFavoritePanelColumnNames {
63 FILE_SIZE = "File size",
64 LAST_MODIFIED = "Last modified"
67 export interface FavoritePanelFilter extends DataTableFilterItem {
68 type: ResourceKind | ContainerRequestState;
71 export const publicFavoritePanelColumns: DataColumns<string, GroupContentsResource> = [
73 name: PublicFavoritePanelColumnNames.NAME,
76 filters: createTree(),
77 render: uuid => <ResourceName uuid={uuid} />
83 filters: createTree(),
84 render: uuid => <ProcessStatus uuid={uuid} />
87 name: PublicFavoritePanelColumnNames.TYPE,
90 filters: getSimpleObjectTypeFilters(),
91 render: uuid => <ResourceType uuid={uuid} />
94 name: PublicFavoritePanelColumnNames.OWNER,
97 filters: createTree(),
98 render: uuid => <ResourceOwnerWithName uuid={uuid} />
101 name: PublicFavoritePanelColumnNames.FILE_SIZE,
104 filters: createTree(),
105 render: uuid => <ResourceFileSize uuid={uuid} />
108 name: PublicFavoritePanelColumnNames.LAST_MODIFIED,
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>(toggleOne(uuid))
152 dispatch<any>(deselectAllOthers(uuid))
153 dispatch<any>(loadDetailsPanel(uuid));
155 onItemDoubleClick: uuid => {
156 dispatch<any>(navigateTo(uuid));
160 type FavoritePanelProps = PublicFavoritePanelDataProps & PublicFavoritePanelActionProps & DispatchProp
161 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
163 export const PublicFavoritePanel = withStyles(styles)(
164 connect(mapStateToProps, mapDispatchToProps)(
165 class extends React.Component<FavoritePanelProps> {
167 return <div className={this.props.classes.root}><DataExplorer
168 id={PUBLIC_FAVORITE_PANEL_ID}
169 onRowClick={this.props.onItemClick}
170 onRowDoubleClick={this.props.onItemDoubleClick}
171 onContextMenu={this.props.onContextMenu(this.props.resources)}
172 contextMenuColumn={true}
173 defaultViewIcon={PublicFavoriteIcon}
174 defaultViewMessages={['Public favorites list is empty.']} />