import type { FormikProps } from 'formik'; import React from 'react'; import type { Application, DeckRuntimeServices, IModalComponentProps } from '@spinnaker/core'; import { CheckboxInput, confirmNotManaged, DeckRuntimeContext, FormikFormField, HelpField, NumberInput, ReactModal, ReactSelectInput, TaskMonitorModal, } from '@spinnaker/core'; import type { AwsServerGroupCommandBuilder } from '../../configure/serverGroupCommandBuilder.service'; import type { IAmazonServerGroupCommand } from '../../configure/serverGroupConfiguration.service'; import type { IAmazonServerGroup } from '../../../domain'; export interface IEditAsgAdvancedSettingsModalProps extends IModalComponentProps { application: Application; serverGroup: IAmazonServerGroup; } export function validateRequiredNonNegativeNumber(value: unknown): string | undefined { return typeof value !== 'number' || !Number.isFinite(value) || value < 0 ? 'Enter a finite non-negative number' : undefined; } export class EditAsgAdvancedSettingsModal extends React.Component { public static contextType = DeckRuntimeContext; public declare context: React.ContextType; private directCommand: Partial; public static show(props: IEditAsgAdvancedSettingsModalProps, runtimeServices: DeckRuntimeServices) { return confirmNotManaged(props.serverGroup, props.application).then( (notManaged) => notManaged && ReactModal.show(EditAsgAdvancedSettingsModal, props, { dialogClassName: 'modal-lg' }, runtimeServices), ); } private get command(): Partial { return (this.directCommand ||= this.context.services.providerServiceDelegate .getDelegate('aws', 'serverGroup.commandBuilder') .buildUpdateServerGroupCommand(this.props.serverGroup)); } private renderFields = (formik: FormikProps) => { const { backingData } = formik.values; return ( <> } required={true} validate={validateRequiredNonNegativeNumber} /> } input={(props) => ( )} /> ( )} /> } required={true} validate={validateRequiredNonNegativeNumber} /> ( )} /> } input={(props) => } /> ); }; public render() { const { application, closeModal, dismissModal, serverGroup } = this.props; return ( application={application} closeModal={closeModal} description={`Update Advanced Settings for ${serverGroup.name}`} dismissModal={dismissModal} initialValues={this.command as IAmazonServerGroupCommand} mapValuesToTask={(command) => ({ application, job: [command] })} render={this.renderFields} title={`Edit Advanced Settings for ${serverGroup.name}`} /> ); } }