view-details-shows-no-data-if-trigerred-as-a-first-thing-in-a-fresh-session
[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, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
18 import { GroupResource } from '~/models/group';
19
20 type CssRules = "toolbar" | "button";
21
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23     toolbar: {
24         paddingBottom: theme.spacing.unit * 3,
25         textAlign: "right"
26     },
27     button: {
28         marginLeft: theme.spacing.unit
29     },
30 });
31
32 interface SharedWithMePanelDataProps {
33     resources: ResourcesState;
34 }
35
36 type SharedWithMePanelProps = SharedWithMePanelDataProps & DispatchProp & WithStyles<CssRules>;
37
38 export const SharedWithMePanel = withStyles(styles)(
39     connect((state: RootState) => ({
40         resources: state.resources
41     }))(
42         class extends React.Component<SharedWithMePanelProps> {
43             render() {
44                 return <DataExplorer
45                     id={SHARED_WITH_ME_PANEL_ID}
46                     onRowClick={this.handleRowClick}
47                     onRowDoubleClick={this.handleRowDoubleClick}
48                     onContextMenu={this.handleContextMenu}
49                     contextMenuColumn={false}
50                     dataTableDefaultView={<DataTableDefaultView icon={ShareMeIcon} />} />;
51             }
52
53             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
54                 const menuKind = resourceKindToContextMenuKind(resourceUuid);
55                 const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
56                 if (menuKind && 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
64                     }));
65                 }
66                 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
67             }
68
69             handleRowDoubleClick = (uuid: string) => {
70                 this.props.dispatch<any>(navigateTo(uuid));
71             }
72
73             handleRowClick = (uuid: string) => {
74                 this.props.dispatch(loadDetailsPanel(uuid));
75             }
76         }
77     )
78 );