import React from 'react'; import { CollapsibleSection, Tooltip } from '@spinnaker/core'; import type { IAmazonServerGroupDetailsSectionProps } from './IAmazonServerGroupDetailsSectionProps'; import { AWSProviderSettings } from '../../../aws.settings'; import type { IScalingProcess } from '../../../domain'; import { AutoScalingProcessService } from '../scalingProcesses/AutoScalingProcessService'; import { ScheduledAction } from '../scheduledAction/ScheduledAction'; import { EditScheduledActionsModal } from '../scheduledActions'; export interface IScheduledActionsDetailsSectionState { scheduledActionsDisabled: boolean; } export class ScheduledActionsDetailsSection extends React.Component< IAmazonServerGroupDetailsSectionProps, IScheduledActionsDetailsSectionState > { constructor(props: IAmazonServerGroupDetailsSectionProps) { super(props); this.state = this.getState(props); } private getState(props: IAmazonServerGroupDetailsSectionProps): IScheduledActionsDetailsSectionState { const { serverGroup } = props; const autoScalingProcesses: IScalingProcess[] = AutoScalingProcessService.normalizeScalingProcesses(serverGroup); const scheduledActionsDisabled = serverGroup.scheduledActions.length > 0 && autoScalingProcesses .filter((p) => !p.enabled) .some((p) => ['Launch', 'Terminate', 'ScheduledAction'].includes(p.name)); return { scheduledActionsDisabled }; } public componentWillReceiveProps(nextProps: IAmazonServerGroupDetailsSectionProps): void { this.setState(this.getState(nextProps)); } private editScheduledActions = (): void => { const { app: application, serverGroup } = this.props; EditScheduledActionsModal.show({ application, serverGroup }); }; public render(): JSX.Element { const { serverGroup } = this.props; const { scheduledActionsDisabled } = this.state; return ( (

{chevron} {scheduledActionsDisabled && ( )} Scheduled Actions

)} > {serverGroup.scheduledActions.map((action, index) => ( ))} {serverGroup.scheduledActions.length > 0 && (

Note: Schedules are evaluated in UTC.

)} {serverGroup.scheduledActions.length === 0 &&

No Scheduled Actions are configured for this server group.

} {AWSProviderSettings.adHocInfraWritesEnabled && ( Edit Scheduled Actions )}
); } }