import React from 'react'; import type { Option } from 'react-select'; import VirtualizedSelect from 'react-virtualized-select'; import type { ISecurityGroup } from '@spinnaker/core'; import { FirewallLabels, HelpField, InfrastructureCaches, ReactInjector, timestamp } from '@spinnaker/core'; import type { IAmazonServerGroupCommand } from '../../serverGroupConfiguration.service'; export interface ISecurityGroupSelectorProps { command: IAmazonServerGroupCommand; availableGroups: ISecurityGroup[]; hideLabel?: boolean; refresh?: () => Promise; groupsToEdit: string[]; helpKey?: string; onChange: (securityGroups: string[]) => void; } export interface ISecurityGroupSelectorState { refreshing: boolean; refreshTime: number; } export class SecurityGroupSelector extends React.Component { constructor(props: ISecurityGroupSelectorProps) { super(props); this.state = { refreshing: false, refreshTime: InfrastructureCaches.get('securityGroups').getStats().ageMax, }; } private refreshSecurityGroups = () => { this.setState({ refreshing: true }); if (this.props.refresh) { this.props.refresh().then(() => this.setState({ refreshing: false })); } else { (ReactInjector.providerServiceDelegate.getDelegate( this.props.command.selectedProvider, 'serverGroup.configurationService', ) as any) .refreshSecurityGroups(this.props.command) .then(() => { this.setState({ refreshing: false, refreshTime: InfrastructureCaches.get('securityGroups').getStats().ageMax, }); }); } }; private onChange = (options: Option[]) => { const securityGroups = options.map((o) => o.value as string); this.props.onChange(securityGroups); }; public render() { const { availableGroups, groupsToEdit, helpKey, hideLabel } = this.props; const { refreshing, refreshTime } = this.state; const availableGroupOptions = availableGroups.map((g) => ({ label: `${g.name} (${g.id})`, value: g.id })); return ( <>
{!hideLabel && (
{FirewallLabels.get('Firewalls')} {helpKey && }
)}

{refreshing && ( )} {FirewallLabels.get('Firewalls')} {!refreshing && last refreshed {timestamp(refreshTime)}} {refreshing && refreshing...}

If you're not finding a {FirewallLabels.get('firewall')} that was recently added,{' '} click here {' '} to refresh the list.

); } }