1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { IconButton, StyleRulesCallback, WithStyles, withStyles, Tooltip } 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 { RootState } from '~/store/store';
11 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
12 import { SortDirection } from '~/components/data-table/data-column';
13 import { ResourceKind, TrashableResource } from '~/models/resource';
14 import { resourceLabel } from '~/common/labels';
15 import { ArvadosTheme } from '~/common/custom-theme';
16 import { RestoreFromTrashIcon, TrashIcon } from '~/components/icon/icon';
17 import { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
18 import { getProperty } from "~/store/properties/properties";
19 import { PROJECT_PANEL_CURRENT_UUID } from "~/store/project-panel/project-panel-action";
20 import { openContextMenu } from "~/store/context-menu/context-menu-actions";
21 import { getResource, ResourcesState } from "~/store/resources/resources";
28 } from "~/views-components/data-explorer/renderers";
29 import { navigateTo } from "~/store/navigation/navigation-action";
30 import { loadDetailsPanel } from "~/store/details-panel/details-panel-action";
31 import { toggleTrashed } from "~/store/trash/trash-actions";
32 import { ContextMenuKind } from "~/views-components/context-menu/context-menu";
33 import { Dispatch } from "redux";
34 import { PanelDefaultView } from '~/components/panel-default-view/panel-default-view';
35 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
37 type CssRules = "toolbar" | "button";
39 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
41 paddingBottom: theme.spacing.unit * 3,
45 marginLeft: theme.spacing.unit
49 export enum TrashPanelColumnNames {
52 FILE_SIZE = "File size",
53 TRASHED_DATE = "Trashed date",
54 TO_BE_DELETED = "To be deleted"
57 export interface TrashPanelFilter extends DataTableFilterItem {
61 export const ResourceRestore =
62 connect((state: RootState, props: { uuid: string, dispatch?: Dispatch<any> }) => {
63 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
64 return { resource, dispatch: props.dispatch };
65 })((props: { resource?: TrashableResource, dispatch?: Dispatch<any> }) =>
66 <Tooltip title="Restore">
67 <IconButton onClick={() => {
68 if (props.resource && props.dispatch) {
69 props.dispatch(toggleTrashed(
72 props.resource.ownerUuid,
73 props.resource.isTrashed
77 <RestoreFromTrashIcon />
82 export const trashPanelColumns: DataColumns<string, TrashPanelFilter> = [
84 name: TrashPanelColumnNames.NAME,
87 sortDirection: SortDirection.ASC,
89 render: uuid => <ResourceName uuid={uuid} />
92 name: TrashPanelColumnNames.TYPE,
95 sortDirection: SortDirection.NONE,
98 name: resourceLabel(ResourceKind.COLLECTION),
100 type: ResourceKind.COLLECTION
103 name: resourceLabel(ResourceKind.PROJECT),
105 type: ResourceKind.PROJECT
108 render: uuid => <ResourceType uuid={uuid} />,
111 name: TrashPanelColumnNames.FILE_SIZE,
114 sortDirection: SortDirection.NONE,
116 render: uuid => <ResourceFileSize uuid={uuid} />
119 name: TrashPanelColumnNames.TRASHED_DATE,
122 sortDirection: SortDirection.NONE,
124 render: uuid => <ResourceTrashDate uuid={uuid} />
127 name: TrashPanelColumnNames.TO_BE_DELETED,
130 sortDirection: SortDirection.NONE,
132 render: uuid => <ResourceDeleteDate uuid={uuid} />
138 sortDirection: SortDirection.NONE,
140 render: uuid => <ResourceRestore uuid={uuid} />
144 interface TrashPanelDataProps {
145 currentItemId: string;
146 resources: ResourcesState;
149 type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles<CssRules>;
151 export const TrashPanel = withStyles(styles)(
152 connect((state: RootState) => ({
153 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
154 resources: state.resources
156 class extends React.Component<TrashPanelProps> {
160 onRowClick={this.handleRowClick}
161 onRowDoubleClick={this.handleRowDoubleClick}
162 onContextMenu={this.handleContextMenu}
163 contextMenuColumn={false}
164 dataTableDefaultView={
165 <DataTableDefaultView
167 messages={['Your trash list is empty.']}/>
171 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
172 const resource = getResource<TrashableResource>(resourceUuid)(this.props.resources);
174 this.props.dispatch<any>(openContextMenu(event, {
177 ownerUuid: resource.ownerUuid,
178 isTrashed: resource.isTrashed,
180 menuKind: ContextMenuKind.TRASH
183 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
186 handleRowDoubleClick = (uuid: string) => {
187 this.props.dispatch<any>(navigateTo(uuid));
190 handleRowClick = (uuid: string) => {
191 this.props.dispatch(loadDetailsPanel(uuid));