]> git.arvados.org - arvados.git/blob - services/workbench2/src/views/project-panel/project-panel.tsx
Merge branch 'main' into 21720-material-ui-upgrade
[arvados.git] / services / workbench2 / src / views / project-panel / project-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 withStyles from '@mui/styles/withStyles';
7 import { DispatchProp, connect } from 'react-redux';
8 import { RouteComponentProps } from 'react-router';
9 import { WithStyles } from '@mui/styles';
10 import { CustomStyleRulesCallback } from 'common/custom-theme';
11 import { RootState } from 'store/store';
12 import { Resource } from 'models/resource';
13 import { ResourcesState, getResource } from 'store/resources/resources';
14 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
15 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
16 import { navigateTo } from 'store/navigation/navigation-action';
17 import { getProperty } from 'store/properties/properties';
18 import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
19 import { ArvadosTheme } from 'common/custom-theme';
20 import { GroupContentsResource } from 'services/groups-service/groups-service';
21 import { GroupClass, GroupResource } from 'models/group';
22 import { CollectionResource } from 'models/collection';
23 import { resourceIsFrozen } from 'common/frozen-resources';
24 import { deselectAllOthers, toggleOne } from 'store/multiselect/multiselect-actions';
25 import { DetailsCardRoot } from 'views-components/details-card/details-card-root';
26 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
27 import { ProjectPanelData } from './project-panel-data';
28 import { ProjectPanelRun } from './project-panel-run';
29
30 type CssRules = 'root' | 'button' | 'mpvRoot' | 'dataExplorer';
31
32 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33     root: {
34         width: '100%',
35         display: 'flex',
36         flexDirection: 'column',
37     },
38     button: {
39         marginLeft: theme.spacing(1),
40     },
41     mpvRoot: {
42         flexGrow: 1,
43         display: 'flex',
44         flexDirection: 'column',
45         '& > div': {
46             height: '100%',
47         },
48     },
49     dataExplorer: {
50         height: "100%",
51     },
52 });
53
54 const panelsData: MPVPanelState[] = [
55     { name: "Data", visible: true },
56     { name: "Workflow Runs", visible: false },
57 ];
58
59 interface ProjectPanelDataProps {
60     currentItemId: string;
61     resources: ResourcesState;
62     project: GroupResource;
63     isAdmin: boolean;
64     userUuid: string;
65     dataExplorerItems: any;
66     working: boolean;
67 }
68
69 type ProjectPanelProps = ProjectPanelDataProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
70
71 const mapStateToProps = (state: RootState) => {
72     const currentItemId = getProperty<string>(PROJECT_PANEL_CURRENT_UUID)(state.properties);
73     const project = getResource<GroupResource>(currentItemId || "")(state.resources);
74     return {
75         currentItemId,
76         project,
77         resources: state.resources,
78         userUuid: state.auth.user!.uuid,
79     };
80 }
81
82 export const ProjectPanel = withStyles(styles)(
83     connect(mapStateToProps)(
84         class extends React.Component<ProjectPanelProps> {
85
86             render() {
87                 const { classes } = this.props;
88                 return <div data-cy='project-panel' className={classes.root}>
89                     <DetailsCardRoot />
90                     <MPVContainer
91                         className={classes.mpvRoot}
92                         spacing={8}
93                         panelStates={panelsData}
94                         mutuallyExclusive
95                         justify-content="flex-start"
96                         direction="column"
97                         wrap="nowrap">
98                         <MPVPanelContent
99                             forwardProps
100                             xs="auto"
101                             data-cy="process-data"
102                             className={classes.dataExplorer}>
103                             <ProjectPanelData
104                                 onRowClick={this.handleRowClick}
105                                 onRowDoubleClick={this.handleRowDoubleClick}
106                                 onContextMenu={this.handleContextMenu}
107                             />
108                         </MPVPanelContent>
109                         <MPVPanelContent
110                             forwardProps
111                             xs="auto"
112                             data-cy="process-run"
113                             className={classes.dataExplorer}>
114                             <ProjectPanelRun
115                                 onRowClick={this.handleRowClick}
116                                 onRowDoubleClick={this.handleRowDoubleClick}
117                                 onContextMenu={this.handleContextMenu}
118                             />
119                         </MPVPanelContent>
120                     </MPVContainer>
121                 </div>
122             }
123
124             isCurrentItemChild = (resource: Resource) => {
125                 return resource.ownerUuid === this.props.currentItemId;
126             };
127
128             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
129                 const { resources, isAdmin } = this.props;
130                 const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
131                 // When viewing the contents of a filter group, all contents should be treated as read only.
132                 let readonly = false;
133                 const project = getResource<GroupResource>(this.props.currentItemId)(resources);
134                 if (project && project.groupClass === GroupClass.FILTER) {
135                     readonly = true;
136                 }
137
138                 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
139                 if (menuKind && resource) {
140                     this.props.dispatch<any>(
141                         openContextMenu(event, {
142                             name: resource.name,
143                             uuid: resource.uuid,
144                             ownerUuid: resource.ownerUuid,
145                             isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
146                             kind: resource.kind,
147                             menuKind,
148                             isAdmin,
149                             isFrozen: resourceIsFrozen(resource, resources),
150                             description: resource.description,
151                             storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
152                             properties: 'properties' in resource ? resource.properties : {},
153                         })
154                     );
155                 }
156                 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
157             };
158
159             handleRowDoubleClick = (uuid: string) => {
160                 this.props.dispatch<any>(navigateTo(uuid));
161             };
162
163             handleRowClick = (uuid: string) => {
164                 this.props.dispatch<any>(toggleOne(uuid))
165                 this.props.dispatch<any>(deselectAllOthers(uuid))
166                 this.props.dispatch<any>(loadDetailsPanel(uuid));
167             };
168         }
169     )
170 );