Mergeg branch 'master'
[arvados-workbench2.git] / src / views / shared-with-me-panel / shared-with-me-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
7 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
8 import { connect, DispatchProp } from 'react-redux';
9 import { RootState } from '~/store/store';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { ShareMeIcon } from '~/components/icon/icon';
12 import { ResourcesState, getResource } from '~/store/resources/resources';
13 import { navigateTo } from "~/store/navigation/navigation-action";
14 import { loadDetailsPanel } from "~/store/details-panel/details-panel-action";
15 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
16 import { SHARED_WITH_ME_PANEL_ID } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
17 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
18 import { GroupResource } from '~/models/group';
19 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
20
21 type CssRules = "toolbar" | "button";
22
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24     toolbar: {
25         paddingBottom: theme.spacing.unit * 3,
26         textAlign: "right"
27     },
28     button: {
29         marginLeft: theme.spacing.unit
30     },
31 });
32
33 interface SharedWithMePanelDataProps {
34     resources: ResourcesState;
35 }
36
37 type SharedWithMePanelProps = SharedWithMePanelDataProps & DispatchProp & WithStyles<CssRules>;
38
39 export const SharedWithMePanel = withStyles(styles)(
40     connect((state: RootState) => ({
41         resources: state.resources
42     }))(
43         class extends React.Component<SharedWithMePanelProps> {
44             render() {
45                 return <DataExplorer
46                     id={SHARED_WITH_ME_PANEL_ID}
47                     onRowClick={this.handleRowClick}
48                     onRowDoubleClick={this.handleRowDoubleClick}
49                     onContextMenu={this.handleContextMenu}
50                     contextMenuColumn={false}
51                     dataTableDefaultView={<DataTableDefaultView icon={ShareMeIcon} />} />;
52             }
53
54             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
55                 const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
56                 if (resource) {
57                     this.props.dispatch<any>(openContextMenu(event, {
58                         name: '',
59                         uuid: resource.uuid,
60                         ownerUuid: resource.ownerUuid,
61                         isTrashed: resource.isTrashed,
62                         kind: resource.kind,
63                         menuKind: ContextMenuKind.PROJECT,
64                     }));
65                 }
66             }
67
68             handleRowDoubleClick = (uuid: string) => {
69                 this.props.dispatch<any>(navigateTo(uuid));
70             }
71
72             handleRowClick = (uuid: string) => {
73                 this.props.dispatch(loadDetailsPanel(uuid));
74             }
75         }
76     )
77 );