import { has } from 'lodash'; import React from 'react'; import { ExecutionUserStatus } from './ExecutionUserStatus'; import type { IExecution } from '../../domain'; import { ExecutionBuildLink } from '../executionBuild/ExecutionBuildLink'; import { buildDisplayName } from '../executionBuild/buildDisplayName.filter'; import type { ISortFilter } from '../../filterModel'; import { HoverablePopover } from '../../presentation'; import { Registry } from '../../registry'; import { SchedulerFactory } from '../../scheduler'; import type { IScheduler } from '../../scheduler/SchedulerFactory'; import { ExecutionState } from '../../state'; import { relativeTime, timestamp } from '../../utils'; import './executionStatus.less'; export interface IExecutionStatusProps { execution: IExecution; showingDetails: boolean; standalone: boolean; } export interface IExecutionStatusState { sortFilter: ISortFilter; timestamp: string; } export class ExecutionStatus extends React.Component { private timestampScheduler: IScheduler; constructor(props: IExecutionStatusProps) { super(props); const { execution } = this.props; this.state = { sortFilter: ExecutionState.filterModel.asFilterModel.sortFilter, timestamp: relativeTime(execution.startTime || execution.buildTime), }; } private validateTimestamp(): void { const newTimestamp = relativeTime(this.props.execution.startTime || this.props.execution.buildTime); if (newTimestamp !== this.state.timestamp) { this.setState({ timestamp: newTimestamp }); } } public componentDidMount(): void { this.timestampScheduler = SchedulerFactory.createScheduler(); this.timestampScheduler.subscribe(() => this.validateTimestamp()); } public componentWillUnmount(): void { this.timestampScheduler.unsubscribe(); } private getExecutionTypeDisplay(): string { const trigger = this.props.execution.trigger; if (trigger.type === 'manual') { return 'Manual Start'; } const config = Registry.pipeline.getTriggerConfig(trigger.type); if (config && config.executionTriggerLabel) { return config.executionTriggerLabel(trigger); } return trigger.type; } private getTriggerExecutionStatus() { const { trigger } = this.props.execution; const triggerConfig = Registry.pipeline.getTriggerConfig(trigger.type); if (triggerConfig) { return triggerConfig.executionStatusComponent; } if (trigger.type === 'manual') { return ExecutionUserStatus; } return null; } public render() { const { execution } = this.props; const { trigger, authentication } = execution; const TriggerExecutionStatus = this.getTriggerExecutionStatus(); return (
{trigger.dryRun && 'DRY RUN: '} {this.getExecutionTypeDisplay()}
); } }