Skip to content

Commit e1fc316

Browse files
committed
useTabHook in jenkinsjobanalysis view
1 parent 6fef9d1 commit e1fc316

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

frontend/src/views/jenkinsjobanalysis.js

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect, useState, useMemo } from 'react';
1+
import React, { useContext, useEffect, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import {
44
Switch,
@@ -16,7 +16,7 @@ import FilterHeatmapWidget from '../widgets/filterheatmap';
1616
import { HEATMAP_MAX_BUILDS } from '../constants';
1717
import { IbutsuContext } from '../services/context';
1818
import ParamDropdown from '../components/param-dropdown';
19-
import { useSearchParams } from 'react-router-dom';
19+
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
2020
import { useTabHook } from '../components/tabHook';
2121

2222
const DEFAULT_BAR = 8;
@@ -29,7 +29,8 @@ const PF_BACK_100 = 'var(--pf-v5-global--BackgroundColor--100)';
2929
const JenkinsJobAnalysisView =({view, defaultTab='heatmap'}) => {
3030
const context = useContext(IbutsuContext);
3131
const {primaryObject} = context;
32-
32+
const location = useLocation();
33+
const navigate = useNavigate();
3334
const [searchParams] = useSearchParams();
3435

3536
const [isAreaChart, setIsAreaChart] = useState(false);
@@ -43,11 +44,10 @@ const JenkinsJobAnalysisView =({view, defaultTab='heatmap'}) => {
4344
const [barchartParams, setBarchartParams] = useState({});
4445
const [linechartParams, setLinechartParams] = useState({});
4546

46-
// Tab state and navigation hooks/effects
4747
const {activeTab, onTabSelect} = useTabHook(
4848
['heatmap', 'overall-health', 'build-durations'],
4949
defaultTab
50-
);
50+
)
5151

5252
useEffect(() => {
5353
// Fetch the widget parameters for heatmap, barchart and linechart
@@ -116,36 +116,6 @@ const JenkinsJobAnalysisView =({view, defaultTab='heatmap'}) => {
116116
return color;
117117
};
118118

119-
const heatmapParam = useMemo(() => {
120-
if (activeTab === 'heatmap') {
121-
return(
122-
<div style={{backgroundColor: PF_BACK_100, float: 'right', clear: 'none', marginBottom: '-2em', padding: '0.2em 1em', width: '30em'}}>
123-
<ParamDropdown
124-
dropdownItems={['Yes', 'No']}
125-
defaultValue={(countSkips ? 'Yes': 'No')}
126-
handleSelect={(value) => setCountSkips(value === 'Yes')}
127-
tooltip="Count skips as failure:"
128-
/>
129-
</div>)
130-
}
131-
}, [activeTab]);
132-
133-
const overallSwitch = useMemo(() => {
134-
if (activeTab === 'overall-health') {
135-
return(
136-
<div style={{backgroundColor: PF_BACK_100, float: 'right', clear: 'none', marginBottom: '-2em', padding: '0.5em 1em'}}>
137-
<Switch
138-
id="bar-chart-switch"
139-
labelOff="Change to Area Chart"
140-
label="Change to Bar Chart"
141-
isChecked={isAreaChart}
142-
onChange={(_, checked) => setIsAreaChart(checked)}
143-
/>
144-
</div>
145-
)
146-
}
147-
}, [activeTab]);
148-
149119
return (
150120
<React.Fragment>
151121
<div style={{backgroundColor: PF_BACK_100, float: 'right', clear: 'right', marginBottom: '-2em', padding: '0.2em 1em', width: '30em'}}>
@@ -156,10 +126,29 @@ const JenkinsJobAnalysisView =({view, defaultTab='heatmap'}) => {
156126
tooltip="Number of builds:"
157127
/>
158128
</div>
159-
{heatmapParam}
160-
{overallSwitch}
129+
{activeTab === 'heatmap' &&
130+
<div style={{backgroundColor: PF_BACK_100, float: 'right', clear: 'none', marginBottom: '-2em', padding: '0.2em 1em', width: '30em'}}>
131+
<ParamDropdown
132+
dropdownItems={['Yes', 'No']}
133+
defaultValue={(countSkips ? 'Yes': 'No')}
134+
handleSelect={(value) => setCountSkips(value === 'Yes')}
135+
tooltip="Count skips as failure:"
136+
/>
137+
</div>
138+
}
139+
{activeTab === 'overall-health' &&
140+
<div style={{backgroundColor: PF_BACK_100, float: 'right', clear: 'none', marginBottom: '-2em', padding: '0.5em 1em'}}>
141+
<Switch
142+
id="bar-chart-switch"
143+
labelOff="Change to Area Chart"
144+
label="Change to Bar Chart"
145+
isChecked={isAreaChart}
146+
onChange={(_, checked) => setIsAreaChart(checked)}
147+
/>
148+
</div>
149+
}
161150
<Tabs activeKey={activeTab} onSelect={onTabSelect} isBox>
162-
<Tab key='heatmap' eventKey='heatmap' title="Heatmap">
151+
<Tab eventKey='heatmap' title="Heatmap">
163152
{!isLoading && activeTab === 'heatmap' &&
164153
<FilterHeatmapWidget
165154
title={heatmapParams.job_name}
@@ -170,7 +159,7 @@ const JenkinsJobAnalysisView =({view, defaultTab='heatmap'}) => {
170159
/>
171160
}
172161
</Tab>
173-
<Tab key='overall-health' eventKey='overall-health' title="Overall Health">
162+
<Tab eventKey='overall-health' title="Overall Health">
174163
{!isLoading && !isAreaChart && activeTab === 'overall-health' &&
175164
<GenericBarWidget
176165
title={'Test counts for ' + barchartParams.job_name}
@@ -221,7 +210,7 @@ const JenkinsJobAnalysisView =({view, defaultTab='heatmap'}) => {
221210
/>
222211
}
223212
</Tab>
224-
<Tab key='build-durations' eventKey='build-durations' title="Build Duration">
213+
<Tab eventKey='build-durations' title="Build Duration">
225214
{!isLoading && activeTab === 'build-durations' &&
226215
<GenericAreaWidget
227216
title={'Durations for ' + linechartParams.job_name}

0 commit comments

Comments
 (0)