1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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 { ArvadosTheme } from 'common/custom-theme';
15 import { RestoreFromTrashIcon, TrashIcon } from 'components/icon/icon';
16 import { TRASH_PANEL_ID } from "store/trash-panel/trash-panel-action";
17 import { getProperty } from "store/properties/properties";
18 import { PROJECT_PANEL_CURRENT_UUID } from "store/project-panel/project-panel-action";
19 import { openContextMenu } from "store/context-menu/context-menu-actions";
20 import { getResource, ResourcesState } from "store/resources/resources";
27 } from "views-components/data-explorer/renderers";
28 import { navigateTo } from "store/navigation/navigation-action";
29 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
30 import { toggleTrashed } from "store/trash/trash-actions";
31 import { ContextMenuKind } from "views-components/context-menu/context-menu";
32 import { Dispatch } from "redux";
33 import { createTree } from 'models/tree';
35 getTrashPanelTypeFilters
36 } from 'store/resource-type-filters/resource-type-filters';
38 type CssRules = "toolbar" | "button" | "root";
40 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 paddingBottom: theme.spacing.unit * 3,
46 marginLeft: theme.spacing.unit
53 export enum TrashPanelColumnNames {
56 FILE_SIZE = "File size",
57 TRASHED_DATE = "Trashed date",
58 TO_BE_DELETED = "To be deleted"
61 export interface TrashPanelFilter extends DataTableFilterItem {
65 export const ResourceRestore =
66 connect((state: RootState, props: { uuid: string, dispatch?: Dispatch<any> }) => {
67 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
68 return { resource, dispatch: props.dispatch };
69 })((props: { resource?: TrashableResource, dispatch?: Dispatch<any> }) =>
70 <Tooltip title="Restore">
71 <IconButton style={{ padding: '0' }} onClick={() => {
72 if (props.resource && props.dispatch) {
73 props.dispatch(toggleTrashed(
76 props.resource.ownerUuid,
77 props.resource.isTrashed
81 <RestoreFromTrashIcon />
86 export const trashPanelColumns: DataColumns<string> = [
88 name: TrashPanelColumnNames.NAME,
91 sortDirection: SortDirection.NONE,
92 filters: createTree(),
93 render: uuid => <ResourceName uuid={uuid} />
96 name: TrashPanelColumnNames.TYPE,
99 sortDirection: SortDirection.NONE,
100 filters: getTrashPanelTypeFilters(),
101 render: uuid => <ResourceType uuid={uuid} />,
104 name: TrashPanelColumnNames.FILE_SIZE,
107 sortDirection: SortDirection.NONE,
108 filters: createTree(),
109 render: uuid => <ResourceFileSize uuid={uuid} />
112 name: TrashPanelColumnNames.TRASHED_DATE,
115 sortDirection: SortDirection.DESC,
116 filters: createTree(),
117 render: uuid => <ResourceTrashDate uuid={uuid} />
120 name: TrashPanelColumnNames.TO_BE_DELETED,
123 sortDirection: SortDirection.NONE,
124 filters: createTree(),
125 render: uuid => <ResourceDeleteDate uuid={uuid} />
131 sortDirection: SortDirection.NONE,
132 filters: createTree(),
133 render: uuid => <ResourceRestore uuid={uuid} />
137 interface TrashPanelDataProps {
138 currentItemId: string;
139 resources: ResourcesState;
142 type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles<CssRules>;
144 export const TrashPanel = withStyles(styles)(
145 connect((state: RootState) => ({
146 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
147 resources: state.resources
149 class extends React.Component<TrashPanelProps> {
151 return <div className={this.props.classes.root}><DataExplorer
153 onRowClick={this.handleRowClick}
154 onRowDoubleClick={this.handleRowDoubleClick}
155 onContextMenu={this.handleContextMenu}
156 contextMenuColumn={false}
157 defaultViewIcon={TrashIcon}
158 defaultViewMessages={['Your trash list is empty.']} />
162 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
163 const resource = getResource<TrashableResource>(resourceUuid)(this.props.resources);
165 this.props.dispatch<any>(openContextMenu(event, {
168 ownerUuid: resource.ownerUuid,
169 isTrashed: resource.isTrashed,
171 menuKind: ContextMenuKind.TRASH
174 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
177 handleRowDoubleClick = (uuid: string) => {
178 this.props.dispatch<any>(navigateTo(uuid));
181 handleRowClick = (uuid: string) => {
182 this.props.dispatch<any>(loadDetailsPanel(uuid));