21128: single-multi works again Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox...
[arvados.git] / src / views-components / context-menu / actions / lock-action.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 { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
7 import { FreezeIcon, UnfreezeIcon } from "components/icon/icon";
8 import { connect } from "react-redux";
9 import { RootState } from "store/store";
10 import { ProjectResource } from "models/project";
11 import { withRouter, RouteComponentProps } from "react-router";
12 import { resourceIsFrozen } from "common/frozen-resources";
13
14 const mapStateToProps = (state: RootState, props: { onClick: () => {} }) => ({
15     isAdmin: !!state.auth.user?.isAdmin,
16     isLocked: !!(state.resources[state.contextMenu.resource!.uuid] as ProjectResource).frozenByUuid,
17     canManage: (state.resources[state.contextMenu.resource!.uuid] as ProjectResource).canManage,
18     canUnfreeze: !state.auth.remoteHostsConfig[state.auth.homeCluster]?.clusterConfig?.API?.UnfreezeProjectRequiresAdmin,
19     resource: state.contextMenu.resource,
20     resources: state.resources,
21     onClick: props.onClick
22 });
23
24 export const ToggleLockAction = withRouter(connect(mapStateToProps)((props: {
25     resource: any,
26     resources: any,
27     onClick: () => void,
28     state: RootState, isAdmin: boolean, isLocked: boolean, canManage: boolean, canUnfreeze: boolean,
29 } & RouteComponentProps) =>
30     (props.canManage && !props.isLocked) || (props.isLocked && props.canManage && (props.canUnfreeze || props.isAdmin))  ? 
31         resourceIsFrozen(props.resource, props.resources) ? null :
32             <ListItem
33                 button
34                 onClick={props.onClick} >
35                 <ListItemIcon>
36                     {props.isLocked
37                         ? <UnfreezeIcon />
38                         : <FreezeIcon />}
39                 </ListItemIcon>
40                 <ListItemText style={{ textDecoration: 'none' }}>
41                     {props.isLocked
42                         ? <>Unfreeze project</>
43                         : <>Freeze project</>}
44                 </ListItemText>
45             </ListItem > : null));