66 */
77import type { ReactEventHandler } from 'react' ;
88import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
9- import { Redirect , Route , Switch , useLocation , useParams , useHistory } from 'react-router-dom' ;
9+ import { Redirect , Route , Switch , useLocation , useParams } from 'react-router-dom' ;
1010import styled from 'styled-components' ;
1111import {
1212 EuiBetaBadge ,
@@ -31,24 +31,15 @@ import {
3131 useBreadcrumbs ,
3232 useStartServices ,
3333} from '../../../../hooks' ;
34- import {
35- PLUGIN_ID ,
36- INTEGRATIONS_PLUGIN_ID ,
37- INTEGRATIONS_ROUTING_PATHS ,
38- pagePathGetters ,
39- } from '../../../../constants' ;
34+ import { PLUGIN_ID , INTEGRATIONS_ROUTING_PATHS , pagePathGetters } from '../../../../constants' ;
4035import {
4136 useCapabilities ,
4237 useGetPackageInfoByKey ,
4338 useLink ,
4439 useAgentPolicyContext ,
4540} from '../../../../hooks' ;
4641import { pkgKeyFromPackageInfo } from '../../../../services' ;
47- import type {
48- CreatePackagePolicyRouteState ,
49- DetailViewPanelName ,
50- PackageInfo ,
51- } from '../../../../types' ;
42+ import type { DetailViewPanelName , PackageInfo } from '../../../../types' ;
5243import { InstallStatus } from '../../../../types' ;
5344import { Error , Loading } from '../../../../components' ;
5445import type { WithHeaderLayoutProps } from '../../../../layouts' ;
@@ -89,8 +80,7 @@ export function Detail() {
8980 const { pkgkey, panel } = useParams < DetailParams > ( ) ;
9081 const { getHref } = useLink ( ) ;
9182 const hasWriteCapabilites = useCapabilities ( ) . write ;
92- const history = useHistory ( ) ;
93- const { pathname, search, hash } = useLocation ( ) ;
83+ const { search } = useLocation ( ) ;
9484 const queryParams = useMemo ( ( ) => new URLSearchParams ( search ) , [ search ] ) ;
9585 const integration = useMemo ( ( ) => queryParams . get ( 'integration' ) , [ queryParams ] ) ;
9686 const services = useStartServices ( ) ;
@@ -212,66 +202,19 @@ export function Detail() {
212202 ( ev ) => {
213203 ev . preventDefault ( ) ;
214204
215- // The object below, given to `createHref` is explicitly accessing keys of `location` in order
216- // to ensure that dependencies to this `useCallback` is set correctly (because `location` is mutable)
217- const currentPath = history . createHref ( {
218- pathname,
219- search,
220- hash,
221- } ) ;
222-
223205 const path = pagePathGetters . add_integration_to_policy ( {
224206 pkgkey,
225207 ...( integration ? { integration } : { } ) ,
226208 ...( agentPolicyIdFromContext ? { agentPolicyId : agentPolicyIdFromContext } : { } ) ,
227209 } ) [ 1 ] ;
228210
229- let redirectToPath : CreatePackagePolicyRouteState [ 'onSaveNavigateTo' ] &
230- CreatePackagePolicyRouteState [ 'onCancelNavigateTo' ] ;
231-
232- if ( agentPolicyIdFromContext ) {
233- redirectToPath = [
234- PLUGIN_ID ,
235- {
236- path : `#${
237- pagePathGetters . policy_details ( {
238- policyId : agentPolicyIdFromContext ,
239- } ) [ 1 ]
240- } `,
241- } ,
242- ] ;
243- } else {
244- redirectToPath = [
245- INTEGRATIONS_PLUGIN_ID ,
246- {
247- path : currentPath ,
248- } ,
249- ] ;
250- }
251-
252- const redirectBackRouteState : CreatePackagePolicyRouteState = {
253- onSaveNavigateTo : redirectToPath ,
254- onCancelNavigateTo : redirectToPath ,
255- onCancelUrl : currentPath ,
256- } ;
257-
258211 services . application . navigateToApp ( PLUGIN_ID , {
259212 // Necessary because of Fleet's HashRouter. Can be changed when
260213 // https://github.com/elastic/kibana/issues/96134 is resolved
261214 path : `#${ path } ` ,
262- state : redirectBackRouteState ,
263215 } ) ;
264216 } ,
265- [
266- history ,
267- hash ,
268- pathname ,
269- search ,
270- pkgkey ,
271- integration ,
272- services . application ,
273- agentPolicyIdFromContext ,
274- ]
217+ [ pkgkey , integration , services . application , agentPolicyIdFromContext ]
275218 ) ;
276219
277220 const headerRightContent = useMemo (
0 commit comments