@@ -3,7 +3,6 @@ import React from 'react';
3
3
import { GrafanaTheme2 } from '@grafana/data' ;
4
4
import { Button , HorizontalGroup , Icon , IconButton , Tooltip , VerticalGroup , withTheme2 } from '@grafana/ui' ;
5
5
import { observer } from 'mobx-react' ;
6
- import { RouteComponentProps , withRouter } from 'react-router-dom' ;
7
6
import { getUtilStyles } from 'styles/utils.styles' ;
8
7
9
8
import { Collapse } from 'components/Collapse/Collapse' ;
@@ -30,10 +29,15 @@ import { PageProps, WithStoreProps } from 'state/types';
30
29
import { withMobXProviderContext } from 'state/withStore' ;
31
30
import { UserActions } from 'utils/authorization/authorization' ;
32
31
import { PAGE , PLUGIN_ROOT } from 'utils/consts' ;
32
+ import { PropsWithRouter , withRouter } from 'utils/hoc' ;
33
33
34
34
import { getEscalationChainStyles } from './EscalationChains.styles' ;
35
35
36
- interface EscalationChainsPageProps extends WithStoreProps , PageProps , RouteComponentProps < { id : string } > {
36
+ interface RouteProps {
37
+ id : string ;
38
+ }
39
+
40
+ interface EscalationChainsPageProps extends WithStoreProps , PageProps , PropsWithRouter < RouteProps > {
37
41
theme : GrafanaTheme2 ;
38
42
}
39
43
@@ -60,7 +64,7 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
60
64
61
65
const {
62
66
store,
63
- match : {
67
+ router : {
64
68
params : { id } ,
65
69
} ,
66
70
} = this . props ;
@@ -101,9 +105,11 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
101
105
} ;
102
106
103
107
handleEsclalationSelect = ( id : EscalationChain [ 'id' ] ) => {
104
- const { history } = this . props ;
108
+ const {
109
+ router : { navigate } ,
110
+ } = this . props ;
105
111
106
- history . push ( `${ PLUGIN_ROOT } /escalations/${ id } ${ window . location . search } ` ) ;
112
+ navigate ( `${ PLUGIN_ROOT } /escalations/${ id } ${ window . location . search } ` ) ;
107
113
} ;
108
114
109
115
setSelectedEscalationChain = async ( escalationChainId : EscalationChain [ 'id' ] ) => {
@@ -119,15 +125,17 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
119
125
} ;
120
126
121
127
componentDidUpdate ( prevProps : EscalationChainsPageProps ) {
122
- if ( this . props . match . params . id !== prevProps . match . params . id ) {
128
+ const { router } = this . props ;
129
+
130
+ if ( router . params . id !== prevProps . router . params . id ) {
123
131
this . parseQueryParams ( ) ;
124
132
}
125
133
}
126
134
127
135
render ( ) {
128
136
const {
129
137
store,
130
- match : {
138
+ router : {
131
139
params : { id } ,
132
140
} ,
133
141
theme,
@@ -256,7 +264,7 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
256
264
257
265
handleFiltersChange = ( filters : FiltersValues , isOnMount = false ) => {
258
266
const {
259
- match : {
267
+ router : {
260
268
params : { id } ,
261
269
} ,
262
270
} = this . props ;
@@ -272,15 +280,18 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
272
280
} ;
273
281
274
282
autoSelectEscalationChain = ( ) => {
275
- const { store, history } = this . props ;
283
+ const {
284
+ store,
285
+ router : { navigate } ,
286
+ } = this . props ;
276
287
const { selectedEscalationChain } = this . state ;
277
288
const { escalationChainStore } = store ;
278
289
279
290
const searchResult = escalationChainStore . getSearchResult ( ) ;
280
291
281
292
if ( ! searchResult . find ( ( escalationChain : EscalationChain ) => escalationChain . id === selectedEscalationChain ) ) {
282
293
const id = searchResult [ 0 ] ?. id ;
283
- history . push ( `${ PLUGIN_ROOT } /escalations/${ id || '' } ${ window . location . search } ` ) ;
294
+ navigate ( `${ PLUGIN_ROOT } /escalations/${ id || '' } ${ window . location . search } ` ) ;
284
295
}
285
296
} ;
286
297
@@ -400,11 +411,13 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
400
411
401
412
handleEscalationChainCreate = async ( id : EscalationChain [ 'id' ] ) => {
402
413
const { selectedEscalationChain } = this . state ;
403
- const { history } = this . props ;
414
+ const {
415
+ router : { navigate } ,
416
+ } = this . props ;
404
417
405
418
await this . applyFilters ( ) ;
406
419
407
- history . push ( `${ PLUGIN_ROOT } /escalations/${ id } ${ window . location . search } ` ) ;
420
+ navigate ( `${ PLUGIN_ROOT } /escalations/${ id } ${ window . location . search } ` ) ;
408
421
409
422
// because this page wouldn't detect query.id change
410
423
if ( selectedEscalationChain === id ) {
@@ -444,7 +457,10 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
444
457
} ;
445
458
446
459
handleDeleteEscalationChain = async ( ) => {
447
- const { store, history } = this . props ;
460
+ const {
461
+ store,
462
+ router : { navigate } ,
463
+ } = this . props ;
448
464
const { escalationChainStore } = store ;
449
465
const { selectedEscalationChain, extraEscalationChains } = this . state ;
450
466
@@ -464,10 +480,9 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
464
480
}
465
481
466
482
const escalationChains = escalationChainStore . getSearchResult ( ) ;
467
-
468
483
const newSelected = escalationChains [ index - 1 ] || escalationChains [ 0 ] ;
469
484
470
- history . push ( `${ PLUGIN_ROOT } /escalations/${ newSelected ?. id || '' } ${ window . location . search } ` ) ;
485
+ navigate ( `${ PLUGIN_ROOT } /escalations/${ newSelected ?. id || '' } ${ window . location . search } ` ) ;
471
486
} ;
472
487
473
488
handleEscalationChainNameChange = ( value : string ) => {
@@ -480,4 +495,6 @@ class _EscalationChainsPage extends React.Component<EscalationChainsPageProps, E
480
495
} ;
481
496
}
482
497
483
- export const EscalationChainsPage = withRouter ( withMobXProviderContext ( withTheme2 ( _EscalationChainsPage ) ) ) ;
498
+ export const EscalationChainsPage = withRouter < RouteProps , Omit < EscalationChainsPageProps , 'store' | 'meta' | 'theme' > > (
499
+ withMobXProviderContext ( withTheme2 ( _EscalationChainsPage ) )
500
+ ) ;
0 commit comments