import * as React from 'react'; import { LabeledValue, LabeledValueList } from '@spinnaker/core'; import { MetricAlarmChart } from '../chart/MetricAlarmChart'; import type { IAmazonServerGroup, IScalingPolicyAlarmView, IScalingPolicyView, IStepAdjustmentView, } from '../../../../domain'; import { comparatorMap } from '../popover/AlarmSummary'; export interface IStepPolicyPopoverContentProps { policy: IScalingPolicyView; serverGroup: IAmazonServerGroup; } export const StepPolicyPopoverContent = ({ policy, serverGroup }: IStepPolicyPopoverContentProps) => { const { adjustmentType, alarms, cooldown, estimatedInstanceWarmup, minAdjustmentMagnitude, stepAdjustments } = policy; const showWait = cooldown ? true : stepAdjustments?.[0]?.operator === 'decrease'; const alarm = alarms[0] || ({} as IScalingPolicyAlarmView); const isGreater = alarm?.comparisonOperator.includes('Greater'); const getAdjustmentTypeString = (step: IScalingPolicyView | IStepAdjustmentView): string => { if (adjustmentType === 'ExactCapacity') { return `set capacity to ${step.scalingAdjustment} instance${step.scalingAdjustment > 1 ? 's' : ''}`; } return `${step.operator} capacity by ${step.absAdjustment}${ adjustmentType === 'PercentChangeInCapacity' ? '%' : ' instance' }${adjustmentType === 'ChangeInCapacity' && step.absAdjustment > 1 ? 's' : ''}`; }; const getBoundaryStr = (step: IStepAdjustmentView) => { const middleBounds = step.metricIntervalLowerBound !== undefined && step.metricIntervalUpperBound !== undefined ? `is between ${alarm.threshold + step.metricIntervalLowerBound} and ${ alarm.threshold + step.metricIntervalUpperBound } ` : ''; const sourceBound = isGreater ? step.metricIntervalLowerBound : step.metricIntervalUpperBound; const finalBound = `is ${isGreater ? 'greater' : 'less'} than ${alarm.threshold + sourceBound}`; return `if ${alarm.metricName} ${middleBounds}${finalBound}`; }; return (