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