17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / views / shared-with-me-panel / shared-with-me-panel.tsx
index 5d782f5d11870dcb8b60e1dac9bd97608989f102..1c47e4375a1bfe5e9f12cebac4e5712675f132b6 100644 (file)
@@ -2,19 +2,23 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import React from 'react';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
-import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
+import { DataExplorer } from "views-components/data-explorer/data-explorer";
 import { connect, DispatchProp } from 'react-redux';
-import { RootState } from '~/store/store';
-import { ArvadosTheme } from '~/common/custom-theme';
-import { ShareMeIcon } from '~/components/icon/icon';
-import { ResourcesState } from "~/store/resources/resources";
-import { navigateTo } from "~/store/navigation/navigation-action";
-import { loadDetailsPanel } from "~/store/details-panel/details-panel-action";
-import { PanelDefaultView } from '~/components/panel-default-view/panel-default-view';
-import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
-import { SHARED_WITH_ME_PANEL_ID } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
+import { RootState } from 'store/store';
+import { ArvadosTheme } from 'common/custom-theme';
+import { ShareMeIcon } from 'components/icon/icon';
+import { ResourcesState, getResource } from 'store/resources/resources';
+import { navigateTo } from "store/navigation/navigation-action";
+import { loadDetailsPanel } from "store/details-panel/details-panel-action";
+import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
+import { SHARED_WITH_ME_PANEL_ID } from 'store/shared-with-me-panel/shared-with-me-panel-actions';
+import {
+    openContextMenu,
+    resourceUuidToContextMenuKind
+} from 'store/context-menu/context-menu-actions';
+import { GroupContentsResource } from 'services/groups-service/groups-service';
 
 type CssRules = "toolbar" | "button";
 
@@ -30,47 +34,42 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 interface SharedWithMePanelDataProps {
     resources: ResourcesState;
+    userUuid: string;
 }
 
 type SharedWithMePanelProps = SharedWithMePanelDataProps & DispatchProp & WithStyles<CssRules>;
 
 export const SharedWithMePanel = withStyles(styles)(
     connect((state: RootState) => ({
-        resources: state.resources
+        resources: state.resources,
+        userUuid: state.auth.user!.uuid,
     }))(
         class extends React.Component<SharedWithMePanelProps> {
             render() {
-                return this.hasAnyTrashedResources()
-                    ? <DataExplorer
-                        id={SHARED_WITH_ME_PANEL_ID}
-                        onRowClick={this.handleRowClick}
-                        onRowDoubleClick={this.handleRowDoubleClick}
-                        onContextMenu={this.handleContextMenu}
-                        contextMenuColumn={false}
-                        dataTableDefaultView={<DataTableDefaultView icon={ShareMeIcon} />} />
-                    : <PanelDefaultView
-                        icon={ShareMeIcon}
-                        messages={['No shared items.']} />;
-            }
-
-            hasAnyTrashedResources = () => {
-                // TODO: implement check if there is anything in the trash,
-                //       without taking pagination into the account
-                return true;
+                return <DataExplorer
+                    id={SHARED_WITH_ME_PANEL_ID}
+                    onRowClick={this.handleRowClick}
+                    onRowDoubleClick={this.handleRowDoubleClick}
+                    onContextMenu={this.handleContextMenu}
+                    contextMenuColumn={false}
+                    dataTableDefaultView={<DataTableDefaultView icon={ShareMeIcon} />} />;
             }
 
             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
-                //     }));
-                // }
+                const { resources } = this.props;
+                const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
+                const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid));
+                if (menuKind && resource) {
+                    this.props.dispatch<any>(openContextMenu(event, {
+                        name: '',
+                        uuid: resource.uuid,
+                        ownerUuid: resource.ownerUuid,
+                        isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
+                        kind: resource.kind,
+                        menuKind
+                    }));
+                }
+                this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
             }
 
             handleRowDoubleClick = (uuid: string) => {
@@ -78,7 +77,7 @@ export const SharedWithMePanel = withStyles(styles)(
             }
 
             handleRowClick = (uuid: string) => {
-                this.props.dispatch(loadDetailsPanel(uuid));
+                this.props.dispatch<any>(loadDetailsPanel(uuid));
             }
         }
     )