X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/1baec2d74e64375ce1b410f6a66fc8c8c9848307..de7204ffbb7255e0aa9cefb7efd06f5130b19038:/src/views/trash-panel/trash-panel.tsx

diff --git a/src/views/trash-panel/trash-panel.tsx b/src/views/trash-panel/trash-panel.tsx
index 3c25a3e1..4a1e197d 100644
--- a/src/views/trash-panel/trash-panel.tsx
+++ b/src/views/trash-panel/trash-panel.tsx
@@ -3,24 +3,36 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { TrashPanelItem } from './trash-panel-item';
-import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
+import { IconButton, StyleRulesCallback, WithStyles, withStyles, Tooltip } from '@material-ui/core';
 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
-import { DispatchProp, connect } from 'react-redux';
+import { connect, DispatchProp } from 'react-redux';
 import { DataColumns } from '~/components/data-table/data-table';
-import { RouteComponentProps } from 'react-router';
 import { RootState } from '~/store/store';
 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
 import { SortDirection } from '~/components/data-table/data-column';
-import { ResourceKind } from '~/models/resource';
+import { ResourceKind, TrashableResource } from '~/models/resource';
 import { resourceLabel } from '~/common/labels';
 import { ArvadosTheme } from '~/common/custom-theme';
-import { renderName, renderType, renderFileSize, renderDate } from '~/views-components/data-explorer/renderers';
-import { TrashIcon } from '~/components/icon/icon';
+import { RestoreFromTrashIcon, TrashIcon } from '~/components/icon/icon';
 import { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
 import { getProperty } from "~/store/properties/properties";
 import { PROJECT_PANEL_CURRENT_UUID } from "~/store/project-panel/project-panel-action";
-import { openContextMenu, resourceKindToContextMenuKind } from "~/store/context-menu/context-menu-actions";
+import { openContextMenu } from "~/store/context-menu/context-menu-actions";
+import { getResource, ResourcesState } from "~/store/resources/resources";
+import {
+    ResourceDeleteDate,
+    ResourceFileSize,
+    ResourceName,
+    ResourceTrashDate,
+    ResourceType
+} from "~/views-components/data-explorer/renderers";
+import { navigateTo } from "~/store/navigation/navigation-action";
+import { loadDetailsPanel } from "~/store/details-panel/details-panel-action";
+import { toggleTrashed } from "~/store/trash/trash-actions";
+import { ContextMenuKind } from "~/views-components/context-menu/context-menu";
+import { Dispatch } from "redux";
+import { PanelDefaultView } from '~/components/panel-default-view/panel-default-view';
+import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
 
 type CssRules = "toolbar" | "button";
 
@@ -46,15 +58,35 @@ export interface TrashPanelFilter extends DataTableFilterItem {
     type: ResourceKind;
 }
 
-export const trashPanelColumns: DataColumns<TrashPanelItem, TrashPanelFilter> = [
+export const ResourceRestore =
+    connect((state: RootState, props: { uuid: string, dispatch?: Dispatch<any> }) => {
+        const resource = getResource<TrashableResource>(props.uuid)(state.resources);
+        return { resource, dispatch: props.dispatch };
+    })((props: { resource?: TrashableResource, dispatch?: Dispatch<any> }) =>
+        <IconButton onClick={() => {
+            if (props.resource && props.dispatch) {
+                props.dispatch(toggleTrashed(
+                    props.resource.kind,
+                    props.resource.uuid,
+                    props.resource.ownerUuid,
+                    props.resource.isTrashed
+                ));
+            }
+        }}>
+            <Tooltip title="Restore">
+                <RestoreFromTrashIcon />
+            </Tooltip>
+        </IconButton>
+    );
+
+export const trashPanelColumns: DataColumns<string, TrashPanelFilter> = [
     {
         name: TrashPanelColumnNames.NAME,
         selected: true,
         configurable: true,
         sortDirection: SortDirection.ASC,
         filters: [],
-        render: renderName,
-        width: "450px"
+        render: uuid => <ResourceName uuid={uuid} />
     },
     {
         name: TrashPanelColumnNames.TYPE,
@@ -78,8 +110,7 @@ export const trashPanelColumns: DataColumns<TrashPanelItem, TrashPanelFilter> =
                 type: ResourceKind.PROJECT
             }
         ],
-        render: item => renderType(item.kind),
-        width: "125px"
+        render: uuid => <ResourceType uuid={uuid} />,
     },
     {
         name: TrashPanelColumnNames.FILE_SIZE,
@@ -87,8 +118,7 @@ export const trashPanelColumns: DataColumns<TrashPanelItem, TrashPanelFilter> =
         configurable: true,
         sortDirection: SortDirection.NONE,
         filters: [],
-        render: item => renderFileSize(item.fileSize),
-        width: "50px"
+        render: uuid => <ResourceFileSize uuid={uuid} />
     },
     {
         name: TrashPanelColumnNames.TRASHED_DATE,
@@ -96,8 +126,7 @@ export const trashPanelColumns: DataColumns<TrashPanelItem, TrashPanelFilter> =
         configurable: true,
         sortDirection: SortDirection.NONE,
         filters: [],
-        render: item => renderDate(item.trashAt),
-        width: "50px"
+        render: uuid => <ResourceTrashDate uuid={uuid} />
     },
     {
         name: TrashPanelColumnNames.TO_BE_DELETED,
@@ -105,24 +134,24 @@ export const trashPanelColumns: DataColumns<TrashPanelItem, TrashPanelFilter> =
         configurable: true,
         sortDirection: SortDirection.NONE,
         filters: [],
-        render: item => renderDate(item.deleteAt),
-        width: "50px"
+        render: uuid => <ResourceDeleteDate uuid={uuid} />
     },
+    {
+        name: '',
+        selected: true,
+        configurable: false,
+        sortDirection: SortDirection.NONE,
+        filters: [],
+        render: uuid => <ResourceRestore uuid={uuid} />
+    }
 ];
 
 interface TrashPanelDataProps {
     currentItemId: string;
+    resources: ResourcesState;
 }
 
