import React from 'react'; import { DurationRender, RelativeTimestamp } from '../../RelativeTimestamp'; import { VersionOperationIcon } from './VersionOperation'; import { useRetryVersionActionMutation } from '../../graphql/graphql-sdk'; import { Tooltip, useApplicationContextSafe } from '../../../presentation'; import type { QueryArtifactVersionTask, QueryArtifactVersionTaskStatus } from '../types'; import { TOOLTIP_DELAY_SHOW } from '../../utils/defaults'; import { useLogEvent } from '../../utils/logging'; import { useNotifyOnError } from '../../utils/useNotifyOnError.hook'; import { Spinner } from '../../../widgets'; import './ArtifactVersionTasks.less'; const statusToText: { [key in QueryArtifactVersionTaskStatus]: string; } = { FAIL: 'failed', FORCE_PASS: 'has been overridden', PASS: 'passed', PENDING: 'in progress', NOT_EVALUATED: 'has not started yet', }; export interface ITaskArtifactVersionProps { environment: string; version: string; reference: string; isCurrent?: boolean; } interface IBaseTaskProps { type: string; artifact: ITaskArtifactVersionProps; } interface IArtifactVersionTaskProps extends IBaseTaskProps { task: QueryArtifactVersionTask; } // Example of a task: postDeploy and verification const ArtifactVersionTask = ({ type, artifact, task }: IArtifactVersionTaskProps) => { const status = task.status || 'PENDING'; const { link, startedAt, completedAt } = task; const logEvent = useLogEvent('ArtifactVersionTask'); const app = useApplicationContextSafe(); const [retryTask, { loading: mutationInFlight, error }] = useRetryVersionActionMutation({ variables: { payload: { application: app.name, environment: artifact.environment, reference: artifact.reference, version: artifact.version, actionId: task.actionId, actionType: task.actionType, }, }, }); useNotifyOnError({ key: task.id, content: `Failed to re-run ${type}`, error }); return (
{type} {task.actionId} {statusToText[status]}{' '} {startedAt && completedAt && ( <> () )} {startedAt && ( )} {link && ( View logs )} {status === 'FAIL' && artifact.isCurrent && (
{mutationInFlight && ( )}
)}
); }; interface IArtifactVersionTasksProps extends IBaseTaskProps { tasks?: QueryArtifactVersionTask[]; } // Example of tasks: postDeploys and verifications export const ArtifactVersionTasks = ({ tasks, ...restProps }: IArtifactVersionTasksProps) => { if (!tasks || !tasks.length) return null; return (
{tasks.map((task) => ( ))}
); };