1+ import React , { useState , useContext } from 'react'
2+ import { useNavigate } from 'react-router-dom'
3+ import { ApplicationContext } from '../../context/ApplicationContext'
4+ import { QueryContext } from '../../context/QueryContext'
5+ import { CommsContext } from '../../context/CommsContext'
6+ import { HealthContext } from '../../context/HealthContext'
7+ import { Link } from 'react-router-dom' ;
8+
9+ const GraphNavBar = ( props ) => {
10+
11+ const { chart, setChart, dockerData, inspect, setInspect } = props
12+ const [ prevRoute , setPrevRoute ] = useState < string > ( '' ) ;
13+ const { servicesData } = useContext ( ApplicationContext ) ;
14+ const { selectedMetrics } = useContext ( QueryContext ) ;
15+ const { commsData } = useContext ( CommsContext )
16+ const { services } = useContext ( HealthContext )
17+
18+ const navigate = useNavigate ( ) ;
19+
20+ const routing = ( route : string ) => {
21+ if ( location . href . includes ( 'communications' ) ) {
22+ if ( prevRoute === '' ) navigate ( `${ servicesData [ 0 ] . microservice } ` ) ;
23+ else navigate ( prevRoute ) ;
24+ }
25+ setChart ( route ) ;
26+ } ;
27+
28+ const getHealthAndEventComponents = ( ) => {
29+ const buttonList : JSX . Element [ ] = [ ] ;
30+ if ( selectedMetrics ) {
31+ selectedMetrics . forEach ( ( element , id ) => {
32+ const categoryName = Object . keys ( element ) [ 0 ] ;
33+ let prefix ;
34+ if ( categoryName === 'Event' ) {
35+ prefix = 'event_' ;
36+ } else if ( categoryName === 'books' || categoryName === 'customers' || categoryName === 'frontend' || categoryName === 'orders' ) {
37+ prefix = 'docker_' ;
38+ } else {
39+ prefix = 'health_' ;
40+ }
41+ buttonList . push (
42+ < button
43+ id = { `${ prefix } ${ categoryName } -button` }
44+ className = { chart === `${ prefix } ${ categoryName } ` ? 'selected' : undefined }
45+ onClick = { ( ) => routing ( `${ prefix } ${ categoryName } ` ) }
46+ key = { `1-${ id } ` }
47+ >
48+ { categoryName }
49+ </ button >
50+ ) ;
51+ } ) ;
52+ }
53+
54+ return buttonList ;
55+ } ;
56+
57+ const HealthAndEventButtons : JSX . Element [ ] = getHealthAndEventComponents ( ) ;
58+
59+ return (
60+ < nav id = "navigationBar" >
61+ < button
62+ className = { chart === 'all' ? 'selected' : undefined }
63+ id = "all-button"
64+ onClick = { ( ) => routing ( 'all' ) }
65+ key = "0"
66+ >
67+ Metrics Query
68+ </ button >
69+ { HealthAndEventButtons }
70+ { dockerData . containername && (
71+ < button
72+ id = "docker-button"
73+ className = { chart === 'docker' ? 'selected' : undefined }
74+ onClick = { ( ) => routing ( 'docker' ) }
75+ key = "2"
76+ >
77+ Docker
78+ </ button >
79+ ) }
80+ { commsData . length > 0 && (
81+ < button
82+ id = "communication-button"
83+ className = { chart === 'communications' ? 'selected' : undefined }
84+ onClick = { ( ) => {
85+ if ( ! location . href . includes ( 'communications' ) ) setPrevRoute ( services . join ( ' ' ) ) ;
86+ setChart ( 'communications' ) ;
87+ } }
88+ key = "3"
89+ >
90+ Communication
91+ </ button >
92+ ) }
93+ < button
94+ id = "modify-metrics-button"
95+ className = { chart === 'modifyMetrics' ? 'selected' : undefined }
96+ onClick = { ( ) => {
97+ routing ( 'modifyMetrics' ) ;
98+ } }
99+ key = "4"
100+ >
101+ Modify Metrics
102+ </ button >
103+ { /* <Link className="sidebar-link" to="/Inspect" id="Inspect" >
104+ <SettingsIcon
105+ style={{
106+ WebkitBoxSizing: 'content-box',
107+ boxShadow: 'none',
108+ width: '35px',
109+ height: '35px',
110+ }}
111+ />
112+  Inspect
113+ </Link> */ }
114+ < button onClick = { ( ) => { setInspect ( ! inspect ) } } > Inspect</ button >
115+ </ nav >
116+ )
117+ }
118+
119+ export default GraphNavBar
0 commit comments