Skip to content

Commit

Permalink
Move alerts search bar to triggers action use package
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi committed Nov 3, 2022
1 parent 1a1ee54 commit ad37c76
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 38 deletions.
5 changes: 0 additions & 5 deletions x-pack/plugins/observability/public/config/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,4 @@ export const translations = {
}
),
},
alertsSearchBar: {
placeholder: i18n.translate('xpack.observability.alerts.searchBarPlaceholder', {
defaultMessage: 'Search alerts (e.g. kibana.alert.evaluation.threshold > 75)',
}),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export * from './alerts_flyout';
export * from './render_cell_value';
export * from './severity_badge';
export * from './workflow_status_filter';
export * from './alerts_search_bar';
export * from './filter_for_value';
export * from './parse_alert';
export * from './alerts_status_filter';
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
useAlertsPageStateContainer,
} from '../state_container';
import './styles.scss';
import { AlertsStatusFilter, AlertsSearchBar, ALERT_STATUS_QUERY } from '../../components';
import { AlertsStatusFilter, ALERT_STATUS_QUERY } from '../../components';
import { renderRuleStats } from '../../components/rule_stats';
import { ObservabilityAppServices } from '../../../../application/types';
import { ALERTS_PER_PAGE, ALERTS_TABLE_ID } from './constants';
Expand All @@ -46,7 +46,11 @@ function AlertsPage() {
docLinks,
http,
notifications: { toasts },
triggersActionsUi: { alertsTableConfigurationRegistry, getAlertsStateTable: AlertsStateTable },
triggersActionsUi: {
alertsTableConfigurationRegistry,
getAlertsStateTable: AlertsStateTable,
getAlertsSearchBar: AlertsSearchBar,
},
data: {
query: {
timefilter: { timefilter: timeFilterService },
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
} from '@kbn/triggers-actions-ui-plugin/public';
import { SecurityPluginStart } from '@kbn/security-plugin/public';
import { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';
import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { observabilityAppId, observabilityFeatureId, casesPath } from '../common';
import { createLazyObservabilityPageTemplate } from './components/shared';
import { registerDataHandler } from './data_handler';
Expand Down Expand Up @@ -95,7 +94,6 @@ export interface ObservabilityPublicPluginsStart {
actionTypeRegistry: ActionTypeRegistryContract;
security: SecurityPluginStart;
guidedOnboarding: GuidedOnboardingPluginStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
}

export type ObservabilityPublicStart = ReturnType<Plugin['start']>;
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -23294,7 +23294,6 @@
"xpack.observability.alerts.ruleStats.loadError": "Impossible de charger les statistiques de règles",
"xpack.observability.alerts.ruleStats.muted": "Répété",
"xpack.observability.alerts.ruleStats.ruleCount": "Nombre de règles",
"xpack.observability.alerts.searchBarPlaceholder": "Alertes de recherche (par exemple, kibana.alert.evaluation.threshold > 75)",
"xpack.observability.alerts.workflowStatusFilter.acknowledgedButtonLabel": "Reconnue(s)",
"xpack.observability.alerts.workflowStatusFilter.closedButtonLabel": "Fermé",
"xpack.observability.alerts.workflowStatusFilter.openButtonLabel": "Ouvrir",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -23273,7 +23273,6 @@
"xpack.observability.alerts.ruleStats.loadError": "ルール統計情報を読み込めません",
"xpack.observability.alerts.ruleStats.muted": "スヌーズ済み",
"xpack.observability.alerts.ruleStats.ruleCount": "ルール数",
"xpack.observability.alerts.searchBarPlaceholder": "検索アラート(例:kibana.alert.evaluation.threshold > 75)",
"xpack.observability.alerts.workflowStatusFilter.acknowledgedButtonLabel": "認識",
"xpack.observability.alerts.workflowStatusFilter.closedButtonLabel": "終了",
"xpack.observability.alerts.workflowStatusFilter.openButtonLabel": "開く",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -23304,7 +23304,6 @@
"xpack.observability.alerts.ruleStats.loadError": "无法加载规则统计信息",
"xpack.observability.alerts.ruleStats.muted": "已暂停",
"xpack.observability.alerts.ruleStats.ruleCount": "规则计数",
"xpack.observability.alerts.searchBarPlaceholder": "搜索告警(例如 kibana.alert.evaluation.threshold > 75)",
"xpack.observability.alerts.workflowStatusFilter.acknowledgedButtonLabel": "已确认",
"xpack.observability.alerts.workflowStatusFilter.closedButtonLabel": "已关闭",
"xpack.observability.alerts.workflowStatusFilter.openButtonLabel": "打开",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common';
import type { ValidFeatureId } from '@kbn/rule-data-utils';
import useAsync from 'react-use/lib/useAsync';
import type { AsyncState } from 'react-use/lib/useAsync';

import { ObservabilityAppServices } from '../application/types';
import { TriggersAndActionsUiServices } from '../..';

export function useAlertDataView(featureIds: ValidFeatureId[]): AsyncState<DataView> {
const { http, data: dataService } = useKibana<ObservabilityAppServices>().services;
const { http, data: dataService } = useKibana<TriggersAndActionsUiServices>().services;
const features = featureIds.sort().join(',');

const dataView = useAsync(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
*/

import React, { useState } from 'react';
import { DataView } from '@kbn/data-views-plugin/common';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { ValidFeatureId } from '@kbn/rule-data-utils';
import { translations } from '../../../config';
import { ObservabilityAppServices } from '../../../application/types';
import { useAlertDataView } from '../../../hooks/use_alert_data_view';

type QueryLanguageType = 'lucene' | 'kuery';

const NO_INDEX_PATTERNS: DataView[] = [];
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 '../../..';

export function AlertsSearchBar({
appName,
Expand All @@ -24,22 +20,12 @@ export function AlertsSearchBar({
onQueryChange,
rangeFrom,
rangeTo,
}: {
appName: string;
featureIds: ValidFeatureId[];
rangeFrom?: string;
rangeTo?: string;
query?: string;
onQueryChange: ({}: {
dateRange: { from: string; to: string; mode?: 'absolute' | 'relative' };
query?: string;
}) => void;
}) {
}: AlertsSearchBarProps) {
const {
unifiedSearch: {
ui: { SearchBar },
},
} = useKibana<ObservabilityAppServices>().services;
} = useKibana<TriggersAndActionsUiServices>().services;

const [queryLanguage, setQueryLanguage] = useState<QueryLanguageType>('kuery');
const { value: dataView, loading, error } = useAlertDataView(featureIds);
Expand All @@ -48,7 +34,7 @@ export function AlertsSearchBar({
<SearchBar
appName={appName}
indexPatterns={loading || error ? NO_INDEX_PATTERNS : [dataView!]}
placeholder={translations.alertsSearchBar.placeholder}
placeholder={SEARCH_BAR_PLACEHOLDER}
query={{ query: query ?? '', language: queryLanguage }}
dateRangeFrom={rangeFrom}
dateRangeTo={rangeTo}
Expand All @@ -64,3 +50,6 @@ export function AlertsSearchBar({
/>
);
}

// eslint-disable-next-line import/no-default-export
export { AlertsSearchBar as default };
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[] = [];
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';
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)',
}
);
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;
}
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>
);
6 changes: 6 additions & 0 deletions x-pack/plugins/triggers_actions_ui/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import type { AlertsSearchBarProps } from './application/sections/alerts_search_bar';
import { TypeRegistry } from './application/type_registry';

import { getAddConnectorFlyoutLazy } from './common/get_add_connector_flyout';
Expand Down Expand Up @@ -72,6 +73,7 @@ import { registerAlertsTableConfiguration } from './application/sections/alerts_
import { PLUGIN_ID, CONNECTORS_PLUGIN_ID } from './common/constants';
import type { AlertsTableStateProps } from './application/sections/alerts_table/alerts_table_state';
import { getAlertsTableStateLazy } from './common/get_alerts_table_state';
import { getAlertsSearchBarLazy } from './common/get_alerts_search_bar';
import { ActionAccordionFormProps } from './application/sections/action_connector_form/action_form';
import type { FieldBrowserProps } from './application/sections/field_browser/types';
import { getRuleDefinitionLazy } from './common/get_rule_definition';
Expand Down Expand Up @@ -108,6 +110,7 @@ export interface TriggersAndActionsUIPublicPluginStart {
) => ReactElement<RuleEditProps>;
getAlertsTable: (props: AlertsTableProps) => ReactElement<AlertsTableProps>;
getAlertsStateTable: (props: AlertsTableStateProps) => ReactElement<AlertsTableStateProps>;
getAlertsSearchBar: (props: AlertsSearchBarProps) => ReactElement<AlertsSearchBarProps>;
getFieldBrowser: (props: FieldBrowserProps) => ReactElement<FieldBrowserProps>;
getRuleStatusDropdown: (props: RuleStatusDropdownProps) => ReactElement<RuleStatusDropdownProps>;
getRuleTagFilter: (props: RuleTagFilterProps) => ReactElement<RuleTagFilterProps>;
Expand Down Expand Up @@ -378,6 +381,9 @@ export class Plugin
getAlertsStateTable: (props: AlertsTableStateProps) => {
return getAlertsTableStateLazy(props);
},
getAlertsSearchBar: (props: AlertsSearchBarProps) => {
return getAlertsSearchBarLazy(props);
},
getAlertsTable: (props: AlertsTableProps) => {
return getAlertsTableLazy(props);
},
Expand Down

0 comments on commit ad37c76

Please sign in to comment.