|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { Dropdown, DropdownItem } from 'nr1'; |
| 4 | +import { groupBy } from 'lodash'; |
| 5 | +import styled from 'styled-components'; |
| 6 | + |
| 7 | +import { ToolbarItem } from '../../../shared/components/Toolbar'; |
| 8 | + |
| 9 | +const StyledToolbarItem = styled(ToolbarItem)` |
| 10 | + flex-direction: column; |
| 11 | + align-items: flex-start; |
| 12 | +
|
| 13 | + > span { |
| 14 | + margin-bottom: 7px; |
| 15 | + letter-spacing: 1.25px; |
| 16 | + text-transform: uppercase; |
| 17 | + color: #8e9494; |
| 18 | + font-size: 10px; |
| 19 | + } |
| 20 | +
|
| 21 | + > h4 { |
| 22 | + max-width: 308px; |
| 23 | + white-space: nowrap; |
| 24 | + text-overflow: ellipsis; |
| 25 | + overflow: hidden; |
| 26 | + font-size: 20px; |
| 27 | + text-transform: none; |
| 28 | + color: #464e4e; |
| 29 | + } |
| 30 | +`; |
| 31 | + |
| 32 | +const LeftToolbar = ({ |
| 33 | + map, |
| 34 | + mapLocations, |
| 35 | + onFilter, |
| 36 | + regionFilter, |
| 37 | + favoriteFilter, |
| 38 | + alertFilter |
| 39 | +}) => { |
| 40 | + const regions = Object.keys( |
| 41 | + groupBy(mapLocations, i => (i.location ? i.location.region : null)) |
| 42 | + ); |
| 43 | + |
| 44 | + const favoriteOptions = [ |
| 45 | + { name: 'All', value: null }, |
| 46 | + { name: 'Favorites', value: true }, |
| 47 | + { name: 'Unfavorited', value: false } |
| 48 | + ]; |
| 49 | + |
| 50 | + const selectedFavorite = favoriteOptions.find( |
| 51 | + o => o.value === favoriteFilter |
| 52 | + ); |
| 53 | + |
| 54 | + const alertStatusOptions = [ |
| 55 | + { name: 'All', value: null }, |
| 56 | + { name: 'CRITICAL', value: 'CRITICAL' }, |
| 57 | + { name: 'NOT_ALERTING', value: 'NOT_ALERTING' }, |
| 58 | + { name: 'NOT_CONFIGURED', value: 'NOT_CONFIGURED' }, |
| 59 | + { name: 'WARNING', value: 'WARNING' } |
| 60 | + ]; |
| 61 | + |
| 62 | + const selectedAlertStatus = alertStatusOptions.find( |
| 63 | + o => o.value === alertFilter |
| 64 | + ); |
| 65 | + |
| 66 | + return ( |
| 67 | + <> |
| 68 | + <StyledToolbarItem hasSeparator> |
| 69 | + <span>Current Map</span> |
| 70 | + <h4>{map.title}</h4> |
| 71 | + </StyledToolbarItem> |
| 72 | + <ToolbarItem> |
| 73 | + <Dropdown label="Regions" title={regionFilter || 'Filter by Region'}> |
| 74 | + <DropdownItem |
| 75 | + key={0} |
| 76 | + onClick={() => { |
| 77 | + onFilter({ |
| 78 | + filter: { name: 'regionFilter', value: null } |
| 79 | + }); |
| 80 | + }} |
| 81 | + > |
| 82 | + All |
| 83 | + </DropdownItem> |
| 84 | + {regions.map(r => { |
| 85 | + return ( |
| 86 | + <DropdownItem |
| 87 | + key={r} |
| 88 | + onClick={() => { |
| 89 | + onFilter({ |
| 90 | + filter: { name: 'regionFilter', value: r } |
| 91 | + }); |
| 92 | + }} |
| 93 | + > |
| 94 | + {r} |
| 95 | + </DropdownItem> |
| 96 | + ); |
| 97 | + })} |
| 98 | + </Dropdown> |
| 99 | + </ToolbarItem> |
| 100 | + <ToolbarItem> |
| 101 | + <Dropdown label="Favorites" title={selectedFavorite.name}> |
| 102 | + {favoriteOptions.map(r => { |
| 103 | + return ( |
| 104 | + <DropdownItem |
| 105 | + key={r.value} |
| 106 | + onClick={() => { |
| 107 | + onFilter({ |
| 108 | + filter: { name: 'favoriteFilter', value: r.value } |
| 109 | + }); |
| 110 | + }} |
| 111 | + > |
| 112 | + {r.name} |
| 113 | + </DropdownItem> |
| 114 | + ); |
| 115 | + })} |
| 116 | + </Dropdown> |
| 117 | + </ToolbarItem> |
| 118 | + <ToolbarItem> |
| 119 | + <Dropdown label="Alerting Status" title={selectedAlertStatus.name}> |
| 120 | + {alertStatusOptions.map(r => { |
| 121 | + return ( |
| 122 | + <DropdownItem |
| 123 | + key={r.value} |
| 124 | + onClick={() => { |
| 125 | + onFilter({ |
| 126 | + filter: { name: 'alertFilter', value: r.value } |
| 127 | + }); |
| 128 | + }} |
| 129 | + > |
| 130 | + {r.name} |
| 131 | + </DropdownItem> |
| 132 | + ); |
| 133 | + })} |
| 134 | + </Dropdown> |
| 135 | + </ToolbarItem> |
| 136 | + </> |
| 137 | + ); |
| 138 | +}; |
| 139 | + |
| 140 | +LeftToolbar.propTypes = { |
| 141 | + map: PropTypes.object, |
| 142 | + mapLocations: PropTypes.array, |
| 143 | + onFilter: PropTypes.func, |
| 144 | + regionFilter: PropTypes.string, |
| 145 | + favoriteFilter: PropTypes.bool, |
| 146 | + alertFilter: PropTypes.string |
| 147 | +}; |
| 148 | + |
| 149 | +export default LeftToolbar; |
0 commit comments