import * as React from 'react'; import { NumberInput, ReactSelectInput } from '@spinnaker/core'; import type { IScalingPolicyAlarm, IStepAdjustment } from '../../../../../domain'; import './StepPolicyAction.less'; export type Operator = 'Add' | 'Remove' | 'Set to'; export type AdjustmentTypeView = 'instances' | 'percent of group'; export interface IStepPolicyActionProps { adjustmentType: AdjustmentTypeView; adjustmentTypeChanged: (action: Operator, type: AdjustmentTypeView) => void; alarm: IScalingPolicyAlarm; isMin: boolean; operator: Operator; step: { stepAdjustments: IStepAdjustment[] }; stepAdjustments?: IStepAdjustment[]; stepsChanged: (steps: IStepAdjustment[]) => void; } export const StepPolicyAction = ({ adjustmentType, adjustmentTypeChanged, alarm, isMin, operator, step, stepAdjustments, stepsChanged, }: IStepPolicyActionProps) => { const hasEqualTo = alarm?.comparisonOperator.includes('Equal'); const availableActions = ['Add', 'Remove', 'Set to']; const adjustmentTypeOptions = operator === 'Set to' ? ['instances'] : ['instances', 'percent of group']; const onActionChange = (val: Operator) => { adjustmentTypeChanged(val, adjustmentType); }; const onAdjustmentTypeChange = (type: AdjustmentTypeView) => { adjustmentTypeChanged(operator, type); }; const steps = step?.stepAdjustments || stepAdjustments; const addStep = () => { const newStep = { scalingAdjustment: 1 } as IStepAdjustment; const newSteps = [...steps, newStep]; stepsChanged(newSteps); }; const removeStep = (index: number) => { const newSteps = steps.filter((_s, i) => i !== index); stepsChanged(newSteps); }; const updateStep = (updatedStep: IStepAdjustment, index: number) => { const newSteps = [...steps]; newSteps[index] = updatedStep; stepsChanged(newSteps); }; return (