1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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,
21 } from '~/views-components/data-explorer/renderers';
22 import { PublicFavoriteIcon } from '~/components/icon/icon';
23 import { Dispatch } from 'redux';
24 import { openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
25 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
26 import { navigateTo } from '~/store/navigation/navigation-action';
27 import { ContainerRequestState } from "~/models/container-request";
28 import { RootState } from '~/store/store';
29 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
30 import { createTree } from '~/models/tree';
31 import { getSimpleObjectTypeFilters } from '~/store/resource-type-filters/resource-type-filters';
32 import { PUBLIC_FAVORITE_PANEL_ID } from '~/store/public-favorites-panel/public-favorites-action';
33 import { PublicFavoritesState } from '~/store/public-favorites/public-favorites-reducer';
34 import { getIsAdmin } from '~/store/public-favorites/public-favorites-actions';
36 type CssRules = "toolbar" | "button";
38 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 paddingBottom: theme.spacing.unit * 3,
44 marginLeft: theme.spacing.unit
48 export enum PublicFavoritePanelColumnNames {
53 FILE_SIZE = "File size",
54 LAST_MODIFIED = "Last modified"
57 export interface FavoritePanelFilter extends DataTableFilterItem {
58 type: ResourceKind | ContainerRequestState;
61 export const publicFavoritePanelColumns: DataColumns<string> = [
63 name: PublicFavoritePanelColumnNames.NAME,
66 sortDirection: SortDirection.NONE,
67 filters: createTree(),
68 render: uuid => <ResourceName uuid={uuid} />
74 filters: createTree(),
75 render: uuid => <ProcessStatus uuid={uuid} />
78 name: PublicFavoritePanelColumnNames.TYPE,
81 filters: getSimpleObjectTypeFilters(),
82 render: uuid => <ResourceType uuid={uuid} />
85 name: PublicFavoritePanelColumnNames.FILE_SIZE,
88 filters: createTree(),
89 render: uuid => <ResourceFileSize uuid={uuid} />
92 name: PublicFavoritePanelColumnNames.LAST_MODIFIED,
95 sortDirection: SortDirection.DESC,
96 filters: createTree(),
97 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
101 interface PublicFavoritePanelDataProps {
102 publicFavorites: PublicFavoritesState;
105 interface PublicFavoritePanelActionProps {
106 onItemClick: (item: string) => void;
107 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
108 onDialogOpen: (ownerUuid: string) => void;
109 onItemDoubleClick: (item: string) => void;
111 const mapStateToProps = ({ publicFavorites }: RootState): PublicFavoritePanelDataProps => ({
115 const mapDispatchToProps = (dispatch: Dispatch): PublicFavoritePanelActionProps => ({
116 onContextMenu: (event, resourceUuid) => {
117 const isAdmin = dispatch<any>(getIsAdmin());
118 const kind = resourceKindToContextMenuKind(resourceUuid, isAdmin);
120 dispatch<any>(openContextMenu(event, {
124 kind: ResourceKind.NONE,
128 dispatch<any>(loadDetailsPanel(resourceUuid));
130 onDialogOpen: (ownerUuid: string) => { return; },
131 onItemClick: (uuid: string) => {
132 dispatch<any>(loadDetailsPanel(uuid));
134 onItemDoubleClick: uuid => {
135 dispatch<any>(navigateTo(uuid));
139 type FavoritePanelProps = PublicFavoritePanelDataProps & PublicFavoritePanelActionProps & DispatchProp
140 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
142 export const PublicFavoritePanel = withStyles(styles)(
143 connect(mapStateToProps, mapDispatchToProps)(
144 class extends React.Component<FavoritePanelProps> {
147 id={PUBLIC_FAVORITE_PANEL_ID}
148 onRowClick={this.props.onItemClick}
149 onRowDoubleClick={this.props.onItemDoubleClick}
150 onContextMenu={this.props.onContextMenu}
151 contextMenuColumn={true}
152 dataTableDefaultView={
153 <DataTableDefaultView
154 icon={PublicFavoriteIcon}
155 messages={['Public favorites list is empty.']} />