Skip to content

Commit

Permalink
[Tech Debt] Clean up /config and /components folders (#160538)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoenWarmer authored Jun 27, 2023
1 parent 59bd9f6 commit ae7c75d
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 217 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugins/observability/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import { i18n } from '@kbn/i18n';
import { AlertConsumers } from '@kbn/rule-data-utils';
import type { ValidFeatureId } from '@kbn/rule-data-utils';

export const SLO_BURN_RATE_RULE_TYPE_ID = 'slo.rules.burnRate';
export const OBSERVABILITY_THRESHOLD_RULE_TYPE_ID = 'observability.rules.threshold';
Expand Down Expand Up @@ -45,3 +47,12 @@ export const LOW_PRIORITY_ACTION = {
defaultMessage: 'Low',
}),
};

export const observabilityAlertFeatureIds: ValidFeatureId[] = [
AlertConsumers.APM,
AlertConsumers.INFRASTRUCTURE,
AlertConsumers.LOGS,
AlertConsumers.UPTIME,
AlertConsumers.SLO,
AlertConsumers.OBSERVABILITY,
];
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { waitFor } from '@testing-library/react';
import { timefilterServiceMock } from '@kbn/data-plugin/public/query/timefilter/timefilter_service.mock';
import { ObservabilityAlertSearchBarProps, Services } from './types';
import { ObservabilityAlertSearchBar } from './alert_search_bar';
import { observabilityAlertFeatureIds } from '../../config/alert_feature_ids';
import { observabilityAlertFeatureIds } from '../../../common/constants';
import { render } from '../../utils/test_helper';

