1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Dispatch } from "redux";
7 import { connect } from "react-redux";
8 import { Badge, MenuItem } from "@material-ui/core";
9 import { DropdownMenu } from "components/dropdown-menu/dropdown-menu";
10 import { NotificationIcon } from "components/icon/icon";
11 import bannerActions from "store/banner/banner-action";
12 import { BANNER_LOCAL_STORAGE_KEY } from "views-components/baner/banner";
13 import { RootState } from "store/store";
14 import { TOOLTIP_LOCAL_STORAGE_KEY } from "store/tooltips/tooltips-middleware";
15 import { useCallback } from "react";
17 const mapStateToProps = (state: RootState): NotificationsMenuProps => ({
18 isOpen: state.banner.isOpen,
19 bannerUUID: state.auth.config.clusterConfig.Workbench.BannerUUID,
22 const mapDispatchToProps = (dispatch: Dispatch) => ({
23 openBanner: () => dispatch<any>(bannerActions.openBanner()),
26 type NotificationsMenuProps = {
31 type NotificationsMenuComponentProps = NotificationsMenuProps & {
35 export const NotificationsMenuComponent = (props: NotificationsMenuComponentProps) => {
36 const { isOpen, openBanner } = props;
37 const bannerResult = localStorage.getItem(BANNER_LOCAL_STORAGE_KEY);
38 const tooltipResult = localStorage.getItem(TOOLTIP_LOCAL_STORAGE_KEY);
39 const menuItems: any[] = [];
41 if (!isOpen && bannerResult) {
42 menuItems.push(<MenuItem><span onClick={openBanner}>Restore Banner</span></MenuItem>);
45 const toggleTooltips = useCallback(() => {
47 localStorage.removeItem(TOOLTIP_LOCAL_STORAGE_KEY);
49 localStorage.setItem(TOOLTIP_LOCAL_STORAGE_KEY, 'true');
51 window.location.reload();
55 menuItems.push(<MenuItem><span onClick={toggleTooltips}>Enable tooltips</span></MenuItem>);
57 menuItems.push(<MenuItem><span onClick={toggleTooltips}>Disable tooltips</span></MenuItem>);
60 if (menuItems.length === 0) {
61 menuItems.push(<MenuItem>You are up to date</MenuItem>);
72 title="Notifications">
74 menuItems.map((item, i) => <div key={i}>{item}</div>)
79 export const NotificationsMenu = connect(mapStateToProps, mapDispatchToProps)(NotificationsMenuComponent);