-
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
Add a flyout to alert list. #57926
Merged
Merged
Add a flyout to alert list. #57926
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
07e448d
add a flyout
e7c891c
Removing TODOs, added issue
3d6f4ab
Rename `queryParams` selector
4aeeba7
Removing TODOs, added issue
6340270
Removed TODOs, added issue
26c3ca6
Removed sample code
09fe7dc
DO IT
517d796
return alerts from alert api.
dc98ea0
remove copy paste
f2847b4
Fix query builder test
7d18af0
GO FOR IT
9686b88
add tests
b5ce863
use davis technique
eb25f76
add tests that test it
daafb55
use currentTarget cause candace said so
0d67dad
use react router link. its an actual link, and its easier to test w/ …
26a5ac2
rewrite the tests
60db616
remove todos
66c4590
Add comments
5a30168
remove snapshot as it was not stable (relied on timezone)
626e2fb
respect existing query params when opening or closing flyouyt
5b78baf
pedro
dbffe17
DO IT
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import { | |
import { i18n } from '@kbn/i18n'; | ||
import { useHistory, Link } from 'react-router-dom'; | ||
import { FormattedDate } from 'react-intl'; | ||
import { urlFromQueryParams } from './url_from_query_params'; | ||
import { AlertData } from '../../../../../common/types'; | ||
import * as selectors from '../../store/alerts/selectors'; | ||
import { useAlertListSelector } from './hooks/use_alerts_selector'; | ||
|
@@ -82,28 +83,39 @@ export const AlertIndex = memo(() => { | |
}, []); | ||
|
||
const { pageIndex, pageSize, total } = useAlertListSelector(selectors.alertListPagination); | ||
const urlFromNewPageSizeParam = useAlertListSelector(selectors.urlFromNewPageSizeParam); | ||
const urlWithSelectedAlert = useAlertListSelector(selectors.urlWithSelectedAlert); | ||
const urlWithoutSelectedAlert = useAlertListSelector(selectors.urlWithoutSelectedAlert); | ||
const urlFromNewPageIndexParam = useAlertListSelector(selectors.urlFromNewPageIndexParam); | ||
const alertListData = useAlertListSelector(selectors.alertListData); | ||
const hasSelectedAlert = useAlertListSelector(selectors.hasSelectedAlert); | ||
const queryParams = useAlertListSelector(selectors.uiQueryParams); | ||
|
||
const onChangeItemsPerPage = useCallback( | ||
newPageSize => history.push(urlFromNewPageSizeParam(newPageSize)), | ||
[history, urlFromNewPageSizeParam] | ||
newPageSize => { | ||
const newQueryParms = { ...queryParams }; | ||
newQueryParms.page_size = newPageSize; | ||
delete newQueryParms.page_index; | ||
const relativeURL = urlFromQueryParams(newQueryParms); | ||
return history.push(relativeURL); | ||
}, | ||
[history, queryParams] | ||
); | ||
|
||
const onChangePage = useCallback( | ||
newPageIndex => history.push(urlFromNewPageIndexParam(newPageIndex)), | ||
[history, urlFromNewPageIndexParam] | ||
newPageIndex => { | ||
return history.push( | ||
urlFromQueryParams({ | ||
...queryParams, | ||
page_index: newPageIndex, | ||
}) | ||
); | ||
}, | ||
[history, queryParams] | ||
); | ||
|
||
const [visibleColumns, setVisibleColumns] = useState(() => columns.map(({ id }) => id)); | ||
|
||
const handleFlyoutClose = useCallback(() => { | ||
history.push(urlWithoutSelectedAlert); | ||
}, [history, urlWithoutSelectedAlert]); | ||
const { selected_alert, ...paramsWithoutSelectedAlert } = queryParams; | ||
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. are we doing url params in snake case? is that the convention? i forget... 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. |
||
history.push(urlFromQueryParams(paramsWithoutSelectedAlert)); | ||
}, [history, queryParams]); | ||
|
||
const datesForRows: Map<AlertData, Date> = useMemo(() => { | ||
return new Map( | ||
|
@@ -123,7 +135,10 @@ export const AlertIndex = memo(() => { | |
|
||
if (columnId === 'alert_type') { | ||
return ( | ||
<Link data-testid="alertTypeCellLink" to={urlWithSelectedAlert('TODO')}> | ||
<Link | ||
data-testid="alertTypeCellLink" | ||
to={urlFromQueryParams({ ...queryParams, selected_alert: 'TODO' })} | ||
> | ||
{i18n.translate( | ||
'xpack.endpoint.application.endpoint.alerts.alertType.maliciousFileDescription', | ||
{ | ||
|
@@ -173,7 +188,7 @@ export const AlertIndex = memo(() => { | |
} | ||
return null; | ||
}; | ||
}, [alertListData, datesForRows, pageSize, total, urlWithSelectedAlert]); | ||
}, [alertListData, datesForRows, pageSize, queryParams, total]); | ||
|
||
const pagination = useMemo(() => { | ||
return { | ||
|
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/endpoint/public/applications/endpoint/view/alerts/url_from_query_params.ts
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,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import querystring from 'querystring'; | ||
import { AlertingIndexUIQueryParams } from '../../types'; | ||
|
||
/** | ||
* Return a relative URL for `AlertingIndexUIQueryParams`. | ||
* usage: | ||
* | ||
* ```ts | ||
* // Replace this with however you get state, e.g. useSelector in react | ||
* const queryParams = selectors.uiQueryParams(store.getState()) | ||
* | ||
* // same as current url, but page_index is now 3 | ||
* const relativeURL = urlFromQueryParams({ ...queryParams, page_index: 3 }) | ||
* | ||
* // now use relativeURL in the 'href' of a link, the 'to' of a react-router-dom 'Link' or history.push, history.replace | ||
* ``` | ||
*/ | ||
export function urlFromQueryParams(queryParams: AlertingIndexUIQueryParams): string { | ||
const search = querystring.stringify(queryParams); | ||
return search === '' ? '' : '?' + search; | ||
} |
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.
@paul-tavares doing something closer to what you have.
@dplumlee @peluja1012 thoughts?
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.
this works for me. maybe we should also use the same querystring package that @paul-tavares is using (
query-string
) just to keep it consistent. I think it's in kibana already and it's a bit better than the one we're usingThere 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.
@oatkiller looks good but closing the flyout doesn't seem to be working when only
selected_alert
is present. The user gets redirected to/app/endpoint/
: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.
I goofed this up. I'm working on another slight improvement, but I feel like I might just be getting in the way of stuff @paul-tavares is doing. Maybe worth syncing
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.
Fixed