-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest Pipeline] Provide url params to use ingestPipeline UI from Fl…
…eet (#134776)
- Loading branch information
Showing
10 changed files
with
173 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ingest_pipelines/public/application/hooks/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { useRedirectPath as useRedirectToPathOrRedirectPath } from './redirect_path'; |
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/ingest_pipelines/public/application/hooks/redirect_path.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { createMemoryHistory } from 'history'; | ||
import { useRedirectPath } from './redirect_path'; | ||
import { useKibana } from '../../shared_imports'; | ||
|
||
const mockedUseKibana = useKibana as jest.MockedFunction<typeof useKibana>; | ||
jest.mock('../../shared_imports'); | ||
|
||
describe('useRedirectPath', () => { | ||
const mockedNavigateToUrl = jest.fn(); | ||
beforeEach(() => { | ||
mockedNavigateToUrl.mockReset(); | ||
mockedUseKibana.mockReturnValue({ | ||
services: { | ||
application: { | ||
navigateToUrl: mockedNavigateToUrl, | ||
}, | ||
}, | ||
} as any); | ||
}); | ||
it('should redirect to redirect path if a redirect path is specified in the url', () => { | ||
const history = createMemoryHistory(); | ||
history.push( | ||
'/app/management/ingest/ingest_pipelines/create?name=logs-system.syslog@custom&redirect_path=/test-redirect-path' | ||
); | ||
|
||
const { | ||
result: { current: redirectToPathOrRedirectPath }, | ||
} = renderHook(() => useRedirectPath(history)); | ||
|
||
redirectToPathOrRedirectPath('/test'); | ||
|
||
expect(mockedNavigateToUrl).toBeCalledWith('/test-redirect-path'); | ||
}); | ||
|
||
it('should redirect to the provided path if no redirect path is specified in the url', () => { | ||
const history = createMemoryHistory(); | ||
history.push('/app/management/ingest/ingest_pipelines/create'); | ||
|
||
const { | ||
result: { current: redirectToPathOrRedirectPath }, | ||
} = renderHook(() => useRedirectPath(history)); | ||
|
||
redirectToPathOrRedirectPath('/test'); | ||
|
||
expect(mockedNavigateToUrl).not.toBeCalled(); | ||
expect(history.location.pathname).toBe('/test'); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/ingest_pipelines/public/application/hooks/redirect_path.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { History } from 'history'; | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
import { useKibana } from '../../shared_imports'; | ||
|
||
/** | ||
* This hook allow to redirect to the provided path or using redirect_path if it's provided in the query params. | ||
*/ | ||
export function useRedirectPath(history: History) { | ||
const { services } = useKibana(); | ||
|
||
const redirectPath = useMemo(() => { | ||
const locationSearchParams = new URLSearchParams(history.location.search); | ||
|
||
return locationSearchParams.get('redirect_path'); | ||
}, [history.location.search]); | ||
|
||
return useCallback( | ||
(path: string) => { | ||
if (redirectPath) { | ||
services.application.navigateToUrl(redirectPath); | ||
} else { | ||
history.push(path); | ||
} | ||
}, | ||
[redirectPath, services.application, history] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters