Skip to content

Commit 345163a

Browse files
authored
Merge branch 'main' into update-bundled-packages-20250501124943
2 parents 9fe7ec5 + 1ee2f62 commit 345163a

64 files changed

Lines changed: 573 additions & 554 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ export const RuleTagBadge = suspendedComponentWithProps(
5050
export const RuleStatusPanel = suspendedComponentWithProps(
5151
lazy(() => import('./rule_details/components/rule_status_panel'))
5252
);
53+
54+
export const UntrackAlertsModal = suspendedComponentWithProps(
55+
lazy(() =>
56+
import('./common/components/untrack_alerts_modal').then((module) => ({
57+
default: module.UntrackAlertsModal,
58+
}))
59+
)
60+
);
61+
5362
export const GlobalRuleEventLogList = suspendedComponentWithProps(
5463
lazy(() => import('./rule_details/components/global_rule_event_log_list'))
5564
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import React from 'react';
9+
import { UntrackAlertsModal } from '../application/sections/common/components/untrack_alerts_modal';
10+
import type { UntrackAlertsModalProps } from '../application/sections/common/components/untrack_alerts_modal';
11+
12+
export const getUntrackModalLazy = (props: UntrackAlertsModalProps) => {
13+
return <UntrackAlertsModal {...props} />;
14+
};

x-pack/platform/plugins/shared/triggers_actions_ui/public/mocks.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ import { getRuleStatusPanelLazy } from './common/get_rule_status_panel';
4242
import { getRuleSnoozeModalLazy } from './common/get_rule_snooze_modal';
4343
import { getRulesSettingsLinkLazy } from './common/get_rules_settings_link';
4444
import type { AlertSummaryWidgetDependencies } from './application/sections/alert_summary_widget/types';
45+
import { isRuleSnoozed } from './application/lib';
46+
import { getNextRuleSnoozeSchedule } from './application/sections/rules_list/components/notify_badge/helpers';
47+
import { getUntrackModalLazy } from './common/get_untrack_modal';
4548

4649
function createStartMock(): TriggersAndActionsUIPublicPluginStart {
4750
const actionTypeRegistry = new TypeRegistry<ActionTypeModel>();
@@ -122,6 +125,20 @@ function createStartMock(): TriggersAndActionsUIPublicPluginStart {
122125
getRulesSettingsLink: () => {
123126
return getRulesSettingsLinkLazy();
124127
},
128+
getUntrackModal: (props) => {
129+
return getUntrackModalLazy(props);
130+
},
131+
getRuleHelpers: (rule) => {
132+
return {
133+
isRuleSnoozed: isRuleSnoozed({
134+
isSnoozedUntil: rule.isSnoozedUntil,
135+
muteAll: rule.muteAll,
136+
}),
137+
getNextRuleSnoozeSchedule: getNextRuleSnoozeSchedule({
138+
snoozeSchedule: rule.snoozeSchedule,
139+
}),
140+
};
141+
},
125142
};
126143
}
127144

x-pack/platform/plugins/shared/triggers_actions_ui/public/plugin.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
3030
import type { ServerlessPluginStart } from '@kbn/serverless/public';
3131
import type { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common';
3232
import type { LensPublicStart } from '@kbn/lens-plugin/public';
33-
import type { RuleAction } from '@kbn/alerting-plugin/common';
33+
import type { RRuleParams, RuleAction, RuleTypeParams } from '@kbn/alerting-plugin/common';
3434
import { TypeRegistry } from '@kbn/alerts-ui-shared/src/common/type_registry';
3535
import type { CloudSetup } from '@kbn/cloud-plugin/public';
3636
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
37-
import type { RuleUiAction } from './types';
37+
import type { Rule, RuleUiAction } from './types';
3838
import type { AlertsSearchBarProps } from './application/sections/alerts_search_bar';
3939

4040
import { getAddConnectorFlyoutLazy } from './common/get_add_connector_flyout';
@@ -84,6 +84,10 @@ import type {
8484
RulesListNotifyBadgePropsWithApi,
8585
RulesListProps,
8686
} from './types';
87+
import type { UntrackAlertsModalProps } from './application/sections/common/components/untrack_alerts_modal';
88+
import { isRuleSnoozed } from './application/lib';
89+
import { getNextRuleSnoozeSchedule } from './application/sections/rules_list/components/notify_badge/helpers';
90+
import { getUntrackModalLazy } from './common/get_untrack_modal';
8791

8892
export interface TriggersAndActionsUIPublicPluginSetup {
8993
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
@@ -122,7 +126,17 @@ export interface TriggersAndActionsUIPublicPluginStart {
122126
getRuleStatusPanel: (props: RuleStatusPanelProps) => ReactElement<RuleStatusPanelProps>;
123127
getAlertSummaryWidget: (props: AlertSummaryWidgetProps) => ReactElement<AlertSummaryWidgetProps>;
124128
getRuleSnoozeModal: (props: RuleSnoozeModalProps) => ReactElement<RuleSnoozeModalProps>;
129+
getUntrackModal: (props: UntrackAlertsModalProps) => ReactElement<UntrackAlertsModalProps>;
125130
getRulesSettingsLink: () => ReactElement;
131+
getRuleHelpers: (rule: Rule<RuleTypeParams>) => {
132+
isRuleSnoozed: boolean;
133+
getNextRuleSnoozeSchedule: {
134+
duration: number;
135+
rRule: RRuleParams;
136+
id?: string | undefined;
137+
skipRecurrences?: string[] | undefined;
138+
} | null;
139+
};
126140
getGlobalRuleEventLogList: (
127141
props: GlobalRuleEventLogListProps
128142
) => ReactElement<GlobalRuleEventLogListProps>;
@@ -495,9 +509,23 @@ export class Plugin
495509
getRuleSnoozeModal: (props: RuleSnoozeModalProps) => {
496510
return getRuleSnoozeModalLazy(props);
497511
},
512+
getUntrackModal: (props: UntrackAlertsModalProps) => {
513+
return getUntrackModalLazy(props);
514+
},
498515
getRulesSettingsLink: () => {
499516
return getRulesSettingsLinkLazy();
500517
},
518+
getRuleHelpers: (rule: Rule<RuleTypeParams>) => {
519+
return {
520+
isRuleSnoozed: isRuleSnoozed({
521+
isSnoozedUntil: rule.isSnoozedUntil,
522+
muteAll: rule.muteAll,
523+
}),
524+
getNextRuleSnoozeSchedule: getNextRuleSnoozeSchedule({
525+
snoozeSchedule: rule.snoozeSchedule,
526+
}),
527+
};
528+
},
501529
};
502530
}
503531

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { useMutation, useQueryClient } from '@tanstack/react-query';
9+
import { i18n } from '@kbn/i18n';
10+
import { useKibana } from '../utils/kibana_react';
11+
12+
export function useDisableRule() {
13+
const {
14+
http,
15+
notifications: { toasts },
16+
} = useKibana().services;
17+
18+
const queryClient = useQueryClient();
19+
20+
const disableRule = useMutation<string, string, { id: string; untrack: boolean }>(
21+
['disableRule'],
22+
({ id, untrack }) => {
23+
const body = JSON.stringify({
24+
...(untrack ? { untrack } : {}),
25+
});
26+
try {
27+
return http.post(`/api/alerting/rule/${id}/_disable`, { body });
28+
} catch (e) {
29+
throw new Error(`Unable to parse id: ${e}`);
30+
}
31+
},
32+
{
33+
onError: (_err) => {
34+
toasts.addDanger(
35+
i18n.translate(
36+
'xpack.observability.rules.disableErrorModal.errorNotification.descriptionText',
37+
{
38+
defaultMessage: 'Failed to disable rule',
39+
}
40+
)
41+
);
42+
},
43+
44+
onSuccess: (_, variables) => {
45+
queryClient.invalidateQueries({ queryKey: ['fetchRule', variables.id], exact: false });
46+
toasts.addSuccess(
47+
i18n.translate(
48+
'xpack.observability.rules.disableConfirmationModal.successNotification.descriptionText',
49+
{
50+
defaultMessage: 'Disabled rule',
51+
}
52+
)
53+
);
54+
},
55+
}
56+
);
57+
58+
return disableRule;
59+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { useMutation, useQueryClient } from '@tanstack/react-query';
9+
import { i18n } from '@kbn/i18n';
10+
import { useKibana } from '../utils/kibana_react';
11+
12+
export function useEnableRule() {
13+
const {
14+
http,
15+
notifications: { toasts },
16+
} = useKibana().services;
17+
18+
const queryClient = useQueryClient();
19+
20+
const enableRule = useMutation<string, string, { id: string }>(
21+
['enableRule'],
22+
({ id }) => {
23+
try {
24+
return http.post(`/api/alerting/rule/${id}/_enable`);
25+
} catch (e) {
26+
throw new Error(`Unable to parse id: ${e}`);
27+
}
28+
},
29+
{
30+
onError: (_err) => {
31+
toasts.addDanger(
32+
i18n.translate(
33+
'xpack.observability.rules.enableErrorModal.errorNotification.descriptionText',
34+
{
35+
defaultMessage: 'Failed to enable rule',
36+
}
37+
)
38+
);
39+
},
40+
41+
onSuccess: (_, variables) => {
42+
queryClient.invalidateQueries({ queryKey: ['fetchRule', variables.id], exact: false });
43+
toasts.addSuccess(
44+
i18n.translate(
45+
'xpack.observability.rules.enableConfirmationModal.successNotification.descriptionText',
46+
{
47+
defaultMessage: 'Enabled rule',
48+
}
49+
)
50+
);
51+
},
52+
}
53+
);
54+
55+
return enableRule;
56+
}

0 commit comments

Comments
 (0)