import React from 'react'; import type { IAccount, IStageConfigProps } from '@spinnaker/core'; import { AccountRegionClusterSelector, AccountService, StageConfigField, StageConstants } from '@spinnaker/core'; const ACTIONS = [ { label: 'Upsert', value: 'upsert' }, { label: 'Delete', value: 'delete' }, ]; const POOL_STATES = ['Stopped', 'Running', 'Hibernated']; export function ModifyWarmPoolStageConfig({ 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.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.poolState) { defaults.poolState = POOL_STATES[0]; } if (Object.keys(defaults).length) { updateStageField(defaults); } }, [ application.defaultCredentials.aws, application.defaultRegions.aws, stage.action, stage.cloudProvider, stage.credentials, stage.poolState, stage.regions, stage.target, updateStageField, ]); const isUpsert = (stage.action || ACTIONS[0].value) === 'upsert'; return (
{!pipeline.strategy && ( )} {isUpsert && ( <> updateStageField({ minSize: Number(event.target.value) })} value={stage.minSize ?? 0} /> updateStageField({ maxGroupPreparedCapacity: Number(event.target.value) })} value={stage.maxGroupPreparedCapacity ?? -1} /> updateStageField({ reuseOnScaleIn: event.target.checked })} /> )}
); }