kibana/x-pack/plugins/ml/common/util/validation_utils.ts
James Gowdy 35302ed273
[ML] Client side cut over (#60100)
* [ML] Client side cut over

* updating paths and commented code

* changes based on review

* disabling telemetry tests

* fixing start job stylesheets

* fixing everything that is broken

* fixing types and ml icon order

* using icon constant
2020-03-13 19:16:41 +00:00

33 lines
999 B
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { VALIDATION_STATUS } from '../constants/validation';
// get the most severe status level from a list of messages
const contains = (arr: string[], str: string) => arr.indexOf(str) >= 0;
export function getMostSevereMessageStatus(messages: Array<{ status: string }>): VALIDATION_STATUS {
const statuses = messages.map(m => m.status);
return [VALIDATION_STATUS.INFO, VALIDATION_STATUS.WARNING, VALIDATION_STATUS.ERROR].reduce(
(previous, current) => {
return contains(statuses, current) ? current : previous;
},
VALIDATION_STATUS.SUCCESS
);
}
export function isValidJson(json: string) {
if (json === null) {
return false;
}
try {
JSON.parse(json);
return true;
} catch (error) {
return false;
}
}