[Synthetics] i18n for monitor validation errors (#155721)

## Summary

Resolves https://github.com/elastic/kibana/issues/154880

Adds i18n for errors from project monitors
This commit is contained in:
Dominique Clarke 2023-05-10 16:10:28 -04:00 committed by GitHub
parent cb7c0f4a6b
commit d391c669d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,7 +60,7 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult
if (isLeft(decodedType)) {
return {
valid: false,
reason: `Monitor type is invalid`,
reason: INVALID_TYPE_ERROR,
details: formatErrors(decodedType.left).join(' | '),
payload: monitorFields,
};
@ -72,7 +72,7 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult
if (!SyntheticsMonitorCodec) {
return {
valid: false,
reason: `Payload is not a valid monitor object`,
reason: INVALID_PAYLOAD_ERROR,
details: '',
payload: monitorFields,
};
@ -81,10 +81,8 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult
if (!ALLOWED_SCHEDULES_IN_MINUTES.includes(monitorFields[ConfigKey.SCHEDULE].number)) {
return {
valid: false,
reason: `Monitor schedule is invalid`,
details: `Invalid schedule ${
monitorFields[ConfigKey.SCHEDULE].number
} minutes supplied to monitor configuration. Please use a supported monitor schedule.`,
reason: INVALID_SCHEDULE_ERROR,
details: INVALID_SCHEDULE_DETAILS(monitorFields[ConfigKey.SCHEDULE].number),
payload: monitorFields,
};
}
@ -95,7 +93,7 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult
if (isLeft(decodedMonitor)) {
return {
valid: false,
reason: `Monitor is not a valid monitor of type ${monitorType}`,
reason: INVALID_SCHEMA_ERROR(monitorType),
details: formatErrors(decodedMonitor.left).join(' | '),
payload: monitorFields,
};
@ -122,7 +120,7 @@ export function validateProjectMonitor(
if (isLeft(decodedMonitor)) {
return {
valid: false,
reason: "Couldn't save or update monitor because of an invalid configuration.",
reason: INVALID_CONFIGURATION_ERROR,
details: [...formatErrors(decodedMonitor.left), locationsError]
.filter((error) => error !== '' && error !== undefined)
.join(' | '),
@ -133,7 +131,7 @@ export function validateProjectMonitor(
if (locationsError) {
return {
valid: false,
reason: "Couldn't save or update monitor because of an invalid configuration.",
reason: INVALID_CONFIGURATION_ERROR,
details: locationsError,
payload: monitorFields,
};
@ -202,6 +200,48 @@ export function validateLocation(
}
}
const INVALID_CONFIGURATION_ERROR = i18n.translate(
'xpack.synthetics.server.monitors.invalidConfigurationError',
{
defaultMessage: "Couldn't save or update monitor because of an invalid configuration.",
}
);
const INVALID_PAYLOAD_ERROR = i18n.translate(
'xpack.synthetics.server.monitors.invalidPayloadError',
{
defaultMessage: 'Payload is not a valid monitor object',
}
);
const INVALID_TYPE_ERROR = i18n.translate('xpack.synthetics.server.monitors.invalidTypeError', {
defaultMessage: 'Monitor type is invalid',
});
const INVALID_SCHEDULE_ERROR = i18n.translate(
'xpack.synthetics.server.monitors.invalidScheduleError',
{
defaultMessage: 'Monitor schedule is invalid',
}
);
const INVALID_SCHEDULE_DETAILS = (schedule: string) =>
i18n.translate('xpack.synthetics.server.monitors.invalidScheduleDetails', {
defaultMessage:
'Invalid schedule {schedule} minutes supplied to monitor configuration. Please use a supported monitor schedule.',
values: {
schedule,
},
});
const INVALID_SCHEMA_ERROR = (type: string) =>
i18n.translate('xpack.synthetics.server.monitors.invalidSchemaError', {
defaultMessage: 'Monitor is not a valid monitor of type {type}',
values: {
type,
},
});
const EMPTY_LOCATION_ERROR = i18n.translate(
'xpack.synthetics.server.projectMonitors.locationEmptyError',
{