-interface TrashPanelActionProps {
-    onItemClick: (item: TrashPanelItem) => void;
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: TrashPanelItem) => void;
-    onDialogOpen: (ownerUuid: string) => void;
-    onItemDoubleClick: (item: TrashPanelItem) => void;
-    onItemRouteChange: (itemId: string) => void;
-}
-
-type TrashPanelProps = TrashPanelDataProps & TrashPanelActionProps & DispatchProp & WithStyles<CssRules>;
+type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles<CssRules>;
 
 export const TrashPanel = withStyles(styles)(
     connect((state: RootState) => ({
@@ -131,23 +160,46 @@ export const TrashPanel = withStyles(styles)(
     }))(
         class extends React.Component<TrashPanelProps> {
             render() {
-                return <DataExplorer
-                    id={TRASH_PANEL_ID}
-                    onRowClick={this.props.onItemClick}
-                    onRowDoubleClick={this.props.onItemDoubleClick}
-                    onContextMenu={this.props.onContextMenu}
-                    extractKey={(item: TrashPanelItem) => item.uuid}
-                    defaultIcon={TrashIcon}
-                    defaultMessages={['Your trash list is empty.']}/>
-                ;
+                return this.hasAnyTrashedResources()
+                    ? <DataExplorer
+                        id={TRASH_PANEL_ID}
+                        onRowClick={this.handleRowClick}
+                        onRowDoubleClick={this.handleRowDoubleClick}
+                        onContextMenu={this.handleContextMenu}
+                        contextMenuColumn={false}
+                        dataTableDefaultView={<DataTableDefaultView icon={TrashIcon} />} />
+                    : <PanelDefaultView
+                        icon={TrashIcon}
+                        messages={['Your trash list is empty.']} />;
+            }
+
+            hasAnyTrashedResources = () => {
+                // TODO: implement check if there is anything in the trash,
+                //       without taking pagination into the account
+                return true;
             }
 
             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
-                const kind = resourceKindToContextMenuKind(resourceUuid);
-                if (kind) {
-                    this.props.dispatch<any>(openContextMenu(event, { name: '', uuid: resourceUuid, kind }));
+                const resource = getResource<TrashableResource>(resourceUuid)(this.props.resources);
+                if (resource) {
+                    this.props.dispatch<any>(openContextMenu(event, {
+                        name: '',
+                        uuid: resource.uuid,
+                        ownerUuid: resource.ownerUuid,
+                        isTrashed: resource.isTrashed,
+                        kind: resource.kind,
+                        menuKind: ContextMenuKind.TRASH
+                    }));
                 }
             }
+
+            handleRowDoubleClick = (uuid: string) => {
+                this.props.dispatch<any>(navigateTo(uuid));
+            }
+
+            handleRowClick = (uuid: string) => {
+                this.props.dispatch(loadDetailsPanel(uuid));
+            }
         }
     )
 );
