14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { Component } from 'react'
17
+ import React , { Component , useEffect } from 'react'
18
+ import ReactGA from 'react-ga4'
19
+ import { generatePath , useHistory , useParams , useRouteMatch } from 'react-router-dom'
20
+ import Tippy from '@tippyjs/react'
21
+ import moment from 'moment'
22
+ import { Bar , BarChart , Label , Legend , ReferenceLine , ResponsiveContainer , Tooltip , XAxis , YAxis } from 'recharts'
23
+
18
24
import {
19
- showError ,
20
- Progressing ,
25
+ EMPTY_STATE_STATUS ,
21
26
ErrorScreenManager ,
22
27
GenericEmptyState ,
28
+ Progressing ,
23
29
SelectPicker ,
30
+ showError ,
24
31
} from '@devtron-labs/devtron-fe-common-lib'
25
- import { generatePath } from 'react-router-dom'
26
- import { ResponsiveContainer , BarChart , Bar , XAxis , YAxis , Tooltip , Legend , Label , ReferenceLine } from 'recharts'
27
- import moment from 'moment'
28
- import Tippy from '@tippyjs/react'
29
- import ReactGA from 'react-ga4'
30
- import { getDeploymentMetrics } from './deploymentMetrics.service'
31
- import { DatePicker } from '../../../common'
32
+
33
+ import { ReactComponent as Success } from '@Icons/appstatus/healthy.svg'
34
+ import { ReactComponent as Fail } from '@Icons/ic-error-exclamation.svg'
35
+ import { ReactComponent as ICHelpOutline } from '@Icons/ic-help-outline.svg'
36
+ import { ReactComponent as Deploy } from '@Icons/ic-nav-rocket.svg'
37
+
38
+ import AppNotDeployed from '@Images/app-not-deployed.svg'
39
+ import SelectEnvImage from '@Images/[email protected] '
32
40
import { ViewType } from '../../../../config'
33
- import { DeploymentTable } from './DeploymentTable'
34
41
import { getAppOtherEnvironmentMin } from '../../../../services/service'
35
- import { DeploymentTableModal } from './DeploymentTableModal '
42
+ import { DatePicker , useAppContext } from '../../../common '
36
43
import { BenchmarkModal } from './BenchmarkModal'
44
+ import { getDeploymentMetrics } from './deploymentMetrics.service'
45
+ import { DeploymentMetricsProps , DeploymentMetricsState } from './deploymentMetrics.types'
37
46
import {
38
47
BenchmarkLine ,
48
+ EliteCategoryMessage ,
49
+ FailureLegendEmptyState ,
50
+ FrequencyTooltip ,
39
51
frequencyXAxisLabel ,
52
+ getGALabel ,
53
+ LeadTimeTooltip ,
40
54
leadTimeXAxisLabel ,
41
55
recoveryTimeLabel ,
56
+ RecoveryTimeTooltip ,
42
57
ReferenceLineLegend ,
43
58
renderCategoryTag ,
44
- FrequencyTooltip ,
45
- RecoveryTimeTooltip ,
46
- LeadTimeTooltip ,
47
- EliteCategoryMessage ,
48
- FailureLegendEmptyState ,
49
59
} from './deploymentMetrics.util'
50
- import AppNotDeployed from '../../../../assets/img/app-not-deployed.svg'
51
- import SelectEnvImage from '../../../../assets/img/[email protected] '
52
- import { ReactComponent as ICHelpOutline } from '@Icons/ic-help-outline.svg'
53
- import { ReactComponent as Deploy } from '@Icons/ic-nav-rocket.svg'
54
- import { ReactComponent as Success } from '@Icons/appstatus/healthy.svg'
55
- import { ReactComponent as Fail } from '@Icons/ic-error-exclamation.svg'
60
+ import { DeploymentTable } from './DeploymentTable'
61
+ import { DeploymentTableModal } from './DeploymentTableModal'
62
+
56
63
import './deploymentMetrics.scss'
57
- import { DeploymentMetricsProps , DeploymentMetricsState } from './deploymentMetrics.types'
58
- import { EMPTY_STATE_STATUS } from '../../../../config/constantMessaging'
59
64
60
- export default class DeploymentMetrics extends Component < DeploymentMetricsProps , DeploymentMetricsState > {
65
+ class DeploymentMetricsComponent extends Component < DeploymentMetricsProps , DeploymentMetricsState > {
61
66
constructor ( props ) {
62
67
super ( props )
63
68
@@ -93,7 +98,6 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
93
98
endDate : undefined ,
94
99
} ,
95
100
deploymentTableView : ViewType . FORM ,
96
- filteredEnvironment : [ ] ,
97
101
}
98
102
this . handleDatesChange = this . handleDatesChange . bind ( this )
99
103
this . handleFocusChange = this . handleFocusChange . bind ( this )
@@ -181,7 +185,6 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
181
185
allEnv . length && prevEnvId && ( prevEnvId !== this . props . match . params . envId || ! isEnvExist )
182
186
this . setState ( {
183
187
environments : allEnv ,
184
- filteredEnvironment : allEnv ,
185
188
view : this . props . match . params . envId || redirectToNewUrl ? ViewType . LOADING : ViewType . FORM ,
186
189
} )
187
190
if ( redirectToNewUrl ) {
@@ -234,7 +237,7 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
234
237
ReactGA . event ( {
235
238
category : 'Deployment Metrics' ,
236
239
action : 'Deployment Status Filter Clicked' ,
237
- label : this . getGALabel ( event . target . value ) ,
240
+ label : getGALabel ( event . target . value ) ,
238
241
} )
239
242
this . setState ( { statusFilter : Number ( event . target . value ) , deploymentTableView : ViewType . LOADING } , ( ) => {
240
243
setTimeout ( ( ) => {
@@ -243,19 +246,6 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
243
246
} )
244
247
}
245
248
246
- getGALabel ( statusFilter ) {
247
- switch ( Number ( statusFilter ) ) {
248
- case - 1 :
249
- return 'All'
250
- case 0 :
251
- return 'Success'
252
- case 1 :
253
- return 'Failed'
254
- default :
255
- return ''
256
- }
257
- }
258
-
259
249
renderInputs ( ) {
260
250
return (
261
251
< div className = "deployment-metrics__inputs bg__primary" >
@@ -269,11 +259,11 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
269
259
onChange = { ( selected ) => {
270
260
this . handleEnvironmentChange ( selected )
271
261
} }
272
- options = { this . state . filteredEnvironment . sort ( ( a , b ) => ( a . label > b . label ? 1 : - 1 ) ) }
262
+ options = { this . state . environments }
273
263
/>
274
264
</ div >
275
265
< div className = "dc__align-right " >
276
- { this . props . match . params . envId ? (
266
+ { this . state . selectedEnvironment ? (
277
267
< DatePicker
278
268
startDate = { this . state . startDate }
279
269
endDate = { this . state . endDate }
@@ -631,21 +621,22 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
631
621
if ( this . state . view === ViewType . FORM && this . state . environments . length === 0 ) {
632
622
return this . renderNoEnvironmentView ( )
633
623
}
634
- if ( this . state . view === ViewType . FORM && ! this . props . match . params . envId ) {
624
+ if ( this . state . view === ViewType . FORM && ( ! this . props . match . params . envId || ! ( this . state . environments ?? [ ] ) . find ( ( env ) => env . value === + this . props . match . params . envId ) ) ) {
635
625
return this . renderSelectEnvironmentView ( )
636
626
}
637
627
if ( this . state . view === ViewType . FORM && this . state . frequencyAndLeadTimeGraph . length === 0 ) {
638
628
return this . renderEmptyState ( )
639
629
}
640
630
641
- let deploymentTableRows = this . state . rows
642
- if ( this . state . statusFilter > - 1 ) {
643
- deploymentTableRows = deploymentTableRows . filter ( ( row ) => {
644
- if ( row . releaseStatus === this . state . statusFilter ) {
645
- return row
646
- }
647
- } )
648
- }
631
+ const deploymentTableRows =
632
+ this . state . statusFilter > - 1
633
+ ? this . state . rows . filter ( ( row ) => {
634
+ if ( row . releaseStatus === this . state . statusFilter ) {
635
+ return row
636
+ }
637
+ } )
638
+ : this . state . rows
639
+
649
640
return (
650
641
< div >
651
642
{ this . renderGraphs ( ) }
@@ -703,7 +694,27 @@ export default class DeploymentMetrics extends Component<DeploymentMetricsProps,
703
694
}
704
695
}
705
696
706
- export interface FrequencyGraphLegendProps {
697
+ const DeploymentMetrics = ( props : DeploymentMetricsProps ) => {
698
+ const { appId, envId } = useParams < { appId : string ; envId : string } > ( )
699
+ const { environmentId, setEnvironmentId } = useAppContext ( )
700
+ const { path } = useRouteMatch ( )
701
+ const { replace } = useHistory ( )
702
+
703
+ useEffect ( ( ) => {
704
+ if ( envId && + envId !== environmentId ) {
705
+ setEnvironmentId ( + envId )
706
+ }
707
+ if ( ! envId && environmentId ) {
708
+ replace ( generatePath ( path , { appId, envId : environmentId } ) )
709
+ }
710
+ } , [ envId ] )
711
+
712
+ return < DeploymentMetricsComponent { ...props } />
713
+ }
714
+
715
+ export default DeploymentMetrics
716
+
717
+ interface FrequencyGraphLegendProps {
707
718
noFailures : boolean
708
719
label : string
709
720
frequency : string
@@ -713,7 +724,7 @@ export interface FrequencyGraphLegendProps {
713
724
setFrequencyMetric : ( ...args ) => void
714
725
setFailureMetric : ( ...args ) => void
715
726
}
716
- export class FrequencyGraphLegend extends React . Component < FrequencyGraphLegendProps , { } > {
727
+ class FrequencyGraphLegend extends React . Component < FrequencyGraphLegendProps , { } > {
717
728
render ( ) {
718
729
return (
719
730
< div className = "graph-legend" >
@@ -789,15 +800,15 @@ export class FrequencyGraphLegend extends React.Component<FrequencyGraphLegendPr
789
800
}
790
801
}
791
802
792
- export interface RecoveryAndLeadTimeGraphLegendProps {
803
+ interface RecoveryAndLeadTimeGraphLegendProps {
793
804
noFailures : boolean
794
805
valueLabel : string
795
806
label : string
796
807
tooltipText : string
797
808
benchmark : undefined | any
798
809
setMetric : ( ...args ) => void
799
810
}
800
- export class RecoveryAndLeadTimeGraphLegend extends React . Component < RecoveryAndLeadTimeGraphLegendProps , { } > {
811
+ class RecoveryAndLeadTimeGraphLegend extends React . Component < RecoveryAndLeadTimeGraphLegendProps , { } > {
801
812
render ( ) {
802
813
if ( this . props . noFailures ) {
803
814
return (
0 commit comments