X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f1065fb7260dd562ea2e826e9cbc508d7932ecca..1ef4bffbfa4d05ae4356ef22b3964d6152310fb9:/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 fa73c0b0..d303c2f7 100644
--- a/src/views/trash-panel/trash-panel.tsx
+++ b/src/views/trash-panel/trash-panel.tsx
@@ -2,24 +2,41 @@
 //
 // 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 { DataExplorer } from "~/views-components/data-explorer/data-explorer";
-import { DispatchProp, connect } 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 { 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 { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
+import React from 'react';
+import { IconButton, StyleRulesCallback, WithStyles, withStyles, Tooltip } from '@material-ui/core';
+import { DataExplorer } from "views-components/data-explorer/data-explorer";
+import { connect, DispatchProp } from 'react-redux';
+import { DataColumns } from 'components/data-table/data-table';
+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, TrashableResource } from 'models/resource';
+import { ArvadosTheme } from 'common/custom-theme';
+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 } 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 { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
+import { createTree } from 'models/tree';
+import {
+    getTrashPanelTypeFilters
+} from 'store/resource-type-filters/resource-type-filters';
 
-type CssRules = "toolbar" | "button";
+type CssRules = "toolbar" | "button" | "root";
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     toolbar: {
@@ -29,6 +46,9 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     button: {
         marginLeft: theme.spacing.unit
     },
+    root: {
+        width: '100%',
+    },
 });
 
 export enum TrashPanelColumnNames {
@@ -43,105 +63,126 @@ export interface TrashPanelFilter extends DataTableFilterItem {
     type: ResourceKind;
 }
 
-export const columns: 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> }) =>
+        <Tooltip title="Restore">
+            <IconButton style={{ padding: '0' }} onClick={() => {
+                if (props.resource && props.dispatch) {
+                    props.dispatch(toggleTrashed(
+                        props.resource.kind,
+                        props.resource.uuid,
+                        props.resource.ownerUuid,
+                        props.resource.isTrashed
+                    ));
+                }}}
+            >
+                <RestoreFromTrashIcon />
+            </IconButton>
+        </Tooltip>
+    );
+
+export const trashPanelColumns: DataColumns<string> = [
     {
         name: TrashPanelColumnNames.NAME,
         selected: true,
         configurable: true,
-        sortDirection: SortDirection.ASC,
-        filters: [],
-        render: renderName,
-        width: "450px"
+        sortDirection: SortDirection.NONE,
+        filters: createTree(),
+        render: uuid => <ResourceName uuid={uuid} />
     },
     {
         name: TrashPanelColumnNames.TYPE,
         selected: true,
         configurable: true,
         sortDirection: SortDirection.NONE,
-        filters: [
-            {
-                name: resourceLabel(ResourceKind.COLLECTION),
-                selected: true,
-                type: ResourceKind.COLLECTION
-            },
-            {
-                name: resourceLabel(ResourceKind.PROCESS),
-                selected: true,
-                type: ResourceKind.PROCESS
-            },
-            {
-                name: resourceLabel(ResourceKind.PROJECT),
-                selected: true,
-                type: ResourceKind.PROJECT
-            }
-        ],
-        render: item => renderType(item.kind),
-        width: "125px"
+        filters: getTrashPanelTypeFilters(),
+        render: uuid => <ResourceType uuid={uuid} />,
     },
     {
         name: TrashPanelColumnNames.FILE_SIZE,
         selected: true,
         configurable: true,
         sortDirection: SortDirection.NONE,
-        filters: [],
-        render: item => renderFileSize(item.fileSize),
-        width: "50px"
+        filters: createTree(),
+        render: uuid => <ResourceFileSize uuid={uuid} />
     },
     {
         name: TrashPanelColumnNames.TRASHED_DATE,
         selected: true,
         configurable: true,
-        sortDirection: SortDirection.NONE,
-        filters: [],
-        render: item => renderDate(item.trashAt),
-        width: "50px"
+        sortDirection: SortDirection.DESC,
+        filters: createTree(),
+        render: uuid => <ResourceTrashDate uuid={uuid} />
     },
     {
         name: TrashPanelColumnNames.TO_BE_DELETED,
         selected: true,
         configurable: true,
         sortDirection: SortDirection.NONE,
-        filters: [],
-        render: item => renderDate(item.deleteAt),
-        width: "50px"
+        filters: createTree(),
+        render: uuid => <ResourceDeleteDate uuid={uuid} />
     },
+    {
+        name: '',
+        selected: true,
+        configurable: false,
+        sortDirection: SortDirection.NONE,
+        filters: createTree(),
+        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> & RouteComponentProps<{ id: string }>;
+type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles<CssRules>;
 
 export const TrashPanel = withStyles(styles)(
-    connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
+    connect((state: RootState) => ({
+        currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
+        resources: state.resources
+    }))(
         class extends React.Component<TrashPanelProps> {
             render() {
-                return <DataExplorer
+                return <div className={this.props.classes.root}><DataExplorer
                     id={TRASH_PANEL_ID}
-                    columns={columns}
-                    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.']}/>
-                ;
+                    onRowClick={this.handleRowClick}
+                    onRowDoubleClick={this.handleRowDoubleClick}
+                    onContextMenu={this.handleContextMenu}
+                    contextMenuColumn={false}
+                    dataTableDefaultView={
+                        <DataTableDefaultView
+                            icon={TrashIcon}
+                            messages={['Your trash list is empty.']}/>
+                    } /></div>;
             }
 
-            componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: TrashPanelProps) {
-                if (match.params.id !== currentItemId) {
-                    onItemRouteChange(match.params.id);
+            handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
+                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
+                    }));
                 }
+                this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
+            }
+
+            handleRowDoubleClick = (uuid: string) => {
+                this.props.dispatch<any>(navigateTo(uuid));
+            }
+
+            handleRowClick = (uuid: string) => {
+                this.props.dispatch<any>(loadDetailsPanel(uuid));
             }
         }
     )
