From 595eb69a146bd35c998a7260e3cfdf32d529246f Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 11 May 2020 15:57:39 -0700 Subject: [PATCH] Fixed due to comments --- .../alerting_example/public/alert_types/always_firing.tsx | 2 +- examples/alerting_example/public/alert_types/astros.tsx | 2 +- x-pack/plugins/alerting/README.md | 2 +- x-pack/plugins/apm/public/plugin.ts | 4 ++-- .../infra/public/alerting/metric_threshold/index.ts | 2 +- .../inventory/metric_inventory_threshold_alert_type.ts | 2 +- .../components/alerting/logs/log_threshold_alert_type.ts | 2 +- x-pack/plugins/triggers_actions_ui/README.md | 6 ++++-- .../components/builtin_alert_types/threshold/index.ts | 2 +- .../sections/action_connector_form/action_form.test.tsx | 2 +- .../alert_details/components/alert_details.test.tsx | 2 +- .../sections/alert_details/components/alert_details.tsx | 2 +- .../application/sections/alert_form/alert_add.test.tsx | 2 +- .../application/sections/alert_form/alert_edit.test.tsx | 2 +- .../application/sections/alert_form/alert_form.test.tsx | 8 ++++---- .../public/application/sections/alert_form/alert_form.tsx | 4 +++- .../sections/alerts_list/components/alerts_list.test.tsx | 2 +- .../public/application/type_registry.test.ts | 2 +- x-pack/plugins/triggers_actions_ui/public/types.ts | 2 +- .../uptime/public/lib/alert_types/monitor_status.tsx | 2 +- x-pack/plugins/uptime/public/lib/alert_types/tls.tsx | 2 +- .../fixtures/plugins/alerts/public/plugin.ts | 4 ++-- 22 files changed, 32 insertions(+), 28 deletions(-) diff --git a/examples/alerting_example/public/alert_types/always_firing.tsx b/examples/alerting_example/public/alert_types/always_firing.tsx index 507cb502bac74..222702d430934 100644 --- a/examples/alerting_example/public/alert_types/always_firing.tsx +++ b/examples/alerting_example/public/alert_types/always_firing.tsx @@ -51,7 +51,7 @@ export function getAlertType(): AlertTypeModel { } return validationResult; }, - isEditable: true, + requiresAppContext: true, }; } diff --git a/examples/alerting_example/public/alert_types/astros.tsx b/examples/alerting_example/public/alert_types/astros.tsx index a5b3b467835c2..b0f25c235fb58 100644 --- a/examples/alerting_example/public/alert_types/astros.tsx +++ b/examples/alerting_example/public/alert_types/astros.tsx @@ -99,7 +99,7 @@ export function getAlertType(): AlertTypeModel { return validationResult; }, - isEditable: true, + requiresAppContext: true, }; } diff --git a/x-pack/plugins/alerting/README.md b/x-pack/plugins/alerting/README.md index 742f3d2a706b8..dfa2991895429 100644 --- a/x-pack/plugins/alerting/README.md +++ b/x-pack/plugins/alerting/README.md @@ -91,7 +91,7 @@ The following table describes the properties of the `options` object. |actionVariables|An explicit list of action variables the alert type makes available via context and state in action parameter templates, and a short human readable description. Alert UI will use this to display prompts for the users for these variables, in action parameter editors. We highly encourage using `kbn-i18n` to translate the descriptions. |{ context: Array<{name:string, description:string}, state: Array<{name:string, description:string}>| |validate.params|When developing an alert type, you can choose to accept a series of parameters. You may also have the parameters validated before they are passed to the `executor` function or created as an alert saved object. In order to do this, provide a `@kbn/config-schema` schema that we will use to validate the `params` attribute.|@kbn/config-schema| |executor|This is where the code of the alert type lives. This is a function to be called when executing an alert on an interval basis. For full details, see executor section below.|Function| -|producer|This is correcponding value to the alert consumer. Used to define the owner application for alert type +|producer|The id of the application producing this alert type.|string| ### Executor diff --git a/x-pack/plugins/apm/public/plugin.ts b/x-pack/plugins/apm/public/plugin.ts index c962944c8d29f..445d252c20112 100644 --- a/x-pack/plugins/apm/public/plugin.ts +++ b/x-pack/plugins/apm/public/plugin.ts @@ -116,7 +116,7 @@ export class ApmPlugin implements Plugin { validate: () => ({ errors: [] }), - isEditable: false + requiresAppContext: false }); plugins.triggers_actions_ui.alertTypeRegistry.register({ @@ -129,7 +129,7 @@ export class ApmPlugin implements Plugin { validate: () => ({ errors: [] }), - isEditable: false + requiresAppContext: false }); } } diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts b/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts index aea9f512f5eab..6f49245411765 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts @@ -30,6 +30,6 @@ Reason: `, } ), - isEditable: true, + requiresAppContext: true, }; } diff --git a/x-pack/plugins/infra/public/components/alerting/inventory/metric_inventory_threshold_alert_type.ts b/x-pack/plugins/infra/public/components/alerting/inventory/metric_inventory_threshold_alert_type.ts index 012f368f3b617..9ff68ef10d537 100644 --- a/x-pack/plugins/infra/public/components/alerting/inventory/metric_inventory_threshold_alert_type.ts +++ b/x-pack/plugins/infra/public/components/alerting/inventory/metric_inventory_threshold_alert_type.ts @@ -30,6 +30,6 @@ Current value is \\{\\{context.valueOf.condition0\\}\\} `, } ), - isEditable: true, + requiresAppContext: true, }; } diff --git a/x-pack/plugins/infra/public/components/alerting/logs/log_threshold_alert_type.ts b/x-pack/plugins/infra/public/components/alerting/logs/log_threshold_alert_type.ts index f98d2ed48e161..30cde458b0760 100644 --- a/x-pack/plugins/infra/public/components/alerting/logs/log_threshold_alert_type.ts +++ b/x-pack/plugins/infra/public/components/alerting/logs/log_threshold_alert_type.ts @@ -25,6 +25,6 @@ export function getAlertType(): AlertTypeModel { defaultMessage: `\\{\\{context.matchingDocuments\\}\\} log entries have matched the following conditions: \\{\\{context.conditions\\}\\}`, } ), - isEditable: true, + requiresAppContext: true, }; } diff --git a/x-pack/plugins/triggers_actions_ui/README.md b/x-pack/plugins/triggers_actions_ui/README.md index b28aec079d81a..156445ca6addd 100644 --- a/x-pack/plugins/triggers_actions_ui/README.md +++ b/x-pack/plugins/triggers_actions_ui/README.md @@ -71,7 +71,7 @@ export function getAlertType(): AlertTypeModel { iconClass: 'alert', alertParamsExpression: IndexThresholdAlertTypeExpression, validate: validateAlertType, - isEditable: true, + requiresAppContext: true, }; } ``` @@ -249,6 +249,7 @@ Each alert type should be defined as `AlertTypeModel` object with the these prop |validate|Validation function for the alert params.| |alertParamsExpression|React functional component for building UI of the current alert type params.| |defaultActionMessage|Optional property for providing default message for all added actions with `message` property.| +|requiresAppContext|Define if alert type is enabled for create and edit in the alerting management UI.| IMPORTANT: The current UI supports a single action group only. Action groups are mapped from the server API result for [GET /api/alert/types: List alert types](https://github.com/elastic/kibana/tree/master/x-pack/legacy/plugins/alerting#get-apialerttypes-list-alert-types). @@ -262,6 +263,7 @@ export interface AlertType { }; actionGroups: string[]; executor: ({ services, params, state }: AlertExecutorOptions) => Promise; + requiresAppContext: boolean; } ``` Only the default (which means first item of the array) action group is displayed in the current UI. @@ -308,7 +310,7 @@ export function getAlertType(): AlertTypeModel { alertParamsExpression: ExampleExpression, validate: validateExampleAlertType, defaultActionMessage: 'Alert [{{ctx.metadata.name}}] has exceeded the threshold', - isEditable: true, + requiresAppContext: true, }; } ``` diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/index.ts b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/index.ts index 3e0eb31217ef0..ee441136b4e8b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/index.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/index.ts @@ -14,6 +14,6 @@ export function getAlertType(): AlertTypeModel { iconClass: 'alert', alertParamsExpression: IndexThresholdAlertTypeExpression, validate: validateExpression, - isEditable: true, + requiresAppContext: true, }; } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx index 60f2536926294..3f1cbd4a8f495 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx @@ -26,7 +26,7 @@ describe('action_form', () => { return { errors: {} }; }, alertParamsExpression: () => , - isEditable: true, + requiresAppContext: true, }; const actionType = { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx index 41ae113f7acab..c8b70fb00cc63 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx @@ -44,7 +44,7 @@ jest.mock('../../../app_context', () => ({ validate: (): ValidationResult => { return { errors: {} }; }, - isEditable: true, + requiresAppContext: true, }), list: jest.fn(), }, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx index 12ee50afc5896..44abfc94e7795 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx @@ -75,7 +75,7 @@ export const AlertDetails: React.FunctionComponent = ({ const actionTypesByTypeId = indexBy(actionTypes, 'id'); const hasEditButton = canSave && alertTypeRegistry.has(alert.alertTypeId) - ? alertTypeRegistry.get(alert.alertTypeId).isEditable + ? alertTypeRegistry.get(alert.alertTypeId).requiresAppContext : false; const alertActions = alert.actions; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx index 6d26c5d8b8acd..e6b971d4ac0db 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx @@ -71,7 +71,7 @@ describe('alert_add', () => { return { errors: {} }; }, alertParamsExpression: TestExpression, - isEditable: true, + requiresAppContext: true, }; const actionTypeModel = { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx index ab65e49e62dfe..db9aef4c9990f 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx @@ -55,7 +55,7 @@ describe('alert_edit', () => { return { errors: {} }; }, alertParamsExpression: () => , - isEditable: true, + requiresAppContext: true, }; const actionTypeModel = { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx index 99c2fec579202..fe2dac3dd6c10 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx @@ -29,7 +29,7 @@ describe('alert_form', () => { return { errors: {} }; }, alertParamsExpression: () => , - isEditable: true, + requiresAppContext: true, }; const actionType = { @@ -55,7 +55,7 @@ describe('alert_form', () => { return { errors: {} }; }, alertParamsExpression: () => , - isEditable: false, + requiresAppContext: false, }; describe('alert_form create alert', () => { @@ -206,7 +206,7 @@ describe('alert_form', () => { return { errors: {} }; }, alertParamsExpression: () => , - isEditable: false, + requiresAppContext: false, }, { id: 'other-consumer-producer-alert-type', @@ -216,7 +216,7 @@ describe('alert_form', () => { return { errors: {} }; }, alertParamsExpression: () => , - isEditable: true, + requiresAppContext: true, }, ]); alertTypeRegistry.has.mockReturnValue(true); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx index ba10a57a04d5f..6383448a07b61 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx @@ -170,7 +170,9 @@ export const AlertForm = ({ alert.consumer === 'alerting' ? alertTypeRegistry .list() - .filter((alertTypeRegistryItem: AlertTypeModel) => alertTypeRegistryItem.isEditable) + .filter( + (alertTypeRegistryItem: AlertTypeModel) => alertTypeRegistryItem.requiresAppContext + ) : alertTypeRegistry .list() .filter( diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx index aec733458d43a..f5d86b2d59d2a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx @@ -44,7 +44,7 @@ const alertType = { return { errors: {} }; }, alertParamsExpression: () => null, - isEditable: true, + requiresAppContext: true, }; alertTypeRegistry.list.mockReturnValue([alertType]); actionTypeRegistry.list.mockReturnValue([]); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts index 7cbaaf4196054..d88982ed2e963 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts @@ -20,7 +20,7 @@ const getTestAlertType = (id?: string, name?: string, iconClass?: string) => { return { errors: {} }; }, alertParamsExpression: ExpressionComponent, - isEditable: true, + requiresAppContext: true, }; }; diff --git a/x-pack/plugins/triggers_actions_ui/public/types.ts b/x-pack/plugins/triggers_actions_ui/public/types.ts index d22d56a4738b6..8aadee8a993ac 100644 --- a/x-pack/plugins/triggers_actions_ui/public/types.ts +++ b/x-pack/plugins/triggers_actions_ui/public/types.ts @@ -117,7 +117,7 @@ export interface AlertTypeModel { iconClass: string; validate: (alertParams: any) => ValidationResult; alertParamsExpression: React.FunctionComponent; - isEditable: boolean; + requiresAppContext: boolean; defaultActionMessage?: string; } diff --git a/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx b/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx index 8f33127f86e62..b805ca21a4359 100644 --- a/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx +++ b/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx @@ -66,5 +66,5 @@ export const initMonitorStatusAlertType: AlertTypeInitializer = ({ alertParamsExpression: params => , validate, defaultActionMessage, - isEditable: false, + requiresAppContext: false, }); diff --git a/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx b/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx index 2b613f622572c..dbafa4e927922 100644 --- a/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx +++ b/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx @@ -20,5 +20,5 @@ export const initTlsAlertType: AlertTypeInitializer = (): AlertTypeModel => ({ name, validate: () => ({ errors: {} }), defaultActionMessage, - isEditable: false, + requiresAppContext: false, }); diff --git a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts index f62a3216c8940..d7ccd402b49af 100644 --- a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts +++ b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts @@ -34,7 +34,7 @@ export class AlertingFixturePlugin implements Plugin { return { errors: {} }; }, - isEditable: true, + requiresAppContext: true, }); triggers_actions_ui.alertTypeRegistry.register({ @@ -45,7 +45,7 @@ export class AlertingFixturePlugin implements Plugin { return { errors: {} }; }, - isEditable: true, + requiresAppContext: true, }); core.application.register({