1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
18 resourceUuidToContextMenuKind
19 } from 'store/context-menu/context-menu-actions';
20 import { GroupContentsResource } from 'services/groups-service/groups-service';
22 type CssRules = "toolbar" | "button" | "root";
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 paddingBottom: theme.spacing.unit * 3,
30 marginLeft: theme.spacing.unit
37 interface SharedWithMePanelDataProps {
38 resources: ResourcesState;
42 type SharedWithMePanelProps = SharedWithMePanelDataProps & DispatchProp & WithStyles<CssRules>;
44 export const SharedWithMePanel = withStyles(styles)(
45 connect((state: RootState) => ({
46 resources: state.resources,
47 userUuid: state.auth.user!.uuid,
49 class extends React.Component<SharedWithMePanelProps> {
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']} />
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, {
70 description: resource.description,
71 ownerUuid: resource.ownerUuid,
72 isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
77 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
80 handleRowDoubleClick = (uuid: string) => {
81 this.props.dispatch<any>(navigateTo(uuid));
84 handleRowClick = (uuid: string) => {
85 this.props.dispatch<any>(loadDetailsPanel(uuid));