Skip to content

Commit

Permalink
119061 refactor observability (elastic#119211)
Browse files Browse the repository at this point in the history
* group containers and components, create index files
  • Loading branch information
ersin-erdal authored and TinLe committed Dec 22, 2021
1 parent 777470c commit e88f1ca
Show file tree
Hide file tree
Showing 35 changed files with 171 additions and 86 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/observability/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export {
METRIC_TYPE,
} from './hooks/use_track_metric';

export const LazyAlertsFlyout = lazy(() => import('./pages/alerts/alerts_flyout'));
export const LazyAlertsFlyout = lazy(
() => import('./pages/alerts/components/alerts_flyout/alerts_flyout')
);
export { useFetcher, FETCH_STATUS } from './hooks/use_fetcher';
export { useEsSearch, createEsParams } from './hooks/use_es_search';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import { ALERT_UUID } from '@kbn/rule-data-utils/technical_field_names';
import React, { ComponentType } from 'react';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { PluginContext, PluginContextValue } from '../../../context/plugin_context';
import { createObservabilityRuleTypeRegistryMock } from '../../../rules/observability_rule_type_registry_mock';
import { apmAlertResponseExample } from '../example_data';
import { AlertsFlyout } from './';
import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public';
import { PluginContext, PluginContextValue } from '../../../../context/plugin_context';
import { createObservabilityRuleTypeRegistryMock } from '../../../../rules/observability_rule_type_registry_mock';
import { apmAlertResponseExample } from './example_data';
import { AlertsFlyout } from '..';

interface Args {
alerts: Array<Record<string, unknown>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

import React from 'react';
import * as useUiSettingHook from '../../../../../../../src/plugins/kibana_react/public/ui_settings/use_ui_setting';
import { createObservabilityRuleTypeRegistryMock } from '../../../rules/observability_rule_type_registry_mock';
import { render } from '../../../utils/test_helper';
import type { TopAlert } from '../';
import { AlertsFlyout } from './';
import * as useUiSettingHook from '../../../../../../../../src/plugins/kibana_react/public/ui_settings/use_ui_setting';
import { createObservabilityRuleTypeRegistryMock } from '../../../../rules/observability_rule_type_registry_mock';
import { render } from '../../../../utils/test_helper';
import type { TopAlert } from '../../containers/alerts_page';
import { AlertsFlyout } from '..';

describe('AlertsFlyout', () => {
jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import {
} from '@kbn/rule-data-utils/alerts_as_data_status';
import moment from 'moment-timezone';
import React, { useMemo } from 'react';
import type { TopAlert } from '../';
import { useKibana, useUiSetting } from '../../../../../../../src/plugins/kibana_react/public';
import { asDuration } from '../../../../common/utils/formatters';
import type { ObservabilityRuleTypeRegistry } from '../../../rules/create_observability_rule_type_registry';
import type { TopAlert } from '../../containers';
import { useKibana, useUiSetting } from '../../../../../../../../src/plugins/kibana_react/public';
import { asDuration } from '../../../../../common/utils/formatters';
import type { ObservabilityRuleTypeRegistry } from '../../../../rules/create_observability_rule_type_registry';
import { parseAlert } from '../parse_alert';
import { AlertStatusIndicator } from '../../../components/shared/alert_status_indicator';
import { ExperimentalBadge } from '../../../components/shared/experimental_badge';
import { translations, paths } from '../../../config';
import { AlertStatusIndicator } from '../../../../components/shared/alert_status_indicator';
import { ExperimentalBadge } from '../../../../components/shared/experimental_badge';
import { translations, paths } from '../../../../config';

type AlertsFlyoutProps = {
alert?: TopAlert;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { AlertsFlyout } from './alerts_flyout';
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { IndexPatternBase } from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import React, { useMemo, useState } from 'react';
import { SearchBar, TimeHistory } from '../../../../../../src/plugins/data/public';
import { Storage } from '../../../../../../src/plugins/kibana_utils/public';
import { SearchBar, TimeHistory } from '../../../../../../../src/plugins/data/public';
import { Storage } from '../../../../../../../src/plugins/kibana_utils/public';

export function AlertsSearchBar({
dynamicIndexPatterns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
ALERT_STATUS_RECOVERED,
} from '@kbn/rule-data-utils/alerts_as_data_status';
import { ALERT_STATUS } from '@kbn/rule-data-utils/technical_field_names';
import { AlertStatusFilterButton } from '../../../common/typings';
import { AlertStatusFilter } from '../../../common/typings';
import { AlertStatusFilterButton } from '../../../../common/typings';
import { AlertStatusFilter } from '../../../../common/typings';

export interface AlertStatusFilterProps {
status: AlertStatusFilterButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { getMappedNonEcsValue } from './render_cell_value';
import FilterForValueButton from './filter_for_value';
import { TimelineNonEcsData } from '../../../../timelines/common/search_strategy';
import { TGridCellAction } from '../../../../timelines/common/types/timeline';
import { getPageRowIndex } from '../../../../timelines/public';
import { TimelineNonEcsData } from '../../../../../timelines/common/search_strategy';
import { TGridCellAction } from '../../../../../timelines/common/types/timeline';
import { getPageRowIndex } from '../../../../../timelines/public';

export const FILTER_FOR_VALUE = i18n.translate('xpack.observability.hoverActions.filterForValue', {
defaultMessage: 'Filter for value',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 * from './alerts_flyout';
export * from './render_cell_value';
export * from './severity_badge';
export * from './workflow_status_filter';
export * from './alerts_search_bar';
export * from './alerts_disclaimer';
export * from './default_cell_actions';
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 @@ -12,10 +12,10 @@ import {
ALERT_RULE_NAME,
} from '@kbn/rule-data-utils/technical_field_names';
import { ALERT_STATUS_ACTIVE } from '@kbn/rule-data-utils/alerts_as_data_status';
import type { TopAlert } from '.';
import { parseTechnicalFields } from '../../../../rule_registry/common/parse_technical_fields';
import { asDuration, asPercent } from '../../../common/utils/formatters';
import { ObservabilityRuleTypeRegistry } from '../../rules/create_observability_rule_type_registry';
import type { TopAlert } from '../';
import { parseTechnicalFields } from '../../../../../rule_registry/common/parse_technical_fields';
import { asDuration, asPercent } from '../../../../common/utils/formatters';
import { ObservabilityRuleTypeRegistry } from '../../../rules/create_observability_rule_type_registry';

export const parseAlert =
(observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { getRenderCellValue, getMappedNonEcsValue } from './render_cell_value';
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
ALERT_STATUS_RECOVERED,
} from '@kbn/rule-data-utils/alerts_as_data_status';
import { ALERT_STATUS } from '@kbn/rule-data-utils/technical_field_names';
import type { CellValueElementProps } from '../../../../timelines/common';
import { createObservabilityRuleTypeRegistryMock } from '../../rules/observability_rule_type_registry_mock';
import * as PluginHook from '../../hooks/use_plugin_context';
import { render } from '../../utils/test_helper';
import type { CellValueElementProps } from '../../../../../../timelines/common';
import { createObservabilityRuleTypeRegistryMock } from '../../../../rules/observability_rule_type_registry_mock';
import * as PluginHook from '../../../../hooks/use_plugin_context';
import { render } from '../../../../utils/test_helper';
import { getRenderCellValue } from './render_cell_value';

interface AlertsTableRow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
ALERT_STATUS_ACTIVE,
ALERT_STATUS_RECOVERED,
} from '@kbn/rule-data-utils/alerts_as_data_status';
import type { CellValueElementProps, TimelineNonEcsData } from '../../../../timelines/common';
import { AlertStatusIndicator } from '../../components/shared/alert_status_indicator';
import { TimestampTooltip } from '../../components/shared/timestamp_tooltip';
import { asDuration } from '../../../common/utils/formatters';
import { SeverityBadge } from './severity_badge';
import { TopAlert } from '.';
import { parseAlert } from './parse_alert';
import { usePluginContext } from '../../hooks/use_plugin_context';
import type { CellValueElementProps, TimelineNonEcsData } from '../../../../../../timelines/common';
import { AlertStatusIndicator } from '../../../../components/shared/alert_status_indicator';
import { TimestampTooltip } from '../../../../components/shared/timestamp_tooltip';
import { asDuration } from '../../../../../common/utils/formatters';
import { SeverityBadge } from '../severity_badge';
import { TopAlert } from '../../';
import { parseAlert } from '../parse_alert';
import { usePluginContext } from '../../../../hooks/use_plugin_context';

export const getMappedNonEcsValue = ({
data,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { SeverityBadge } from './severity_badge';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { WorkflowStatusFilter } from './workflow_status_filter';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React, { ComponentProps, useState } from 'react';
import type { AlertWorkflowStatus } from '../../../common/typings';
import type { AlertWorkflowStatus } from '../../../../../common/typings';
import { WorkflowStatusFilter } from './workflow_status_filter';

type Args = ComponentProps<typeof WorkflowStatusFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { render } from '@testing-library/react';
import { Simulate } from 'react-dom/test-utils';
import React from 'react';
import type { AlertWorkflowStatus } from '../../../common/typings';
import type { AlertWorkflowStatus } from '../../../../../common/typings';
import { WorkflowStatusFilter } from './workflow_status_filter';

describe('StatusFilter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { EuiButtonGroup, EuiButtonGroupOptionProps } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import type { AlertWorkflowStatus } from '../../../common/typings';
import type { AlertWorkflowStatus } from '../../../../../common/typings';

export interface WorkflowStatusFilterProps {
status: AlertWorkflowStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ import useAsync from 'react-use/lib/useAsync';
import { AlertStatus } from '@kbn/rule-data-utils/alerts_as_data_status';
import { ALERT_STATUS } from '@kbn/rule-data-utils/technical_field_names';

import { AlertStatusFilterButton } from '../../../common/typings';
import { ParsedTechnicalFields } from '../../../../rule_registry/common/parse_technical_fields';
import { ExperimentalBadge } from '../../components/shared/experimental_badge';
import { useBreadcrumbs } from '../../hooks/use_breadcrumbs';
import { useFetcher } from '../../hooks/use_fetcher';
import { useHasData } from '../../hooks/use_has_data';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { useTimefilterService } from '../../hooks/use_timefilter_service';
import { callObservabilityApi } from '../../services/call_observability_api';
import { getNoDataConfig } from '../../utils/no_data_config';
import { LoadingObservability } from '../overview/loading_observability';
import { AlertsSearchBar } from './alerts_search_bar';
import { AlertsTableTGrid } from './alerts_table_t_grid';
import { Provider, alertsPageStateContainer, useAlertsPageStateContainer } from './state_container';
import { AlertStatusFilterButton } from '../../../../../common/typings';
import { ParsedTechnicalFields } from '../../../../../../rule_registry/common/parse_technical_fields';
import { ExperimentalBadge } from '../../../../components/shared/experimental_badge';
import { useBreadcrumbs } from '../../../../hooks/use_breadcrumbs';
import { useFetcher } from '../../../../hooks/use_fetcher';
import { useHasData } from '../../../../hooks/use_has_data';
import { usePluginContext } from '../../../../hooks/use_plugin_context';
import { useTimefilterService } from '../../../../hooks/use_timefilter_service';
import { callObservabilityApi } from '../../../../services/call_observability_api';
import { getNoDataConfig } from '../../../../utils/no_data_config';
import { LoadingObservability } from '../../../overview/loading_observability';
import { AlertsTableTGrid } from '../alerts_table_t_grid';
import {
Provider,
alertsPageStateContainer,
useAlertsPageStateContainer,
} from '../state_container';
import './styles.scss';
import { AlertsStatusFilter } from './alerts_status_filter';
import { AlertsDisclaimer } from './alerts_disclaimer';
import { AlertsStatusFilter, AlertsDisclaimer, AlertsSearchBar } from '../../components';

export interface TopAlert {
fields: ParsedTechnicalFields;
Expand Down Expand Up @@ -243,12 +245,10 @@ function AlertsPage() {
);
}

function WrappedAlertsPage() {
export function WrappedAlertsPage() {
return (
<Provider value={alertsPageStateContainer}>
<AlertsPage />
</Provider>
);
}

export { WrappedAlertsPage as AlertsPage };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { WrappedAlertsPage as AlertsPage } from './alerts_page';
export type { TopAlert } from './alerts_page';
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ import styled from 'styled-components';
import React, { Suspense, useMemo, useState, useCallback, useEffect } from 'react';
import usePrevious from 'react-use/lib/usePrevious';
import { pick } from 'lodash';
import { getAlertsPermissions } from '../../hooks/use_alert_permission';
import { getAlertsPermissions } from '../../../../hooks/use_alert_permission';
import type {
TimelinesUIStart,
TGridType,
TGridState,
TGridModel,
SortDirection,
} from '../../../../timelines/public';
} from '../../../../../../timelines/public';

import type { TopAlert } from './';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import type { TopAlert } from '../alerts_page/alerts_page';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import type {
ActionProps,
AlertWorkflowStatus,
ColumnHeaderOptions,
ControlColumnProps,
RowRenderer,
} from '../../../../timelines/common';

import { getRenderCellValue } from './render_cell_value';
import { observabilityAppId, observabilityFeatureId } from '../../../common';
import { useGetUserCasesPermissions } from '../../hooks/use_get_user_cases_permissions';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { LazyAlertsFlyout } from '../..';
import { parseAlert } from './parse_alert';
import { CoreStart } from '../../../../../../src/core/public';
import { translations, paths } from '../../config';
} from '../../../../../../timelines/common';

import { getRenderCellValue } from '../../components/render_cell_value';
import { observabilityAppId, observabilityFeatureId } from '../../../../../common';
import { useGetUserCasesPermissions } from '../../../../hooks/use_get_user_cases_permissions';
import { usePluginContext } from '../../../../hooks/use_plugin_context';
import { LazyAlertsFlyout } from '../../../..';
import { parseAlert } from '../../components/parse_alert';
import { CoreStart } from '../../../../../../../../src/core/public';
import { translations, paths } from '../../../../config';

const ALERT_TABLE_STATE_STORAGE_KEY = 'xpack.observability.alert.tableState';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { AlertsTableTGrid } from './alerts_table_t_grid';
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 * from './alerts_page';
export * from './alerts_table_t_grid';
export * from './state_container';
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import {
createStateContainer,
createStateContainerReactHelpers,
} from '../../../../../../../src/plugins/kibana_utils/public';
import type { AlertWorkflowStatus } from '../../../../common/typings';
} from '../../../../../../../../src/plugins/kibana_utils/public';
import type { AlertWorkflowStatus } from '../../../../../common/typings';

interface AlertsPageContainerState {
rangeFrom: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import { useEffect } from 'react';
import { useHistory } from 'react-router-dom';

import { TimefilterContract } from '../../../../../../../src/plugins/data/public';
import { TimefilterContract } from '../../../../../../../../src/plugins/data/public';
import {
createKbnUrlStateStorage,
syncState,
IKbnUrlStateStorage,
useContainerSelector,
} from '../../../../../../../src/plugins/kibana_utils/public';
import { useTimefilterService } from '../../../hooks/use_timefilter_service';
} from '../../../../../../../../src/plugins/kibana_utils/public';
import { useTimefilterService } from '../../../../hooks/use_timefilter_service';

import {
useContainer,
Expand Down
Loading

0 comments on commit e88f1ca

Please sign in to comment.