import { UISref } from '@uirouter/react'; import React from 'react'; import type { Application, IRouterInjectedProps } from '@spinnaker/core'; import { AccountTag, CollapsibleSection, CopyToClipboard, HealthCounts, ManagedResourceDetailsIndicator, Spinner, withRouter, } from '@spinnaker/core'; import type { IAmazonApplicationLoadBalancer, ITargetGroup } from '../domain'; import { VpcTag } from '../vpc/VpcTag'; interface IAmazonTargetGroupDetailsState { loadBalancer?: IAmazonApplicationLoadBalancer; loading: boolean; targetGroup?: ITargetGroup; } interface ITargetGroupStateParams { accountId: string; loadBalancerName: string; name: string; provider: string; region: string; vpcId?: string; } interface ITargetGroupDetailsProps { accountId: string; app: Application; name: string; provider: string; targetGroup: ITargetGroupStateParams; } function elbProtocol(loadBalancer: IAmazonApplicationLoadBalancer): string { return loadBalancer.listeners?.some((listener) => listener.protocol === 'HTTPS') ? 'https:' : 'http:'; } export class TargetGroupDetailsComponent extends React.Component< ITargetGroupDetailsProps & IRouterInjectedProps, IAmazonTargetGroupDetailsState > { public state: IAmazonTargetGroupDetailsState = { loading: true }; private unsubscribeFromRefresh: () => void; private isUnmounted = false; public componentDidMount(): void { this.props.app .getDataSource('loadBalancers') .ready() .then(() => { if (this.isUnmounted) { return; } this.extractTargetGroup(); this.unsubscribeFromRefresh = this.props.app.getDataSource('loadBalancers').onRefresh(this.extractTargetGroup); }) .catch(() => { if (!this.isUnmounted) { this.setState({ loading: false }); } }); } public componentWillUnmount(): void { this.isUnmounted = true; if (this.unsubscribeFromRefresh) { this.unsubscribeFromRefresh(); } } private extractTargetGroup = (): void => { const { accountId, loadBalancerName, name, region } = this.props.targetGroup; const loadBalancer = this.props.app .getDataSource('loadBalancers') .data.find( (candidate: IAmazonApplicationLoadBalancer) => candidate.name === loadBalancerName && candidate.region === region && candidate.account === accountId, ); const targetGroup = loadBalancer?.targetGroups?.find((candidate: ITargetGroup) => candidate.name === name); if (!loadBalancer || !targetGroup) { this.autoClose(); return; } if (!this.isUnmounted) { this.setState({ loadBalancer, targetGroup, loading: false }); } }; private autoClose = (): void => { if (this.isUnmounted) { return; } this.props.stateService.params.allowModalToStayOpen = true; this.props.stateService.go('^', null, { location: 'replace' }); }; private closeDetails = (): void => { this.props.stateService.go('^'); }; private renderHeader(): JSX.Element { const { name } = this.props; const { loading } = this.state; return (
); } private renderNotFound(): JSX.Element { return (