-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Sourcerer] Maintain url sync support #221737
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dd3fa13
[Security Solution][Sourcerer] Maintain url support identical to curr…
lgestc 60f8cbe
add tests
lgestc 48390a2
add test
lgestc ace375e
Merge branch 'main' into support_url_sync
lgestc 7bee5f8
fix url sync for timelines
lgestc 2acf7c3
fix broken test
lgestc b79b8cf
modify init flow for the data view plugin to use url state
lgestc 0b6839b
url management improvements
lgestc a23e19a
fix tests
lgestc 63c47a4
Merge branch 'main' into support_url_sync
lgestc 274e239
fixes
lgestc 13e37ff
cancellable tasks for loading data views
lgestc 2a26aa5
update tests
lgestc 2f67cd5
add one more test
lgestc 15e176f
update tests
lgestc 1e70b8e
types
lgestc 23621a4
fix tests
lgestc 89fe57c
fix duplicated condition
lgestc 449fef7
rename ref
lgestc 21f6db8
Merge branch 'main' into support_url_sync
lgestc 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 hidden or 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
21 changes: 21 additions & 0 deletions
21
x-pack/solutions/security/plugins/security_solution/public/common/hooks/constants.ts
This file contains hidden or 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,21 @@ | ||
| /* | ||
| * 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 const URL_PARAM_KEY = { | ||
| appQuery: 'query', | ||
| /** @deprecated */ | ||
| eventFlyout: 'eventFlyout', // TODO remove when we assume it's been long enough that all users should use the newer `flyout` key | ||
| flyout: 'flyout', | ||
| timelineFlyout: 'timelineFlyout', | ||
| filters: 'filters', | ||
| savedQuery: 'savedQuery', | ||
| sourcerer: 'sourcerer', | ||
| timeline: 'timeline', | ||
| timerange: 'timerange', | ||
| pageFilter: 'pageFilters', | ||
| rulesTable: 'rulesTable', | ||
| } as const; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,17 +10,19 @@ import React, { useCallback, useRef, useMemo, memo } from 'react'; | |
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
|
||
| import { DataView } from '@kbn/data-views-plugin/public'; | ||
| import type { DataViewManagerScopeName } from '../../constants'; | ||
| import type { SourcererUrlState } from '../../../sourcerer/store/model'; | ||
| import { useUpdateUrlParam } from '../../../common/utils/global_query_string'; | ||
| import { URL_PARAM_KEY } from '../../../common/hooks/use_url_state'; | ||
| import { useKibana } from '../../../common/lib/kibana'; | ||
| import { DEFAULT_SECURITY_SOLUTION_DATA_VIEW_ID } from '../../constants'; | ||
| import { useDataViewSpec } from '../../hooks/use_data_view_spec'; | ||
| import { sharedStateSelector } from '../../redux/selectors'; | ||
| import { sharedDataViewManagerSlice } from '../../redux/slices'; | ||
| import { useSelectDataView } from '../../hooks/use_select_data_view'; | ||
| import { DATA_VIEW_PICKER_TEST_ID } from './constants'; | ||
| import { DataViewManagerScopeName, DEFAULT_SECURITY_SOLUTION_DATA_VIEW_ID } from '../../constants'; | ||
| import { useManagedDataViews } from '../../hooks/use_managed_data_views'; | ||
| import { useSavedDataViews } from '../../hooks/use_saved_data_views'; | ||
| import { DEFAULT_SECURITY_DATA_VIEW, LOADING } from './translations'; | ||
| import { DATA_VIEW_PICKER_TEST_ID } from './constants'; | ||
|
|
||
| interface DataViewPickerProps { | ||
| /** | ||
|
|
@@ -49,24 +51,43 @@ export const DataViewPicker = memo(({ scope, onClosePopover, disabled }: DataVie | |
|
|
||
| const { dataViewSpec, status } = useDataViewSpec(scope); | ||
|
|
||
| const isDefaultSourcerer = scope === DataViewManagerScopeName.default; | ||
| const updateUrlParam = useUpdateUrlParam<SourcererUrlState>(URL_PARAM_KEY.sourcerer); | ||
|
|
||
| const dataViewId = dataViewSpec?.id; | ||
|
|
||
| // NOTE: this function is called in response to user interaction with the picker, | ||
| // hence - it is the only place where we should update the url param for the data view selection. | ||
| const handleChangeDataView = useCallback( | ||
| (id: string, indexPattern: string = '') => { | ||
| selectDataView({ id, scope }); | ||
|
|
||
| if (isDefaultSourcerer) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, but |
||
| updateUrlParam({ | ||
| [DataViewManagerScopeName.default]: { | ||
| id, | ||
| // NOTE: Boolean filter for removing empty patterns | ||
| selectedPatterns: indexPattern.split(',').filter(Boolean), | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
| [isDefaultSourcerer, scope, selectDataView, updateUrlParam] | ||
| ); | ||
|
|
||
| const createNewDataView = useCallback(() => { | ||
| closeDataViewEditor.current = dataViewEditor.openEditor({ | ||
| onSave: async (newDataView) => { | ||
| if (!newDataView.id) { | ||
| return; | ||
| } | ||
|
|
||
| dispatch(sharedDataViewManagerSlice.actions.addDataView(newDataView)); | ||
| selectDataView({ id: newDataView.id, scope: [scope] }); | ||
| handleChangeDataView(newDataView.id, newDataView.getIndexPattern()); | ||
| }, | ||
| allowAdHocDataView: true, | ||
| }); | ||
| }, [dataViewEditor, dispatch, scope, selectDataView]); | ||
|
|
||
| const handleChangeDataView = useCallback( | ||
| (id: string) => { | ||
| selectDataView({ id, scope: [scope] }); | ||
| }, | ||
| [scope, selectDataView] | ||
| ); | ||
| }, [dataViewEditor, dispatch, handleChangeDataView]); | ||
|
|
||
| const editField = useCallback( | ||
| async (fieldName?: string, _uiAction: 'edit' | 'add' = 'edit') => { | ||
|
|
@@ -86,7 +107,7 @@ export const DataViewPicker = memo(({ scope, onClosePopover, disabled }: DataVie | |
| return; | ||
| } | ||
|
|
||
| handleChangeDataView(dataViewInstance.id); | ||
| handleChangeDataView(dataViewInstance.id, dataViewInstance.getIndexPattern()); | ||
| }, | ||
| }); | ||
| }, | ||
|
|
@@ -98,9 +119,12 @@ export const DataViewPicker = memo(({ scope, onClosePopover, disabled }: DataVie | |
| */ | ||
| const handleDataViewModified = useCallback( | ||
| (updatedDataView: DataView) => { | ||
| selectDataView({ id: updatedDataView.id, scope: [scope] }); | ||
| if (!updatedDataView.id) { | ||
| return; | ||
| } | ||
| handleChangeDataView(updatedDataView.id, updatedDataView.getIndexPattern()); | ||
| }, | ||
| [scope, selectDataView] | ||
| [handleChangeDataView] | ||
| ); | ||
|
|
||
| const handleAddField = useCallback(() => editField(undefined, 'add'), [editField]); | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
@PhilippeOberti,do we have telemetry?
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.
hmmm I know we added telemetry when users open the flyout, but I don't think it logs what's in the url. Can't we just retrieve url information from Kibana telemetry? We should be able to query and see if any of the url we log contain the
eventFlyoutparam?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.
Not related to this PR I think but I can remove it if you want.
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.
Yea, unrelated, but didn't want this to stay in forever. No need to remove here, just wanted to call attention to it so we could remove it later