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 { IconButton, Tooltip } from '@mui/material';
8 import { WithStyles } from '@mui/styles';
9 import withStyles from '@mui/styles/withStyles';
10 import { DataExplorer } from "views-components/data-explorer/data-explorer";
11 import { connect, DispatchProp } from 'react-redux';
12 import { DataColumns } from 'components/data-table/data-table';
13 import { RootState } from 'store/store';
14 import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters';
15 import { SortDirection } from 'components/data-table/data-column';
16 import { ResourceKind, TrashableResource } from 'models/resource';
17 import { ArvadosTheme } from 'common/custom-theme';
18 import { RestoreFromTrashIcon, TrashIcon } from 'components/icon/icon';
19 import { TRASH_PANEL_ID } from "store/trash-panel/trash-panel-action";
20 import { getProperty } from "store/properties/properties";
21 import { PROJECT_PANEL_CURRENT_UUID } from "store/project-panel/project-panel-action";
22 import { openContextMenu } from "store/context-menu/context-menu-actions";
23 import { getResource, ResourcesState } from "store/resources/resources";
30 } from "views-components/data-explorer/renderers";
31 import { navigateTo } from "store/navigation/navigation-action";
32 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
33 import { toggleTrashed } from "store/trash/trash-actions";
34 import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
35 import { Dispatch } from "redux";
36 import { createTree } from 'models/tree';
38 getTrashPanelTypeFilters
39 } from 'store/resource-type-filters/resource-type-filters';
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 TrashPanelColumnNames {
61 FILE_SIZE = "File size",
62 TRASHED_DATE = "Trashed date",
63 TO_BE_DELETED = "To be deleted"
66 export interface TrashPanelFilter extends DataTableFilterItem {
70 export const ResourceRestore =
71 connect((state: RootState, props: { uuid: string, dispatch?: Dispatch<any> }) => {
72 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
73 return { resource, dispatch: props.dispatch };
74 })((props: { resource?: TrashableResource, dispatch?: Dispatch<any> }) =>
75 <Tooltip title="Restore">
77 style={{ padding: '0' }}
79 if (props.resource && props.dispatch) {
80 props.dispatch(toggleTrashed(
83 props.resource.ownerUuid,
84 props.resource.isTrashed
88 <RestoreFromTrashIcon />
93 export const trashPanelColumns: DataColumns<string, CollectionResource> = [
95 name: TrashPanelColumnNames.NAME,
98 sort: {direction: SortDirection.NONE, field: "name"},
99 filters: createTree(),
100 render: uuid => <ResourceName uuid={uuid} />
103 name: TrashPanelColumnNames.TYPE,
106 filters: getTrashPanelTypeFilters(),
107 render: uuid => <ResourceType uuid={uuid} />,
110 name: TrashPanelColumnNames.FILE_SIZE,
113 sort: {direction: SortDirection.NONE, field: "fileSizeTotal"},
114 filters: createTree(),
115 render: uuid => <ResourceFileSize uuid={uuid} />
118 name: TrashPanelColumnNames.TRASHED_DATE,
121 sort: {direction: SortDirection.DESC, field: "trashAt"},
122 filters: createTree(),
123 render: uuid => <ResourceTrashDate uuid={uuid} />
126 name: TrashPanelColumnNames.TO_BE_DELETED,
129 sort: {direction: SortDirection.NONE, field: "deleteAt"},
130 filters: createTree(),
131 render: uuid => <ResourceDeleteDate uuid={uuid} />
137 filters: createTree(),
138 render: uuid => <ResourceRestore uuid={uuid} />
142 interface TrashPanelDataProps {
143 currentItemId: string;
144 resources: ResourcesState;
147 type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles<CssRules>;
149 export const TrashPanel = withStyles(styles)(
150 connect((state: RootState) => ({
151 currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
152 resources: state.resources
154 class extends React.Component<TrashPanelProps> {
156 return <div className={this.props.classes.root}><DataExplorer
158 onRowClick={this.handleRowClick}
159 onRowDoubleClick={this.handleRowDoubleClick}
160 onContextMenu={this.handleContextMenu}
161 contextMenuColumn={false}
162 defaultViewIcon={TrashIcon}
163 defaultViewMessages={['Your trash list is empty.']} />
167 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
168 const resource = getResource<TrashableResource>(resourceUuid)(this.props.resources);
170 this.props.dispatch<any>(openContextMenu(event, {
173 ownerUuid: resource.ownerUuid,
174 isTrashed: resource.isTrashed,
176 menuKind: ContextMenuKind.TRASH
179 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
182 handleRowDoubleClick = (uuid: string) => {
183 this.props.dispatch<any>(navigateTo(uuid));
186 handleRowClick = (uuid: string) => {
187 this.props.dispatch<any>(toggleOne(uuid))
188 this.props.dispatch<any>(deselectAllOthers(uuid))
189 this.props.dispatch<any>(loadDetailsPanel(uuid));