import { VALIDATION_STATUS } from '../constants/validation' ; const contains = ( arr , str ) => arr . indexOf ( str ) >= 0 ; export function getMostSevereMessageStatus ( messages ) { 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 ) { if ( json === null ) { return false ; } try { JSON . parse ( json ) ; return true ; } catch ( error ) { return false ; } } export function findAggField ( aggs , fieldName , returnParent = false ) { if ( fieldName === undefined ) return ; let value ; Object . keys ( aggs ) . some ( function ( k ) { if ( k === fieldName ) { value = returnParent === true ? aggs : aggs [ k ] ; return true ; } if ( aggs . hasOwnProperty ( k ) && aggs [ k ] !== null && typeof aggs [ k ] === 'object' ) { value = findAggField ( aggs [ k ] , fieldName , returnParent ) ; return value !== undefined ; } } ) ; return value ; } export function isValidAggregationField ( aggs , fieldName ) { return findAggField ( aggs , fieldName ) !== undefined ; }