import React from 'react'; export interface InstanceLoadBalancer { healthState?: string; // (usually present but) optional because there's a fallback state?: string; // (usually present but) optional because it is the fallback name?: string; // optional because there's a fallback (depends on source of data) loadBalancerName?: string; // optional because it is the fallback (depends on source of data) description?: string; // optional because there usually isn't a useful description when things are healthy healthCheckPath?: string; healthCheckProtocol?: string; } export interface IInstanceLoadBalancerHealthProps { loadBalancer: InstanceLoadBalancer; ipAddress?: string; } export class InstanceLoadBalancerHealth extends React.Component { public render() { const { loadBalancer: { healthState, state, name, description, loadBalancerName, healthCheckProtocol, healthCheckPath }, ipAddress, } = this.props; const health = healthState || (state === 'InService' ? 'Up' : 'OutOfService'); let icon = null; if (health === 'Up') { icon = ; } else if (health === 'OutOfService' || health === 'Down') { icon = ; } else if (health === 'Starting') { icon = ; } const displayName = {name || loadBalancerName}; const downReason = healthState !== 'Up' && !!description ? ( {description} ) : null; const healthCheck = healthCheckProtocol?.toLowerCase().startsWith('http') ? ( Health Check ) : ( `${healthCheckProtocol}://${ipAddress}${healthCheckPath}` ); return (
{icon}
{displayName} {downReason} {ipAddress && healthCheckPath && healthCheck}
); } }