1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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";
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
24 export const ToggleLockAction = withRouter(connect(mapStateToProps)((props: {
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 :
34 onClick={props.onClick} >
40 <ListItemText style={{ textDecoration: 'none' }}>
42 ? <>Unfreeze project</>
43 : <>Freeze project</>}
45 </ListItem > : null));