import { useCurrentStateAndParams, useSref } from '@uirouter/react';
import type { MouseEventHandler } from 'react';
import React from 'react';
import type { IExecution } from '../../../domain';
import { ExecutionInformationService } from './executionInformation.service';
import { logger } from '../../../utils';
export interface IExecutionBreadcrumbsProps {
execution: IExecution;
}
export const ExecutionBreadcrumbs = ({ execution }: IExecutionBreadcrumbsProps) => {
const parentExecutions = React.useMemo(() => {
return new ExecutionInformationService()
.getAllParentExecutions(execution)
.filter((x) => x !== execution)
.reverse();
}, [execution]);
const label = parentExecutions.length === 1 ? 'Parent Execution' : 'Parent Executions';
return (
{label}:
{parentExecutions.map((execution, index, array) => (
{index !== array.length - 1 && }
))}
);
};
function ExecutionPermaLink({ execution }: IExecutionBreadcrumbsProps) {
const { application, id: executionId } = execution;
const { state } = useCurrentStateAndParams();
const isProject = state.name.includes('.project.');
const executionDetails = `home.${isProject ? 'project.' : 'applications.'}application.pipelines.executionDetails`;
const toState = executionDetails + '.execution';
const srefParams = { application, executionId };
const srefOptions = { reload: executionDetails };
const sref = useSref(toState, srefParams, srefOptions);
const handleClick: MouseEventHandler = (e) => {
logger.log({ category: 'Pipeline', action: 'Execution build number clicked - parent pipeline' });
sref.onClick(e);
};
return (
{execution.name}
);
}