18207: Makes 'working' status work in 'Shared with me' & 'Groups' DataExplorers
[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 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 {
18     openContextMenu,
19     resourceUuidToContextMenuKind
20 } from 'store/context-menu/context-menu-actions';
21 import { GroupContentsResource } from 'services/groups-service/groups-service';
22
23 type CssRules = "toolbar" | "button" | "root";
24
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26     toolbar: {
27         paddingBottom: theme.spacing.unit * 3,
28         textAlign: "right"
29     },
30     button: {
31         marginLeft: theme.spacing.unit
32     },
33     root: {
34         width: '100%',
35     },
36 });
37
38 interface SharedWithMePanelDataProps {
39     resources: ResourcesState;
40     userUuid: string;
41 }
42
43 type SharedWithMePanelProps = SharedWithMePanelDataProps & DispatchProp & WithStyles<CssRules>;
44
45 export const SharedWithMePanel = withStyles(styles)(
46     connect((state: RootState) => ({
47         resources: state.resources,
48         userUuid: state.auth.user!.uuid,
49     }))(
50         class extends React.Component<SharedWithMePanelProps> {
51             render() {
52                 return <div className={this.props.classes.root}><DataExplorer
53                     id={SHARED_WITH_ME_PANEL_ID}
54                     onRowClick={this.handleRowClick}
55                     onRowDoubleClick={this.handleRowDoubleClick}
56                     onContextMenu={this.handleContextMenu}
57                     contextMenuColumn={false}
58                     dataTableDefaultView={
59                         <DataTableDefaultView
60                             icon={ShareMeIcon}
61                             messages={['No shared items']} />
62                     } /></div>;
63             }
64
65             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
66                 const { resources } = this.props;
67                 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
68                 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid));
69                 if (menuKind && resource) {
70                     this.props.dispatch<any>(openContextMenu(event, {
71                         name: resource.name,
72                         uuid: resource.uuid,
73                         description: resource.description,
74                         ownerUuid: resource.ownerUuid,
75                         isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
76                         kind: resource.kind,
77                         menuKind
78                     }));
79                 }
80                 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
81             }
82
83             handleRowDoubleClick = (uuid: string) => {
84                 this.props.dispatch<any>(navigateTo(uuid));
85             }
86
87             handleRowClick = (uuid: string) => {
88                 this.props.dispatch<any>(loadDetailsPanel(uuid));
89             }
90         }
91     )
92 );