Skip to content

Commit 0e7f7b8

Browse files
committed
Moved setting of default alert type to the server api
1 parent 18f19d3 commit 0e7f7b8

8 files changed

Lines changed: 20 additions & 27 deletions

File tree

x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const getLicenseExpiration = (
5454
}),
5555
},
5656
],
57+
defaultActionGroup: 'default',
5758
async executor({
5859
services,
5960
params,

x-pack/plugins/alerting/common/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
77
export * from './alert';
88
export * from './alert_instance';
99
export * from './alert_task_instance';
10+
11+
export interface ActionGroup {
12+
id: string;
13+
name: string;
14+
}

x-pack/plugins/alerting/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type AlertsClient = PublicMethodsOf<AlertsClientClass>;
1212

1313
export {
1414
AlertType,
15+
ActionGroup,
1516
AlertingPlugin,
1617
AlertExecutorOptions,
1718
AlertActionParams,

x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const alertType: AlertType = {
1515
{ id: 'default', name: 'Default' },
1616
{ id: 'other-group', name: 'Other Group' },
1717
],
18+
defaultActionGroup: 'default',
1819
executor: jest.fn(),
1920
};
2021

x-pack/plugins/alerting/server/types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AlertInstance } from './alert_instance';
88
import { AlertTypeRegistry as OrigAlertTypeRegistry } from './alert_type_registry';
99
import { PluginSetupContract, PluginStartContract } from './plugin';
1010
import { SavedObjectAttributes, SavedObjectsClientContract } from '../../../../src/core/server';
11-
import { Alert, AlertActionParams } from '../common';
11+
import { Alert, AlertActionParams, ActionGroup } from '../common';
1212
import { AlertsClient } from './alerts_client';
1313
export * from '../common';
1414

@@ -52,18 +52,14 @@ export interface AlertExecutorOptions {
5252
updatedBy: string | null;
5353
}
5454

55-
export interface ActionGroup {
56-
id: string;
57-
name: string;
58-
}
59-
6055
export interface AlertType {
6156
id: string;
6257
name: string;
6358
validate?: {
6459
params?: { validate: (object: any) => any };
6560
};
6661
actionGroups: ActionGroup[];
62+
defaultActionGroup: ActionGroup['id'];
6763
executor: ({ services, params, state }: AlertExecutorOptions) => Promise<State | void>;
6864
}
6965

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,5 @@ export function getAlertType(): AlertTypeModel {
101101
return validationResult;
102102
},
103103
defaultActionMessage: 'Alert [{{ctx.metadata.name}}] has exceeded the threshold',
104-
defaultActionGroup: 'alert',
105104
};
106105
}

x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export const AlertForm = ({
118118
const [alertThrottleUnit, setAlertThrottleUnit] = useState<string>('m');
119119
const [isAddActionPanelOpen, setIsAddActionPanelOpen] = useState<boolean>(true);
120120
const [connectors, setConnectors] = useState<ActionConnector[]>([]);
121-
const [defaultActionGroup, setDefaultActionGroup] = useState<string>(
122-
alertTypeModel?.defaultActionGroup ?? 'default'
123-
);
121+
const [defaultActionGroup, setDefaultActionGroup] = useState<string>('default');
124122
const [activeActionItem, setActiveActionItem] = useState<ActiveActionConnectorState | undefined>(
125123
undefined
126124
);
@@ -167,13 +165,14 @@ export const AlertForm = ({
167165
],
168166
name: 'threshold',
169167
actionVariables: ['ctx.metadata.name', 'ctx.metadata.test'],
168+
defaultActionGroup: 'alert',
170169
});
171170
const index: AlertTypeIndex = {};
172171
for (const alertTypeItem of alertTypes) {
173172
index[alertTypeItem.id] = alertTypeItem;
174173
}
175-
if (!alertTypeModel?.defaultActionGroup && alert.alertTypeId && index[alert.alertTypeId]) {
176-
setDefaultActionGroup(index[alert.alertTypeId].actionGroups[0].id);
174+
if (alert.alertTypeId && index[alert.alertTypeId]) {
175+
setDefaultActionGroup(index[alert.alertTypeId].defaultActionGroup);
177176
}
178177
setAlertTypesIndex(index);
179178
} catch (e) {
@@ -295,15 +294,8 @@ export const AlertForm = ({
295294
onClick={() => {
296295
setAlertProperty('alertTypeId', item.id);
297296
setAlertTypeModel(item);
298-
if (item.defaultActionGroup) {
299-
setDefaultActionGroup(item.defaultActionGroup);
300-
} else if (
301-
!alertTypeModel?.defaultActionGroup &&
302-
alertTypesIndex &&
303-
alertTypesIndex[item.id] &&
304-
alertTypesIndex[item.id].actionGroups.length > 0
305-
) {
306-
setDefaultActionGroup(alertTypesIndex[item.id].actionGroups[0].id);
297+
if (alertTypesIndex && alertTypesIndex[item.id]) {
298+
setDefaultActionGroup(alertTypesIndex[item.id].defaultActionGroup);
307299
}
308300
}}
309301
>

x-pack/plugins/triggers_actions_ui/public/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
import { ActionGroup } from '../../alerting/common';
67
import { ActionType } from '../../actions/common';
78
import { TypeRegistry } from './application/type_registry';
89
import {
@@ -70,18 +71,16 @@ export interface ActionConnectorTableItem extends ActionConnector {
7071
actionType: ActionType['name'];
7172
}
7273

73-
export interface ActionGroup {
74-
id: string;
75-
name: string;
76-
}
77-
7874
export interface AlertType {
7975
id: string;
8076
name: string;
8177
actionGroups: ActionGroup[];
8278
actionVariables: string[];
79+
defaultActionGroup: ActionGroup['id'];
8380
}
8481

82+
export type SanitizedAlertType = Omit<AlertType, 'apiKey'>;
83+
8584
export type AlertWithoutId = Omit<Alert, 'id'>;
8685

8786
export interface AlertTableItem extends Alert {
@@ -96,7 +95,6 @@ export interface AlertTypeModel {
9695
validate: (alertParams: any) => ValidationResult;
9796
alertParamsExpression: React.FunctionComponent<any>;
9897
defaultActionMessage?: string;
99-
defaultActionGroup?: string;
10098
}
10199

102100
export interface IErrorObject {

0 commit comments

Comments
 (0)