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 { 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 { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
34 import { createTree } from '~/models/tree';
36 getInitialResourceTypeFilters,
37 getTrashPanelTypeFilters
38 } from '~/store/resource-type-filters/resource-type-filters';
40 type CssRules = "toolbar" | "button";
42 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
44 paddingBottom: theme.spacing.unit * 3,
48 marginLeft: theme.spacing.unit
52 export enum TrashPanelColumnNames {
55 FILE_SIZE = "File size",
56 TRASHED_DATE = "Trashed date",
57 TO_BE_DELETED = "To be deleted"
60 export interface TrashPanelFilter extends DataTableFilterItem {
64 export const ResourceRestore =
65 connect((state: RootState, props: { uuid: string, dispatch?: Dispatch<any> }) => {
66 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
67 return { resource, dispatch: props.dispatch };
68 })((props: { resource?: TrashableResource, dispatch?: Dispatch<any> }) =>
69 <Tooltip title="Restore">
70 <IconButton style={{ padding: '0' }} onClick={() => {
71 if (props.resource && props.dispatch) {
72 props.dispatch(toggleTrashed(
75 props.resource.ownerUuid,
76 props.resource.isTrashed
80 <RestoreFromTrashIcon />
85 export const trashPanelColumns: DataColumns<string> = [
87 name: TrashPanelColumnNames.NAME,
90 sortDirection: SortDirection.NONE,
91 filters: createTree(),
92 render: uuid => <ResourceName uuid={uuid} />
95 name: TrashPanelColumnNames.TYPE,
98 sortDirection: SortDirection.NONE,
99 filters: getTrashPanelTypeFilters(),
100 render: uuid => <ResourceType uuid={uuid} />,
103 name: TrashPanelColumnNames.FILE_SIZE,
106 sortDirection: SortDirection.NONE,
107 filters: createTree(),
108 render: uuid => <ResourceFileSize uuid={uuid} />
111 name: TrashPanelColumnNames.TRASHED_DATE,
114 sortDirection: SortDirection.DESC,
115 filters: createTree(),
116 render: uuid => <ResourceTrashDate uuid={uuid} />
119 name: TrashPanelColumnNames.TO_BE_DELETED,
122 sortDirection: SortDirection.NONE,
123 filters: createTree(),
124 render: uuid => <ResourceDeleteDate uuid={uuid} />
130 sortDirection: SortDirection.NONE,
131 filters: createTree(),
132 render: uuid => <ResourceRestore uuid={uuid} />
136 interface TrashPanelDataProps {
137 currentItemId: string;
138 resources: ResourcesState;
141 type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles<CssRules>;
143 export const TrashPanel = withStyles(styles)(
144 connect((state: RootState) => ({
145 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
146 resources: state.resources
148 class extends React.Component<TrashPanelProps> {
152 onRowClick={this.handleRowClick}
153 onRowDoubleClick={this.handleRowDoubleClick}
154 onContextMenu={this.handleContextMenu}
155 contextMenuColumn={false}
156 dataTableDefaultView={
157 <DataTableDefaultView
159 messages={['Your trash list is empty.']}/>
163 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
164 const resource = getResource<TrashableResource>(resourceUuid)(this.props.resources);
166 this.props.dispatch<any>(openContextMenu(event, {
169 ownerUuid: resource.ownerUuid,
170 isTrashed: resource.isTrashed,
172 menuKind: ContextMenuKind.TRASH
175 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
178 handleRowDoubleClick = (uuid: string) => {
179 this.props.dispatch<any>(navigateTo(uuid));
182 handleRowClick = (uuid: string) => {
183 this.props.dispatch(loadDetailsPanel(uuid));