15012: Uses varargs version of joinFilters().
[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     isAdmin: boolean;
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         isAdmin: state.auth.user!.isAdmin
43     }))(
44         class extends React.Component<SharedWithMePanelProps> {
45             render() {
46                 return <DataExplorer
47                     id={SHARED_WITH_ME_PANEL_ID}
48                     onRowClick={this.handleRowClick}
49                     onRowDoubleClick={this.handleRowDoubleClick}
50                     onContextMenu={this.handleContextMenu}
51                     contextMenuColumn={false}
52                     dataTableDefaultView={<DataTableDefaultView icon={ShareMeIcon} />} />;
53             }
54
55             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
56                 const menuKind = resourceKindToContextMenuKind(resourceUuid, this.props.isAdmin);
57                 const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
58                 if (menuKind && resource) {
59                     this.props.dispatch<any>(openContextMenu(event, {
60                         name: '',
61                         uuid: resource.uuid,
62                         ownerUuid: resource.ownerUuid,
63                         isTrashed: resource.isTrashed,
64                         kind: resource.kind,
65                         menuKind
66                     }));
67                 }
68                 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
69             }
70
71             handleRowDoubleClick = (uuid: string) => {
72                 this.props.dispatch<any>(navigateTo(uuid));
73             }
74
75             handleRowClick = (uuid: string) => {
76                 this.props.dispatch(loadDetailsPanel(uuid));
77             }
78         }
79     )
80 );