import { Link } from 'react-router-dom';
import { Button, Popover, Skeleton } from '@patternfly/react-core';
import { PipelineRunLabel } from '~/consts/pipelinerun';
import { usePipelineRunsV2 } from '~/hooks/usePipelineRunsV2';
import { PipelineRunKind } from '~/types';
import { getCommitSha } from '~/utils/commits-utils';
import { getPipelineRunDetailsPath } from '~/utils/pipeline-run-routes';
const RelatedNamespacePipelineRuns = ({ pipelineRun }: { pipelineRun: PipelineRunKind }) => {
const labels = pipelineRun.metadata.labels;
const groupName = labels?.[PipelineRunLabel.COMPONENT_GROUP];
const componentName = labels?.[PipelineRunLabel.COMPONENT];
const commit = getCommitSha(pipelineRun);
const enabled = !!commit && !!(groupName || componentName);
const [runs, loaded, error, getNextPage, { hasNextPage, isFetchingNextPage }] = usePipelineRunsV2(
enabled ? pipelineRun.metadata.namespace : null,
{
selector: {
matchLabels: groupName
? { [PipelineRunLabel.COMPONENT_GROUP]: groupName }
: { [PipelineRunLabel.COMPONENT]: componentName },
filterByCommit: commit,
},
},
);
if (!enabled) return <>->;
if (error) return <>Unable to load related pipeline runs>;
if (!loaded) return ;
const relatedRuns = runs.filter((run) => run.metadata.name !== pipelineRun.metadata.name);
return (
{relatedRuns.length === 0 && !hasNextPage && 'No related pipeline runs'}
{relatedRuns.map((run) => (
{run.metadata.name}
))}
{hasNextPage && (
)}
>
}
>
);
};
export default RelatedNamespacePipelineRuns;