// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 import React, { Component } from 'react'; import PropTypes from 'prop-types'; import './Header.scss'; import { Navbar, NavbarBrand, Nav, NavItem, NavLink, UncontrolledDropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { Colors } from "./common/Colors"; export class Header extends Component { showLogInButton(isLoggedIn) { if (!isLoggedIn) { return ( Log in ); } else { return null; } } shouldHaveDropdown(menu, onLogout) { return this.shouldShowMenu(menu) || onLogout; } shouldShowMenu(menu) { return Array.isArray(menu) && menu.length > 0; } showMenuItems(menu) { if (!this.shouldShowMenu(menu)) { return null; } return menu.map(item => { return {item.text} ; }); } showUserMenu(isLoggedIn, loginName, menu, onLogout, onMLTraining, onHome, onBatchUpload) { if (isLoggedIn) { const dropdownAttr = this.shouldHaveDropdown(menu, onLogout) ? {nav : true, caret : true} : {nav : true}; return ( {loginName} { this.shouldHaveDropdown(menu, onLogout) && {this.showMenuItems(menu)} {onLogout && Home } {onLogout && Model Training } {onLogout && Batch Analysis } {onLogout && Log out } } ); } else { return null; } } createThemeObject(theme) { if (theme === 'dark') { return { dark : true, // color: 'dark',// will use dark-gray with !important style // Instead of customizing bootstrap (which is difficult to find right variable and avoid side effect) style : { backgroundColor : Colors.SQUIDINK } }; } else { return { color : 'light', light : true }; } } render() { const {customerName, customerLogoUrl, loginName, theme, menu, onLogout, onMLTraining, onHome, onBatchUpload} = this.props; const hideLoginComponent = (loginName === undefined || loginName === null); const isLoggedIn = !!loginName; let customTheme = this.createThemeObject(theme); return ( { customerLogoUrl && Customer logo } {customerName} {/* Divide left and right alignment*/}
{ !hideLoginComponent && } ); } } Header.propTypes = { customerLogoUrl : PropTypes.string, customerName : PropTypes.string, loginName : PropTypes.string, menu : PropTypes.array, onLogout : PropTypes.func, onMLTraining: PropTypes.func, onHome: PropTypes.func, onBatchUpload: PropTypes.func, theme : PropTypes.oneOf(['light', 'dark']), logoHeight : PropTypes.number, };