-
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.
[Actionable Observability] Move the alerts search bar to triggers act…
…ion UI plugin (#144541) * Move alerts search bar to triggers action use package * Fix useAlertDataView test * Fix mocks for useAlertDataView test * Fix type issue and add getAlertsSearchBar mock
- Loading branch information
1 parent
8ed9d82
commit 4d46bd7
Showing
18 changed files
with
174 additions
and
92 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
66 changes: 0 additions & 66 deletions
66
x-pack/plugins/observability/public/pages/alerts/components/alerts_search_bar.tsx
This file was deleted.
Oops, something went wrong.
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
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
62 changes: 62 additions & 0 deletions
62
...s/triggers_actions_ui/public/application/sections/alerts_search_bar/alerts_search_bar.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,62 @@ | ||
/* | ||
* 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 React, { useCallback, useState } from 'react'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { NO_INDEX_PATTERNS } from './constants'; | ||
import { SEARCH_BAR_PLACEHOLDER } from './translations'; | ||
import { AlertsSearchBarProps, QueryLanguageType } from './types'; | ||
import { useAlertDataView } from '../../hooks/use_alert_data_view'; | ||
import { TriggersAndActionsUiServices } from '../../..'; | ||
|
||
// TODO Share buildEsQuery to be used between AlertsSearchBar and AlertsStateTable component https://github.com/elastic/kibana/issues/144615 | ||
export function AlertsSearchBar({ | ||
appName, | ||
featureIds, | ||
query, | ||
onQueryChange, | ||
rangeFrom, | ||
rangeTo, | ||
}: AlertsSearchBarProps) { | ||
const { | ||
unifiedSearch: { | ||
ui: { SearchBar }, | ||
}, | ||
} = useKibana<TriggersAndActionsUiServices>().services; | ||
|
||
const [queryLanguage, setQueryLanguage] = useState<QueryLanguageType>('kuery'); | ||
const { value: dataView, loading, error } = useAlertDataView(featureIds); | ||
|
||
const onQuerySubmit = useCallback( | ||
(payload) => { | ||
const { dateRange, query: nextQuery } = payload; | ||
onQueryChange({ | ||
dateRange, | ||
query: typeof nextQuery?.query === 'string' ? nextQuery.query : '', | ||
}); | ||
setQueryLanguage((nextQuery?.language ?? 'kuery') as QueryLanguageType); | ||
}, | ||
[onQueryChange, setQueryLanguage] | ||
); | ||
|
||
return ( | ||
<SearchBar | ||
appName={appName} | ||
indexPatterns={loading || error ? NO_INDEX_PATTERNS : [dataView!]} | ||
placeholder={SEARCH_BAR_PLACEHOLDER} | ||
query={{ query: query ?? '', language: queryLanguage }} | ||
dateRangeFrom={rangeFrom} | ||
dateRangeTo={rangeTo} | ||
displayStyle="inPage" | ||
showFilterBar={false} | ||
onQuerySubmit={onQuerySubmit} | ||
/> | ||
); | ||
} | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { AlertsSearchBar as default }; |
10 changes: 10 additions & 0 deletions
10
...ck/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/constants.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,10 @@ | ||
/* | ||
* 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 { DataView } from '@kbn/data-views-plugin/common'; | ||
|
||
export const NO_INDEX_PATTERNS: DataView[] = []; |
10 changes: 10 additions & 0 deletions
10
x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/index.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,10 @@ | ||
/* | ||
* 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 { AlertsSearchBar } from './alerts_search_bar'; | ||
|
||
export type { AlertsSearchBarProps } from './types'; |
15 changes: 15 additions & 0 deletions
15
...plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/translations.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,15 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const SEARCH_BAR_PLACEHOLDER = i18n.translate( | ||
'xpack.triggersActionsUI.alertsSearchBar.placeholder', | ||
{ | ||
defaultMessage: 'Search alerts (e.g. kibana.alert.evaluation.threshold > 75)', | ||
} | ||
); |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/types.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,22 @@ | ||
/* | ||
* 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 { ValidFeatureId } from '@kbn/rule-data-utils'; | ||
|
||
export type QueryLanguageType = 'lucene' | 'kuery'; | ||
|
||
export interface AlertsSearchBarProps { | ||
appName: string; | ||
featureIds: ValidFeatureId[]; | ||
rangeFrom?: string; | ||
rangeTo?: string; | ||
query?: string; | ||
onQueryChange: ({}: { | ||
dateRange: { from: string; to: string; mode?: 'absolute' | 'relative' }; | ||
query?: string; | ||
}) => void; | ||
} |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/triggers_actions_ui/public/common/get_alerts_search_bar.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,20 @@ | ||
/* | ||
* 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 { EuiLoadingSpinner } from '@elastic/eui'; | ||
import React, { lazy, Suspense } from 'react'; | ||
import type { AlertsSearchBarProps } from '../application/sections/alerts_search_bar'; | ||
|
||
const AlertsSearchBarLazy: React.FC<AlertsSearchBarProps> = lazy( | ||
() => import('../application/sections/alerts_search_bar/alerts_search_bar') | ||
); | ||
|
||
export const getAlertsSearchBarLazy = (props: AlertsSearchBarProps) => ( | ||
<Suspense fallback={<EuiLoadingSpinner />}> | ||
<AlertsSearchBarLazy {...props} /> | ||
</Suspense> | ||
); |
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.