-
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
[Actionable Observability] Expose ObservabilityAlertSearchBar from Observability plugin #146401
Changes from all commits
4e96f35
b693b11
f937182
5489109
6b2b4c1
7275cc6
307af94
a86b076
66d173d
a52525b
03598cc
cbc898e
5aa3496
d785a1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,15 @@ | |
*/ | ||
|
||
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
|
||
import React, { useCallback, useEffect } from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { Query } from '@kbn/es-query'; | ||
import { useKibana } from '../../../utils/kibana_react'; | ||
import { observabilityAlertFeatureIds } from '../../../config'; | ||
import { ObservabilityAppServices } from '../../../application/types'; | ||
import { useServices } from './services'; | ||
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. What benefit does it have to introduce a new 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. Since this component will be used in another plugin, we don't know if they have all the related dependencies defined in their plugin as this shared component needs. |
||
import { AlertsStatusFilter } from './components'; | ||
import { observabilityAlertFeatureIds } from '../../../config'; | ||
import { ALERT_STATUS_QUERY, DEFAULT_QUERIES, DEFAULT_QUERY_STRING } from './constants'; | ||
import { AlertSearchBarProps } from './types'; | ||
import { ObservabilityAlertSearchBarProps } from './types'; | ||
import { buildEsQuery } from '../../../utils/build_es_query'; | ||
import { AlertStatus } from '../../../../common/typings'; | ||
|
||
|
@@ -27,83 +26,79 @@ const getAlertStatusQuery = (status: string): Query[] => { | |
|
||
export function ObservabilityAlertSearchBar({ | ||
appName, | ||
defaultSearchQueries = DEFAULT_QUERIES, | ||
onEsQueryChange, | ||
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. Renamed for readability |
||
onKueryChange, | ||
onRangeFromChange, | ||
onRangeToChange, | ||
onStatusChange, | ||
kuery, | ||
rangeFrom, | ||
setRangeFrom, | ||
rangeTo, | ||
setRangeTo, | ||
kuery, | ||
setKuery, | ||
status, | ||
setStatus, | ||
setEsQuery, | ||
queries = DEFAULT_QUERIES, | ||
}: AlertSearchBarProps) { | ||
const { | ||
data: { | ||
query: { | ||
timefilter: { timefilter: timeFilterService }, | ||
}, | ||
}, | ||
notifications: { toasts }, | ||
triggersActionsUi: { getAlertsSearchBar: AlertsSearchBar }, | ||
} = useKibana<ObservabilityAppServices>().services; | ||
}: ObservabilityAlertSearchBarProps) { | ||
const { AlertsSearchBar, timeFilterService, useToasts } = useServices(); | ||
const toasts = useToasts(); | ||
|
||
const onStatusChange = useCallback( | ||
const onAlertStatusChange = useCallback( | ||
(alertStatus: AlertStatus) => { | ||
setEsQuery( | ||
onEsQueryChange( | ||
buildEsQuery( | ||
{ | ||
to: rangeTo, | ||
from: rangeFrom, | ||
}, | ||
kuery, | ||
[...getAlertStatusQuery(alertStatus), ...queries] | ||
[...getAlertStatusQuery(alertStatus), ...defaultSearchQueries] | ||
) | ||
); | ||
}, | ||
[kuery, queries, rangeFrom, rangeTo, setEsQuery] | ||
[kuery, defaultSearchQueries, rangeFrom, rangeTo, onEsQueryChange] | ||
); | ||
|
||
useEffect(() => { | ||
onStatusChange(status); | ||
}, [onStatusChange, status]); | ||
onAlertStatusChange(status); | ||
}, [onAlertStatusChange, status]); | ||
|
||
const onSearchBarParamsChange = useCallback( | ||
const onSearchBarParamsChange = useCallback< | ||
(query: { | ||
dateRange: { from: string; to: string; mode?: 'absolute' | 'relative' }; | ||
query: string; | ||
}) => void | ||
>( | ||
({ dateRange, query }) => { | ||
try { | ||
// First try to create es query to make sure query is valid, then save it in state | ||
const esQuery = buildEsQuery( | ||
{ | ||
to: rangeTo, | ||
from: rangeFrom, | ||
to: dateRange.to, | ||
from: dateRange.from, | ||
}, | ||
query, | ||
[...getAlertStatusQuery(status), ...queries] | ||
[...getAlertStatusQuery(status), ...defaultSearchQueries] | ||
); | ||
setKuery(query); | ||
onKueryChange(query); | ||
timeFilterService.setTime(dateRange); | ||
setRangeFrom(dateRange.from); | ||
setRangeTo(dateRange.to); | ||
setEsQuery(esQuery); | ||
onRangeFromChange(dateRange.from); | ||
onRangeToChange(dateRange.to); | ||
maryam-saeidi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onEsQueryChange(esQuery); | ||
} catch (error) { | ||
toasts.addError(error, { | ||
title: i18n.translate('xpack.observability.alerts.searchBar.invalidQueryTitle', { | ||
defaultMessage: 'Invalid query string', | ||
}), | ||
}); | ||
setKuery(DEFAULT_QUERY_STRING); | ||
onKueryChange(DEFAULT_QUERY_STRING); | ||
clintandrewhall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}, | ||
[ | ||
defaultSearchQueries, | ||
timeFilterService, | ||
setRangeFrom, | ||
setRangeTo, | ||
setKuery, | ||
setEsQuery, | ||
rangeTo, | ||
rangeFrom, | ||
onRangeFromChange, | ||
onRangeToChange, | ||
onKueryChange, | ||
onEsQueryChange, | ||
status, | ||
queries, | ||
toasts, | ||
] | ||
); | ||
|
@@ -124,15 +119,13 @@ export function ObservabilityAlertSearchBar({ | |
<EuiFlexItem> | ||
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<AlertsStatusFilter | ||
status={status} | ||
onChange={(id) => { | ||
setStatus(id as AlertStatus); | ||
}} | ||
/> | ||
<AlertsStatusFilter status={status} onChange={onStatusChange} /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ObservabilityAlertSearchBar; |
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 added
getAlertsSearchBar
to the TriggerActionsUI mock over here. So you might not need to reintroduce this here.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.
But this one is mocking
useServices
notuseKibana
, and I also want to check the related props, so I defined the mock here.