import React from 'react' ; import { Dropdown } from 'react-bootstrap' ; import type { Application } from '@spinnaker/core' ; import { AddEntityTagLinks , ApplicationReader , ConfirmationModalService , FunctionWriter , SETTINGS , } from '@spinnaker/core' ; import type { IFunctionFromStateParams } from './AmazonFunctionDetails' ; import { CreateLambdaFunction } from '../CreateLambdaFunction' ; import { AWSProviderSettings } from '../../aws.settings' ; import type { IAmazonFunction , IAmazonFunctionDeleteCommand } from '../../domain' ; export interface IFunctionActionsProps { app : Application ; functionDef : IAmazonFunction ; functionFromParams : IFunctionFromStateParams ; } export interface IFunctionActionsState { application : Application ; } export class FunctionActions extends React . Component < IFunctionActionsProps , IFunctionActionsState > { constructor ( props ) { super ( props ) ; this . state = { application : props . app } ; } public componentDidMount ( ) { const { app , functionDef } = this . props ; let application ; const functionAppName = functionDef . functionName . split ( '-' ) [ 0 ] ; if ( functionAppName === app . name ) { application = app ; } else { ApplicationReader . getApplication ( functionAppName ) . then ( ( functionApp ) => { this . setState ( { application : functionApp } ) ; } ) . catch ( ( ) => { this . setState ( { application : this . props . app } ) ; } ) ; } this . setState ( { application , } ) ; } public editFunction = ( ) : void => { const { functionDef } = this . props ; const { application } = this . state ; const FunctionModal = CreateLambdaFunction ; FunctionModal . show ( { app : application , functionDef } ) ; } ; public deleteFunction = ( ) : void => { const { app , functionDef , functionFromParams } = this . props ; const taskMonitor = { application : app , title : 'Deleting ' + functionFromParams . functionName , } ; const command = { cloudProvider : functionDef . cloudProvider , functionName : functionDef . functionName , region : functionDef . region , credentials : functionDef . credentials , } ; const submitMethod = ( ) => FunctionWriter . deleteFunction ( command , app ) ; ConfirmationModalService . confirm ( { header : `Really delete ${ functionFromParams . functionName } in ${ functionFromParams . region }: ${ functionFromParams . account }?` , buttonText : `Delete ${ functionFromParams . functionName }` , account : functionFromParams . account , taskMonitorConfig : taskMonitor , submitMethod , } ) ; } ; private entityTagUpdate = ( ) : void => { this . props . app . functions . refresh ( ) ; } ; public render ( ) { const { app , functionDef } = this . props ; const { application } = this . state ; return ( < div style = { { display : 'inline-block' } } > { AWSProviderSettings . adHocInfraWritesEnabled && ( < Dropdown className = "dropdown" id = "function-actions-dropdown" > < Dropdown . Toggle className = "btn btn-sm btn-primary dropdown-toggle" > < span > Function Actions < / span > < /Dropdown.Toggle> < Dropdown . Menu className = "dropdown-menu" > < li className = { ! application ? 'disabled' : '' } > < a className = "clickable" onClick = { this . editFunction } > Edit Function < /a> < /li> { functionDef . functionName && ( < li > < a className = "clickable" onClick = { this . deleteFunction } > Delete Function < /a> < /li>)} { SETTINGS && SETTINGS . feature . entityTags && ( < AddEntityTagLinks component = { functionDef } application = { app } entityType = "function" onUpdate = { this . entityTagUpdate } / > ) } < /Dropdown.Menu> < /Dropdown>)} < /div>); } }