Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ export const RuleTagBadge = suspendedComponentWithProps(
export const RuleStatusPanel = suspendedComponentWithProps(
lazy(() => import('./rule_details/components/rule_status_panel'))
);

export const UntrackAlertsModal = suspendedComponentWithProps(
lazy(() =>
import('./common/components/untrack_alerts_modal').then((module) => ({
default: module.UntrackAlertsModal,
}))
)
);

export const GlobalRuleEventLogList = suspendedComponentWithProps(
lazy(() => import('./rule_details/components/global_rule_event_log_list'))
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 from 'react';
import { UntrackAlertsModal } from '../application/sections/common/components/untrack_alerts_modal';
import type { UntrackAlertsModalProps } from '../application/sections/common/components/untrack_alerts_modal';

export const getUntrackModalLazy = (props: UntrackAlertsModalProps) => {
return <UntrackAlertsModal {...props} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import { getRuleStatusPanelLazy } from './common/get_rule_status_panel';
import { getRuleSnoozeModalLazy } from './common/get_rule_snooze_modal';
import { getRulesSettingsLinkLazy } from './common/get_rules_settings_link';
import type { AlertSummaryWidgetDependencies } from './application/sections/alert_summary_widget/types';
import { isRuleSnoozed } from './application/lib';
import { getNextRuleSnoozeSchedule } from './application/sections/rules_list/components/notify_badge/helpers';
import { getUntrackModalLazy } from './common/get_untrack_modal';

function createStartMock(): TriggersAndActionsUIPublicPluginStart {
const actionTypeRegistry = new TypeRegistry<ActionTypeModel>();
Expand Down Expand Up @@ -122,6 +125,20 @@ function createStartMock(): TriggersAndActionsUIPublicPluginStart {
getRulesSettingsLink: () => {
return getRulesSettingsLinkLazy();
},
getUntrackModal: (props) => {
return getUntrackModalLazy(props);
},
getRuleHelpers: (rule) => {
return {
isRuleSnoozed: isRuleSnoozed({
isSnoozedUntil: rule.isSnoozedUntil,
muteAll: rule.muteAll,
}),
getNextRuleSnoozeSchedule: getNextRuleSnoozeSchedule({
snoozeSchedule: rule.snoozeSchedule,
}),
};
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import type { ServerlessPluginStart } from '@kbn/serverless/public';
import type { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common';
import type { LensPublicStart } from '@kbn/lens-plugin/public';
import type { RuleAction } from '@kbn/alerting-plugin/common';
import type { RRuleParams, RuleAction, RuleTypeParams } from '@kbn/alerting-plugin/common';
import { TypeRegistry } from '@kbn/alerts-ui-shared/src/common/type_registry';
import type { CloudSetup } from '@kbn/cloud-plugin/public';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import type { RuleUiAction } from './types';
import type { Rule, RuleUiAction } from './types';
import type { AlertsSearchBarProps } from './application/sections/alerts_search_bar';

import { getAddConnectorFlyoutLazy } from './common/get_add_connector_flyout';
Expand Down Expand Up @@ -84,6 +84,10 @@ import type {
RulesListNotifyBadgePropsWithApi,
RulesListProps,
} from './types';
import type { UntrackAlertsModalProps } from './application/sections/common/components/untrack_alerts_modal';
import { isRuleSnoozed } from './application/lib';
import { getNextRuleSnoozeSchedule } from './application/sections/rules_list/components/notify_badge/helpers';
import { getUntrackModalLazy } from './common/get_untrack_modal';

export interface TriggersAndActionsUIPublicPluginSetup {
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
Expand Down Expand Up @@ -122,7 +126,17 @@ export interface TriggersAndActionsUIPublicPluginStart {
getRuleStatusPanel: (props: RuleStatusPanelProps) => ReactElement<RuleStatusPanelProps>;
getAlertSummaryWidget: (props: AlertSummaryWidgetProps) => ReactElement<AlertSummaryWidgetProps>;
getRuleSnoozeModal: (props: RuleSnoozeModalProps) => ReactElement<RuleSnoozeModalProps>;
getUntrackModal: (props: UntrackAlertsModalProps) => ReactElement<UntrackAlertsModalProps>;
getRulesSettingsLink: () => ReactElement;
getRuleHelpers: (rule: Rule<RuleTypeParams>) => {
isRuleSnoozed: boolean;
getNextRuleSnoozeSchedule: {
duration: number;
rRule: RRuleParams;
id?: string | undefined;
skipRecurrences?: string[] | undefined;
} | null;
};
getGlobalRuleEventLogList: (
props: GlobalRuleEventLogListProps
) => ReactElement<GlobalRuleEventLogListProps>;
Expand Down Expand Up @@ -493,9 +507,23 @@ export class Plugin
getRuleSnoozeModal: (props: RuleSnoozeModalProps) => {
return getRuleSnoozeModalLazy(props);
},
getUntrackModal: (props: UntrackAlertsModalProps) => {
return getUntrackModalLazy(props);
},
getRulesSettingsLink: () => {
return getRulesSettingsLinkLazy();
},
getRuleHelpers: (rule: Rule<RuleTypeParams>) => {
return {
isRuleSnoozed: isRuleSnoozed({
isSnoozedUntil: rule.isSnoozedUntil,
muteAll: rule.muteAll,
}),
getNextRuleSnoozeSchedule: getNextRuleSnoozeSchedule({
snoozeSchedule: rule.snoozeSchedule,
}),
};
},
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 { useMutation, useQueryClient } from '@tanstack/react-query';
import { i18n } from '@kbn/i18n';
import { useKibana } from '../utils/kibana_react';

export function useDisableRule() {
const {
http,
notifications: { toasts },
} = useKibana().services;

const queryClient = useQueryClient();

const disableRule = useMutation<string, string, { id: string; untrack: boolean }>(
['disableRule'],
({ id, untrack }) => {
const body = JSON.stringify({
...(untrack ? { untrack } : {}),
});
try {
return http.post(`/api/alerting/rule/${id}/_disable`, { body });
} catch (e) {
throw new Error(`Unable to parse id: ${e}`);
}
},
{
onError: (_err) => {
toasts.addDanger(
i18n.translate(
'xpack.observability.rules.disableErrorModal.errorNotification.descriptionText',
{
defaultMessage: 'Failed to disable rule',
}
)
);
},

onSuccess: (_, variables) => {
queryClient.invalidateQueries({ queryKey: ['fetchRule', variables.id], exact: false });
toasts.addSuccess(
i18n.translate(
'xpack.observability.rules.disableConfirmationModal.successNotification.descriptionText',
{
defaultMessage: 'Disabled rule',
}
)
);
},
}
);

return disableRule;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 { useMutation, useQueryClient } from '@tanstack/react-query';
import { i18n } from '@kbn/i18n';
import { useKibana } from '../utils/kibana_react';

export function useEnableRule() {
const {
http,
notifications: { toasts },
} = useKibana().services;

const queryClient = useQueryClient();

const enableRule = useMutation<string, string, { id: string }>(
['enableRule'],
({ id }) => {
try {
return http.post(`/api/alerting/rule/${id}/_enable`);
} catch (e) {
throw new Error(`Unable to parse id: ${e}`);
}
},
{
onError: (_err) => {
toasts.addDanger(
i18n.translate(
'xpack.observability.rules.enableErrorModal.errorNotification.descriptionText',
{
defaultMessage: 'Failed to enable rule',
}
)
);
},

onSuccess: (_, variables) => {
queryClient.invalidateQueries({ queryKey: ['fetchRule', variables.id], exact: false });
toasts.addSuccess(
i18n.translate(
'xpack.observability.rules.enableConfirmationModal.successNotification.descriptionText',
{
defaultMessage: 'Enabled rule',
}
)
);
},
}
);

return enableRule;
}
Loading