import type { ServiceStatusLevel } from '../../../../types/status' ; import { FormattedStatus , StatusState , STATUS_LEVEL_UI_ATTRS } from './load_status' ; export const orderedLevels = [ 'critical' , 'unavailable' , 'degraded' , 'available' , ] ; export const groupByLevel = ( statuses ) => { return statuses . reduce ( ( map , status ) => { const existing = map . get ( status . state . id ) ?? [ ] ; map . set ( status . state . id , [ ... existing , status ] ) ; return map ; } , new Map < ServiceStatusLevel , FormattedStatus [ ] > ( ) ) ; } ; export const getHighestStatus = ( statuses ) : Omit < StatusState , 'message' > => { const grouped = groupByLevel ( statuses ) ; for ( const level of orderedLevels ) { if ( grouped . has ( level ) && grouped . get ( level ) ! . length ) { const { message , ... status } = grouped . get ( level ) ! [ 0 ] . state ; return status ; } } return { id : 'available' , title : STATUS_LEVEL_UI_ATTRS . available . title , uiColor : STATUS_LEVEL_UI_ATTRS . available . uiColor , } ; } ; export const getLevelSortValue = ( status ) => { return orderedLevels . indexOf ( status . state . id ) ; } ;