-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fleet[ Allow to specify a datastream id in the edit integration page #135321
Merged
nchaulet
merged 5 commits into
elastic:main
from
nchaulet:feature-edit-integration-allow-datastream-id
Jun 30, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c3822a7
[Fleet[ Allow to specify a datastream id in the edit integration page
nchaulet 94946f7
fix history
nchaulet dcff25a
add step on edit mapping
nchaulet 52624a7
Add unit tests
nchaulet b0ae9f1
Merge branch 'main' into feature-edit-integration-allow-datastream-id
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
54 changes: 54 additions & 0 deletions
54
...eet/sections/agent_policy/create_package_policy_page/components/datastream_hooks.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,54 @@ | ||
/* | ||
* 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 { useRouteMatch } from 'react-router-dom'; | ||
|
||
import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
|
||
import { usePackagePolicyEditorPageUrl } from './datastream_hooks'; | ||
|
||
const mockedUseRouteMatch = useRouteMatch as jest.MockedFunction<typeof useRouteMatch>; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useRouteMatch: jest.fn(), | ||
})); | ||
|
||
describe('usePackagePolicyEditorPageUrl', () => { | ||
it('should render an integration url if no policy id is provided', () => { | ||
const renderer = createFleetTestRendererMock(); | ||
mockedUseRouteMatch.mockReturnValue({ | ||
params: { packagePolicyId: 'test-package-policy-id' }, | ||
} as any); | ||
const { result } = renderer.renderHook(() => usePackagePolicyEditorPageUrl()); | ||
expect(result.current).toBe('/mock/app/integrations/edit-integration/test-package-policy-id'); | ||
}); | ||
|
||
it('should render a fleet url if a policy id is provided', () => { | ||
const renderer = createFleetTestRendererMock(); | ||
mockedUseRouteMatch.mockReturnValue({ | ||
params: { policyId: 'policy1', packagePolicyId: 'test-package-policy-id' }, | ||
} as any); | ||
const { result } = renderer.renderHook(() => usePackagePolicyEditorPageUrl()); | ||
expect(result.current).toBe( | ||
'/mock/app/fleet/policies/policy1/edit-integration/test-package-policy-id' | ||
); | ||
}); | ||
|
||
it('should add datastream Id if provided', () => { | ||
const renderer = createFleetTestRendererMock(); | ||
mockedUseRouteMatch.mockReturnValue({ | ||
params: { policyId: 'policy1', packagePolicyId: 'test-package-policy-id' }, | ||
} as any); | ||
const { result } = renderer.renderHook(() => | ||
usePackagePolicyEditorPageUrl('test-datastream-id') | ||
); | ||
expect(result.current).toBe( | ||
'/mock/app/fleet/policies/policy1/edit-integration/test-package-policy-id?datastreamId=test-datastream-id' | ||
); | ||
}); | ||
}); |
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
18 changes: 18 additions & 0 deletions
18
...et/sections/agent_policy/create_package_policy_page/components/steps/components/hooks.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,18 @@ | ||
/* | ||
* 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 { useMemo } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
export function useDataStreamId() { | ||
const history = useHistory(); | ||
|
||
return useMemo(() => { | ||
const searchParams = new URLSearchParams(history.location.search); | ||
return searchParams.get('datastreamId') ?? undefined; | ||
}, [history.location.search]); | ||
} |
61 changes: 61 additions & 0 deletions
61
...reate_package_policy_page/components/steps/components/package_policy_input_panel.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,61 @@ | ||
/* | ||
* 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 { shouldShowStreamsByDefault } from './package_policy_input_panel'; | ||
|
||
describe('shouldShowStreamsByDefault', () => { | ||
it('should return true if a datastreamId is provided and contained in the input', () => { | ||
const res = shouldShowStreamsByDefault( | ||
{} as any, | ||
[], | ||
{ | ||
enabled: true, | ||
streams: [ | ||
{ | ||
id: 'datastream-id', | ||
}, | ||
], | ||
} as any, | ||
'datastream-id' | ||
); | ||
expect(res).toBeTruthy(); | ||
}); | ||
|
||
it('should return false if a datastreamId is provided but not contained in the input', () => { | ||
const res = shouldShowStreamsByDefault( | ||
{} as any, | ||
[], | ||
{ | ||
enabled: true, | ||
streams: [ | ||
{ | ||
id: 'datastream-1', | ||
}, | ||
], | ||
} as any, | ||
'datastream-id' | ||
); | ||
expect(res).toBeFalsy(); | ||
}); | ||
|
||
it('should return false if a datastreamId is provided but the input is disabled', () => { | ||
const res = shouldShowStreamsByDefault( | ||
{} as any, | ||
[], | ||
{ | ||
enabled: false, | ||
streams: [ | ||
{ | ||
id: 'datastream-id', | ||
}, | ||
], | ||
} as any, | ||
'datastream-id' | ||
); | ||
expect(res).toBeFalsy(); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to add some unit tests on the url building logic