17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / views-components / context-menu / actions / favorite-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 { AddFavoriteIcon, RemoveFavoriteIcon } from "components/icon/icon";
8 import { connect } from "react-redux";
9 import { RootState } from "store/store";
10
11 const mapStateToProps = (state: RootState, props: { onClick: () => {} }) => ({
12     isFavorite: state.contextMenu.resource !== undefined && state.favorites[state.contextMenu.resource.uuid] === true,
13     onClick: props.onClick
14 });
15
16 export const ToggleFavoriteAction = connect(mapStateToProps)((props: { isFavorite: boolean, onClick: () => void }) =>
17     <ListItem
18         button
19         onClick={props.onClick}>
20         <ListItemIcon>
21             {props.isFavorite
22                 ? <RemoveFavoriteIcon />
23                 : <AddFavoriteIcon />}
24         </ListItemIcon>
25         <ListItemText style={{ textDecoration: 'none' }}>
26             {props.isFavorite
27                 ? <>Remove from favorites</>
28                 : <>Add to favorites</>}
29         </ListItemText>
30     </ListItem >);