import _ from 'lodash' ; import moment , { Moment } from 'moment' ; import { Optional } from '@kbn/utility-types' ; import { Filter , TimeRange , RefreshInterval } from '../../services/data' ; type TimeRangeCompare = Optional < TimeRange > ; type RefreshIntervalCompare = Optional < RefreshInterval > ; param time { string | Moment } returns export const convertTimeToUTCString = ( time ? ) : undefined | string => { if ( moment ( time ) . isValid ( ) ) { return moment ( time ) . utc ( ) . format ( 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' ) ; } else { return time as string ; } } ; export const areTimeRangesEqual = ( rangeA , rangeB ) : boolean => areTimesEqual ( rangeA . from , rangeB . from ) && areTimesEqual ( rangeA . to , rangeB . to ) ; export const areRefreshIntervalsEqual = ( refreshA ? , refreshB ? ) : boolean => refreshA ?. pause === refreshB ?. pause && refreshA ?. value === refreshB ?. value ; param timeA { string | Moment } param timeB { string | Moment } returns { boolean } export const areTimesEqual = ( timeA ? , timeB ? ) => { return convertTimeToUTCString ( timeA ) === convertTimeToUTCString ( timeB ) ; } ; param filters { Array . < Object > } returns { Array . < Object > } export const cleanFiltersForComparison = ( filters ) => { return _ . map ( filters , ( filter ) => { const f = _ . omit ( filter , [ '$$hashKey' , '$state' ] ) ; if ( f . meta ) { return _ . omit ( f . meta , [ 'value' ] ) ; } return f ; } ) ; } ; export const cleanFiltersForSerialize = ( filters ) : Filter [ ] => { return filters . map ( ( filter ) => { if ( filter . meta ?. value ) { delete filter . meta . value ; } return filter ; } ) ; } ;