import * as React from 'react'; import { NumberInput, ReactSelectInput } from '@spinnaker/core'; import './SimplePolicyAction.less'; type Operator = 'Add' | 'Remove' | 'Set to'; type AdjustmentTypeView = 'instances' | 'percent of group'; export interface ISimplePolicyActionProps { adjustmentType: AdjustmentTypeView; adjustmentTypeChanged: (action: Operator, type: AdjustmentTypeView) => void; operator: Operator; scalingAdjustment: number; updateScalingAdjustment: (adjustment: number) => void; } export const SimplePolicyAction = ({ adjustmentType, adjustmentTypeChanged, operator, scalingAdjustment, updateScalingAdjustment, }: ISimplePolicyActionProps) => { const availableActions = ['Add', 'Remove', 'Set to']; const adjustmentTypeOptions = operator === 'Set to' ? ['instances'] : ['instances', 'percent of group']; const onActionChange = (val: Operator) => { adjustmentTypeChanged(val, adjustmentType); }; const [adjustmentTypeView, setAdjustmentTypeView] = React.useState(adjustmentType); const onAdjustmentTypeChange = (type: AdjustmentTypeView) => { setAdjustmentTypeView(type); adjustmentTypeChanged(operator, type); }; const [adjustment, setAdjustment] = React.useState(scalingAdjustment); const onScalingAdjustmentChange = (adj: number) => { setAdjustment(adj); updateScalingAdjustment(adj); }; return (
onActionChange(e.target.value)} clearable={false} inputClassName="action-input" /> onScalingAdjustmentChange(Number.parseInt(e.target.value))} inputClassName="action-input" /> onAdjustmentTypeChange(e.target.value)} clearable={false} inputClassName="adjustment-type-input" />
); };