2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import classnames from 'classnames';
19 import Collapse from 'react-bootstrap/lib/Collapse.js';
21 class NavigationSideBar extends React.Component {
23 activeItemId: PropTypes.string.isRequired,
24 onSelect: PropTypes.func,
25 onToggle: PropTypes.func,
26 groups: PropTypes.array
34 this.handleItemClicked = this.handleItemClicked.bind(this);
38 let {groups, activeItemId} = this.props;
41 <div className='navigation-side-content'>
42 {groups.map(group => (
43 <NavigationMenu menu={group} activeItemId={activeItemId} onNavigationItemClick={this.handleItemClicked} key={'menu_' + group.id} />
49 handleItemClicked(event, item) {
50 event.stopPropagation();
51 if(this.props.onToggle) {
52 this.props.onToggle(this.props.groups, item.id);
57 if(this.props.onSelect) {
58 this.props.onSelect(item);
63 class NavigationMenu extends React.Component {
65 activeItemId: PropTypes.string.isRequired,
66 onNavigationItemClick: PropTypes.func,
71 const {menu, activeItemId, onNavigationItemClick} = this.props;
73 <div className='navigation-group' key={menu.id}>
74 <NavigationMenuHeader title={menu.name} />
75 <NavigationMenuItems items={menu.items} activeItemId={activeItemId} onNavigationItemClick={onNavigationItemClick} />
80 function NavigationMenuHeader(props) {
81 return <div className='group-name' data-test-id='navbar-group-name'>{props.title}</div>;
84 function getItemDataTestId(itemId) {
85 return itemId.split('|')[0];
87 function NavigationMenuItems(props) {
88 const {items, activeItemId, onNavigationItemClick} = props;
90 <div className='navigation-group-items'>
92 items && items.map(item => (<NavigationMenuItem key={'menuItem_' + item.id} item={item} activeItemId={activeItemId} onNavigationItemClick={onNavigationItemClick} />))
98 function NavigationMenuItem(props) {
99 const {onNavigationItemClick, item, activeItemId} = props;
100 const isGroup = item.items && item.items.length > 0;
102 <div className={classnames('navigation-group-item', {'selected-item': item.id === activeItemId})} key={'item_' + item.id}>
103 <NavigationLink item={item} activeItemId={activeItemId} onClick={onNavigationItemClick} />
104 {isGroup && <Collapse in={item.expanded} data-test-id={'navigation-group-' + getItemDataTestId(item.id)}>
106 {item.items.map(subItem => (<NavigationMenuItem key={'menuItem_' + subItem.id} item={subItem} onNavigationItemClick={onNavigationItemClick} activeItemId={activeItemId} />)) }
114 function NavigationLink(props) {
115 const {item, activeItemId, onClick} = props;
116 // todo should this be button
119 key={'navAction_' + item.id}
120 className={classnames('navigation-group-item-name', {
121 'selected': item.id === activeItemId,
122 'disabled': item.disabled,
123 'bold-name': item.expanded,
124 'hidden': item.hidden
126 onClick={(event) => onClick(event, item)}
127 data-test-id={'navbar-group-item-' + getItemDataTestId(item.id)}>
133 export default NavigationSideBar;