Skip to content

Commit

Permalink
Fixed due to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed May 11, 2020
1 parent a1efef8 commit 595eb69
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getAlertType(): AlertTypeModel {
}
return validationResult;
},
isEditable: true,
requiresAppContext: true,
};
}

Expand Down
2 changes: 1 addition & 1 deletion examples/alerting_example/public/alert_types/astros.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function getAlertType(): AlertTypeModel {

return validationResult;
},
isEditable: true,
requiresAppContext: true,
};
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
validate: () => ({
errors: []
}),
isEditable: false
requiresAppContext: false
});

plugins.triggers_actions_ui.alertTypeRegistry.register({
Expand All @@ -129,7 +129,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
validate: () => ({
errors: []
}),
isEditable: false
requiresAppContext: false
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ Reason:
`,
}
),
isEditable: true,
requiresAppContext: true,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ Current value is \\{\\{context.valueOf.condition0\\}\\}
`,
}
),
isEditable: true,
requiresAppContext: true,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export function getAlertType(): AlertTypeModel {
defaultMessage: `\\{\\{context.matchingDocuments\\}\\} log entries have matched the following conditions: \\{\\{context.conditions\\}\\}`,
}
),
isEditable: true,
requiresAppContext: true,
};
}
6 changes: 4 additions & 2 deletions x-pack/plugins/triggers_actions_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function getAlertType(): AlertTypeModel {
iconClass: 'alert',
alertParamsExpression: IndexThresholdAlertTypeExpression,
validate: validateAlertType,
isEditable: true,
requiresAppContext: true,
};
}
```
Expand Down Expand Up @@ -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).
Expand All @@ -262,6 +263,7 @@ export interface AlertType {
};
actionGroups: string[];
executor: ({ services, params, state }: AlertExecutorOptions) => Promise<State | void>;
requiresAppContext: boolean;
}
```
Only the default (which means first item of the array) action group is displayed in the current UI.
Expand Down Expand Up @@ -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,
};
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export function getAlertType(): AlertTypeModel {
iconClass: 'alert',
alertParamsExpression: IndexThresholdAlertTypeExpression,
validate: validateExpression,
isEditable: true,
requiresAppContext: true,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('action_form', () => {
return { errors: {} };
},
alertParamsExpression: () => <Fragment />,
isEditable: true,
requiresAppContext: true,
};

const actionType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jest.mock('../../../app_context', () => ({
validate: (): ValidationResult => {
return { errors: {} };
},
isEditable: true,
requiresAppContext: true,
}),
list: jest.fn(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('alert_add', () => {
return { errors: {} };
},
alertParamsExpression: TestExpression,
isEditable: true,
requiresAppContext: true,
};

const actionTypeModel = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('alert_edit', () => {
return { errors: {} };
},
alertParamsExpression: () => <React.Fragment />,
isEditable: true,
requiresAppContext: true,
};

const actionTypeModel = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('alert_form', () => {
return { errors: {} };
},
alertParamsExpression: () => <Fragment />,
isEditable: true,
requiresAppContext: true,
};

const actionType = {
Expand All @@ -55,7 +55,7 @@ describe('alert_form', () => {
return { errors: {} };
},
alertParamsExpression: () => <Fragment />,
isEditable: false,
requiresAppContext: false,
};

describe('alert_form create alert', () => {
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('alert_form', () => {
return { errors: {} };
},
alertParamsExpression: () => <Fragment />,
isEditable: false,
requiresAppContext: false,
},
{
id: 'other-consumer-producer-alert-type',
Expand All @@ -216,7 +216,7 @@ describe('alert_form', () => {
return { errors: {} };
},
alertParamsExpression: () => <Fragment />,
isEditable: true,
requiresAppContext: true,
},
]);
alertTypeRegistry.has.mockReturnValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const alertType = {
return { errors: {} };
},
alertParamsExpression: () => null,
isEditable: true,
requiresAppContext: true,
};
alertTypeRegistry.list.mockReturnValue([alertType]);
actionTypeRegistry.list.mockReturnValue([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getTestAlertType = (id?: string, name?: string, iconClass?: string) => {
return { errors: {} };
},
alertParamsExpression: ExpressionComponent,
isEditable: true,
requiresAppContext: true,
};
};

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/triggers_actions_ui/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface AlertTypeModel {
iconClass: string;
validate: (alertParams: any) => ValidationResult;
alertParamsExpression: React.FunctionComponent<any>;
isEditable: boolean;
requiresAppContext: boolean;
defaultActionMessage?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ export const initMonitorStatusAlertType: AlertTypeInitializer = ({
alertParamsExpression: params => <AlertMonitorStatus {...params} autocomplete={autocomplete} />,
validate,
defaultActionMessage,
isEditable: false,
requiresAppContext: false,
});
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/public/lib/alert_types/tls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export const initTlsAlertType: AlertTypeInitializer = (): AlertTypeModel => ({
name,
validate: () => ({ errors: {} }),
defaultActionMessage,
isEditable: false,
requiresAppContext: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamp
validate: () => {
return { errors: {} };
},
isEditable: true,
requiresAppContext: true,
});

triggers_actions_ui.alertTypeRegistry.register({
Expand All @@ -45,7 +45,7 @@ export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamp
validate: () => {
return { errors: {} };
},
isEditable: true,
requiresAppContext: true,
});

core.application.register({
Expand Down

0 comments on commit 595eb69

Please sign in to comment.