11/* eslint-disable no-bitwise */
22import React , { useEffect , useState , useContext } from 'react' ;
3- import { useNavigate , useParams } from 'react-router-dom' ;
3+ import { useParams } from 'react-router-dom' ;
44import { ApplicationContext } from '../context/ApplicationContext' ;
55import { HealthContext } from '../context/HealthContext' ;
66import { CommsContext } from '../context/CommsContext' ;
77import { DockerContext } from '../context/DockerContext' ;
88import { EventContext } from '../context/EventContext' ;
9- import { QueryContext } from '../context/QueryContext' ;
109import Header from '../components/Header' ;
1110import RequestTypesChart from '../charts/RequestTypesChart' ;
1211import ResponseCodesChart from '../charts/ResponseCodesChart' ;
@@ -21,8 +20,9 @@ import * as DashboardContext from '../context/DashboardContext';
2120import lightAndDark from '../components/Styling' ;
2221import DockerHealthContainer from './DockerHealthContainer' ;
2322
23+ import GraphNavBar from '../components/GraphNavBar' ;
24+
2425import '../stylesheets/GraphsContainer.scss' ;
25- import { Link } from 'react-router-dom' ;
2626import Inspect from './Inspect' ;
2727
2828interface Params {
@@ -31,20 +31,20 @@ interface Params {
3131}
3232
3333const GraphsContainer : React . FC = React . memo ( ( ) => {
34- const navigate = useNavigate ( ) ;
34+
3535 const { app, service } = useParams < keyof Params > ( ) as Params ;
3636 const [ live , setLive ] = useState < boolean > ( false ) ;
3737 const { intervalID, setIntervalID } = useContext ( ApplicationContext ) ;
38- const { servicesData , getSavedMetrics } = useContext ( ApplicationContext ) ;
39- const { fetchHealthData, setHealthData, services } = useContext ( HealthContext ) ;
38+ const { getSavedMetrics } = useContext ( ApplicationContext ) ;
39+ const { fetchHealthData, setHealthData } = useContext ( HealthContext ) ;
4040 const { setDockerData, dockerData } = useContext ( DockerContext ) ;
4141 const { fetchEventData, setEventData } = useContext ( EventContext ) ;
4242 // const { fetchKafkaEventData, setKafkaEventData } = useContext(EventContext);
4343 // const { fetchKubernetesEventData, setKubernetesEventData } = useContext(EventContext);
44- const { fetchCommsData, commsData } = useContext ( CommsContext ) ;
45- const { selectedMetrics } = useContext ( QueryContext ) ;
44+ const { fetchCommsData } = useContext ( CommsContext ) ;
45+ // const { selectedMetrics } = useContext(QueryContext);
4646 const [ chart , setChart ] = useState < string > ( 'all' ) ;
47- const [ prevRoute , setPrevRoute ] = useState < string > ( '' ) ;
47+ // const [prevRoute, setPrevRoute] = useState<string>('');
4848 const { mode } = useContext ( DashboardContext . DashboardContext ) ;
4949 let [ inspect , setInspect ] = useState < boolean > ( false ) ;
5050
@@ -94,14 +94,6 @@ const GraphsContainer: React.FC = React.memo(() => {
9494 //random variable to hold the light or dark mode of the display?..ok....sure
9595 const currentMode = mode === 'light' ? lightAndDark . lightModeText : lightAndDark . darkModeText ;
9696
97- const routing = ( route : string ) => {
98- if ( location . href . includes ( 'communications' ) ) {
99- if ( prevRoute === '' ) navigate ( `${ servicesData [ 0 ] . microservice } ` ) ;
100- else navigate ( prevRoute ) ;
101- }
102- setChart ( route ) ;
103- } ;
104-
10597 const stringToColour = ( string : string , recurses = 0 ) => {
10698 if ( recurses > 20 ) return string ;
10799 function hashString ( str : string ) {
@@ -128,96 +120,21 @@ const GraphsContainer: React.FC = React.memo(() => {
128120 return contrastYiq ( string ) ;
129121 } ;
130122
131- const getHealthAndEventComponents = ( ) => {
132- const buttonList : JSX . Element [ ] = [ ] ;
133- if ( selectedMetrics ) {
134- selectedMetrics . forEach ( ( element , id ) => {
135- const categoryName = Object . keys ( element ) [ 0 ] ;
136- let prefix ;
137- if ( categoryName === 'Event' ) {
138- prefix = 'event_' ;
139- } else if ( categoryName === 'books' || categoryName === 'customers' || categoryName === 'frontend' || categoryName === 'orders' ) {
140- prefix = 'docker_' ;
141- } else {
142- prefix = 'health_' ;
143- }
144- buttonList . push (
145- < button
146- id = { `${ prefix } ${ categoryName } -button` }
147- className = { chart === `${ prefix } ${ categoryName } ` ? 'selected' : undefined }
148- onClick = { ( ) => routing ( `${ prefix } ${ categoryName } ` ) }
149- key = { `1-${ id } ` }
150- >
151- { categoryName }
152- </ button >
153- ) ;
154- } ) ;
155- }
156-
157- return buttonList ;
158- } ;
159-
160- const HealthAndEventButtons : JSX . Element [ ] = getHealthAndEventComponents ( ) ;
161-
162123 return (
163124 < >
164- < nav id = "navigationBar" >
165- < button
166- className = { chart === 'all' ? 'selected' : undefined }
167- id = "all-button"
168- onClick = { ( ) => routing ( 'all' ) }
169- key = "0"
170- >
171- Metrics Query
172- </ button >
173- { HealthAndEventButtons }
174- { dockerData . containername && (
175- < button
176- id = "docker-button"
177- className = { chart === 'docker' ? 'selected' : undefined }
178- onClick = { ( ) => routing ( 'docker' ) }
179- key = "2"
180- >
181- Docker
182- </ button >
183- ) }
184- { commsData . length > 0 && (
185- < button
186- id = "communication-button"
187- className = { chart === 'communications' ? 'selected' : undefined }
188- onClick = { ( ) => {
189- if ( ! location . href . includes ( 'communications' ) ) setPrevRoute ( services . join ( ' ' ) ) ;
190- setChart ( 'communications' ) ;
191- } }
192- key = "3"
193- >
194- Communication
195- </ button >
196- ) }
197- < button
198- id = "modify-metrics-button"
199- className = { chart === 'modifyMetrics' ? 'selected' : undefined }
200- onClick = { ( ) => {
201- routing ( 'modifyMetrics' ) ;
202- } }
203- key = "4"
204- >
205- Modify Metrics
206- </ button >
207- { /* <Link className="sidebar-link" to="/Inspect" id="Inspect" >
208- <SettingsIcon
209- style={{
210- WebkitBoxSizing: 'content-box',
211- boxShadow: 'none',
212- width: '35px',
213- height: '35px',
214- }}
215- />
216-  Inspect
217- </Link> */ }
218- < button onClick = { ( ) => { setInspect ( ! inspect ) } } > Inspect</ button >
219- </ nav >
220- < Header app = { app } service = { service } live = { live } setLive = { setLive } />
125+ < GraphNavBar
126+ chart = { chart }
127+ setChart = { setChart }
128+ dockerData = { dockerData }
129+ inspect = { inspect }
130+ setInspect = { setInspect }
131+ />
132+ < Header
133+ app = { app }
134+ service = { service }
135+ live = { live }
136+ setLive = { setLive }
137+ />
221138 { inspect && < Inspect /> }
222139 < div className = "graphs-container" >
223140 { chart === 'communications' ? (
0 commit comments