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) {
43 <MenuItem onClick={openBanner} data-cy="restore-banner-li">
44 <span>Restore Banner</span>
49 const toggleTooltips = useCallback(() => {
51 localStorage.removeItem(TOOLTIP_LOCAL_STORAGE_KEY);
53 localStorage.setItem(TOOLTIP_LOCAL_STORAGE_KEY, "true");
55 window.location.reload();
60 <MenuItem onClick={toggleTooltips} data-cy="enable-tooltip-toggle">
61 <span>Enable tooltips</span>
66 <MenuItem onClick={toggleTooltips} data-cy="disable-tooltip-toggle">
67 <span>Disable tooltips</span>
72 if (menuItems.length === 0) {
73 menuItems.push(<MenuItem>You are up to date</MenuItem>);
89 {menuItems.map((item, i) => (
90 <div key={i}>{item}</div>
96 export const NotificationsMenu = connect(mapStateToProps, mapDispatchToProps)(NotificationsMenuComponent);