import React from 'react'; import type { IAccount, IStageConfigProps } from '@spinnaker/core'; import { AccountRegionClusterSelector, AccountService, ChecklistInput, StageConfigField, StageConstants, } from '@spinnaker/core'; const ACTIONS = [ { label: 'Suspend', value: 'suspend' }, { label: 'Resume', value: 'resume' }, ]; const SCALING_PROCESSES = [ 'Launch', 'Terminate', 'AddToLoadBalancer', 'AlarmNotification', 'AZRebalance', 'HealthCheck', 'ReplaceUnhealthy', 'ScheduledActions', ]; export function ModifyScalingProcessStageConfig({ application, pipeline, stage, updateStage, updateStageField, }: IStageConfigProps) { const [accounts, setAccounts] = React.useState([]); React.useEffect(() => { let mounted = true; AccountService.listAccounts('aws').then((loadedAccounts) => mounted && setAccounts(loadedAccounts)); return () => { mounted = false; }; }, []); React.useEffect(() => { const defaults: Record = {}; const defaultCredentials = application.defaultCredentials.aws; const defaultRegion = application.defaultRegions.aws; if (!stage.cloudProvider) { defaults.cloudProvider = 'aws'; } if (!stage.processes) { defaults.processes = []; } if (!stage.regions) { defaults.regions = defaultRegion ? [defaultRegion] : []; } else if (!stage.regions.length && defaultRegion) { defaults.regions = [defaultRegion]; } if (!stage.credentials && defaultCredentials) { defaults.credentials = defaultCredentials; } if (!stage.action) { defaults.action = ACTIONS[0].value; } if (!stage.target) { defaults.target = StageConstants.TARGET_LIST[0].val; } if (stage.suspendProcesses !== undefined || stage.resumeProcesses !== undefined) { defaults.suspendProcesses = undefined; defaults.resumeProcesses = undefined; } if (Object.keys(defaults).length) { updateStageField(defaults); } }, [ application.defaultCredentials.aws, application.defaultRegions.aws, stage.action, stage.cloudProvider, stage.credentials, stage.processes, stage.regions, stage.resumeProcesses, stage.suspendProcesses, stage.target, updateStageField, ]); return (
{!pipeline.strategy && ( )} updateStageField({ processes: event.target.value })} showSelectAll={true} stringOptions={SCALING_PROCESSES} value={stage.processes || []} />
); }