data-explorer-routing-and-admins-context-menu-for-resources
[arvados-workbench2.git] / src / views-components / context-menu / actions / public-favorite-action.tsx
diff --git a/src/views-components/context-menu/actions/public-favorite-action.tsx b/src/views-components/context-menu/actions/public-favorite-action.tsx
new file mode 100644 (file)
index 0000000..647b33b
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
+import { AddFavoriteIcon, RemoveFavoriteIcon } from "~/components/icon/icon";
+import { connect } from "react-redux";
+import { RootState } from "~/store/store";
+
+const mapStateToProps = (state: RootState, props: { onClick: () => {} }) => ({
+    isFavorite: state.contextMenu.resource !== undefined && state.favorites[state.contextMenu.resource.uuid] === true,
+    onClick: props.onClick
+});
+
+export const TogglePublicFavoriteAction = connect(mapStateToProps)((props: { isFavorite: boolean, onClick: () => void }) =>
+    <ListItem
+        button
+        onClick={props.onClick}>
+        <ListItemIcon>
+            {props.isFavorite
+                ? <RemoveFavoriteIcon />
+                : <AddFavoriteIcon />}
+        </ListItemIcon>
+        <ListItemText style={{ textDecoration: 'none' }}>
+            {props.isFavorite
+                ? <>Remove from public favorites</>
+                : <>Add to public favorites</>}
+        </ListItemText>
+    </ListItem >);