const getAlertsSearchBarMock = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useCallback, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { Query } from '@kbn/es-query';
import { AlertsStatusFilter } from './components';
import { observabilityAlertFeatureIds } from '../../config/alert_feature_ids';
import { observabilityAlertFeatureIds } from '../../../common/constants';
import { ALERT_STATUS_QUERY, DEFAULT_QUERIES, DEFAULT_QUERY_STRING } from './constants';
import { ObservabilityAlertSearchBarProps } from './types';
import { buildEsQuery } from '../../utils/build_es_query';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import {
ALERT_STATUS_ACTIVE,
ALERT_STATUS_RECOVERED,
} from '@kbn/rule-data-utils';
import { i18n } from '@kbn/i18n';
import { AlertLifecycleStatusBadge } from '@kbn/alerts-ui-shared';
import moment from 'moment-timezone';
import { useUiSetting } from '@kbn/kibana-react-plugin/public';
import { useKibana } from '../../utils/kibana_react';
import { asDuration } from '../../../common/utils/formatters';
import { paths } from '../../routes/paths';
import { translations } from '../../config/translations';
import { formatAlertEvaluationValue } from '../../utils/format_alert_evaluation_value';
import { RULE_DETAILS_PAGE_ID } from '../../pages/rule_details/constants';
import type { TopAlert } from '../../typings/alerts';
Expand All @@ -59,7 +59,9 @@ export function AlertsFlyoutBody({ alert, id: pageId }: FlyoutProps) {

const overviewListItems = [
{
title: translations.alertsFlyout.statusLabel,
title: i18n.translate('xpack.observability.alertsFlyout.statusLabel', {
defaultMessage: 'Status',
}),
description: (
<AlertLifecycleStatusBadge
alertStatus={alert.active ? ALERT_STATUS_ACTIVE : ALERT_STATUS_RECOVERED}
Expand All @@ -68,59 +70,81 @@ export function AlertsFlyoutBody({ alert, id: pageId }: FlyoutProps) {
),
},
{
title: translations.alertsFlyout.startedAtLabel,
title: i18n.translate('xpack.observability.alertsFlyout.startedAtLabel', {
defaultMessage: 'Started at',
}),
description: (
<span title={alert.start.toString()}>{moment(alert.start).format(dateFormat)}</span>
),
},
{
title: translations.alertsFlyout.lastUpdatedLabel,
title: i18n.translate('xpack.observability.alertsFlyout.lastUpdatedLabel', {
defaultMessage: 'Last updated',
}),
description: (
<span title={alert.lastUpdated.toString()}>
{moment(alert.lastUpdated).format(dateFormat)}
</span>
),
},
{
title: translations.alertsFlyout.durationLabel,
title: i18n.translate('xpack.observability.alertsFlyout.durationLabel', {
defaultMessage: 'Duration',
}),
description: asDuration(alert.fields[ALERT_DURATION], { extended: true }),
},
{
title: translations.alertsFlyout.expectedValueLabel,
title: i18n.translate('xpack.observability.alertsFlyout.expectedValueLabel', {
defaultMessage: 'Expected value',
}),
description: formatAlertEvaluationValue(
alert.fields[ALERT_RULE_TYPE_ID],
alert.fields[ALERT_EVALUATION_THRESHOLD]
),
},
{
title: translations.alertsFlyout.actualValueLabel,
title: i18n.translate('xpack.observability.alertsFlyout.actualValueLabel', {
defaultMessage: 'Actual value',
}),
description: formatAlertEvaluationValue(
alert.fields[ALERT_RULE_TYPE_ID],
alert.fields[ALERT_EVALUATION_VALUE]
),
},
{
title: translations.alertsFlyout.ruleTypeLabel,
title: i18n.translate('xpack.observability.alertsFlyout.ruleTypeLabel', {
defaultMessage: 'Rule type',
}),
description: alert.fields[ALERT_RULE_CATEGORY] ?? '-',
},
];

return (
<EuiFlyoutBody>
<EuiTitle size="xs">
<h4>{translations.alertsFlyout.reasonTitle}</h4>
<h4>
{i18n.translate('xpack.observability.alertsFlyout.reasonTitle', {
defaultMessage: 'Reason',
})}
</h4>
</EuiTitle>
<EuiSpacer size="s" />
<EuiText size="s">{alert.reason}</EuiText>
<EuiSpacer size="s" />
{!!linkToRule && (
<EuiLink href={linkToRule} data-test-subj="viewRuleDetailsFlyout">
{translations.alertsFlyout.viewRulesDetailsLinkText}
{i18n.translate('xpack.observability.alertsFlyout.viewRulesDetailsLinkText', {
defaultMessage: 'View rule details',
})}
</EuiLink>
)}
<EuiHorizontalRule size="full" />
<EuiTitle size="xs">
<h4>{translations.alertsFlyout.documentSummaryTitle}</h4>
<h4>
{i18n.translate('xpack.observability.alertsFlyout.documentSummaryTitle', {
defaultMessage: 'Document Summary',
})}
</h4>
</EuiTitle>
<EuiSpacer size="m" />
<EuiDescriptionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
import React from 'react';
import { EuiFlyoutFooter, EuiFlexGroup, EuiFlexItem, EuiButton } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useKibana } from '../../utils/kibana_react';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { isAlertDetailsEnabledPerApp } from '../../utils/is_alert_details_enabled';
import { translations } from '../../config/translations';
import { paths } from '../../routes/paths';
import type { TopAlert } from '../../typings/alerts';

Expand All @@ -26,43 +26,39 @@ export function AlertsFlyoutFooter({ alert, isInApp }: FlyoutProps & { isInApp:
} = useKibana().services;
const { config } = usePluginContext();

const getAlertDetailsButton = () => {
if (!isAlertDetailsEnabledPerApp(alert, config)) return <></>;
return (
<EuiFlexItem grow={false}>
<EuiButton
href={
prepend && prepend(paths.observability.alertDetails(alert.fields['kibana.alert.uuid']))
}
data-test-subj="alertsFlyoutAlertDetailsButton"
fill
>
{translations.alertsFlyout.alertDetailsButtonText}
</EuiButton>
</EuiFlexItem>
);
};

const getViewInAppUrlButton = () => {
if (!alert.link || isInApp) return <></>;
return (
<EuiFlexItem grow={false}>
<EuiButton
href={prepend && prepend(alert.link)}
data-test-subj="alertsFlyoutViewInAppButton"
fill
>
{translations.alertsFlyout.viewInAppButtonText}
</EuiButton>
</EuiFlexItem>
);
};

return (
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="flexEnd">
{getViewInAppUrlButton()}
{getAlertDetailsButton()}
{!alert.link || isInApp ? null : (
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="alertsFlyoutViewInAppButton"
fill
href={prepend && prepend(alert.link)}
>
{i18n.translate('xpack.observability.alertsFlyout.viewInAppButtonText', {
defaultMessage: 'View in app',
})}
</EuiButton>
</EuiFlexItem>
)}

{!isAlertDetailsEnabledPerApp(alert, config) ? null : (
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="alertsFlyoutAlertDetailsButton"
fill
href={
prepend &&
prepend(paths.observability.alertDetails(alert.fields['kibana.alert.uuid']))
}
>
{i18n.translate('xpack.observability.alertsFlyout.alertsDetailsButtonText', {
defaultMessage: 'Alert details',
})}
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlyoutFooter>
);
Expand Down
18 changes: 0 additions & 18 deletions x-pack/plugins/observability/public/config/alert_feature_ids.ts

This file was deleted.

125 changes: 0 additions & 125 deletions x-pack/plugins/observability/public/config/translations.ts

This file was deleted.

4 changes: 2 additions & 2 deletions x-pack/plugins/observability/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export {
uptimeOverviewLocatorID,
} from '../common';

export type { UXMetrics } from './components/core_web_vitals/core_vitals';
export { getCoreVitalsComponent } from './components/core_web_vitals/get_core_web_vitals_lazy';
export type { UXMetrics } from './pages/overview/components/sections/ux/core_web_vitals/core_vitals';
export { getCoreVitalsComponent } from './pages/overview/components/sections/ux/core_web_vitals/get_core_web_vitals_lazy';

export { DatePicker } from './pages/overview/components/date_picker/date_picker';
export { ObservabilityAlertSearchBar } from './components/alert_search_bar/get_alert_search_bar_lazy';
Expand Down
Loading

0 comments on commit ae7c75d

Please sign in to comment.