import React from 'react'; import { Link } from 'react-router-dom'; import { Skeleton, Tooltip } from '@patternfly/react-core'; import { ClipboardCheckIcon } from '@patternfly/react-icons/dist/esm/icons/clipboard-check-icon'; import { ExclamationTriangleIcon } from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'; import { StatusIconWithText } from '~/components/StatusIcon/StatusIcon'; import { TriggerColumnData } from '~/components/trigger-column-data/trigger-column-data'; import { PipelineRunColumnKeys } from '~/consts/pipeline'; import { PipelineRunLabel, PipelineRunType, runStatus, UNFINISHED_PLR_STATUSES, } from '~/consts/pipelinerun'; import { useIsOnFeatureFlag } from '~/feature-flags/hooks'; import { useKarchScanResults } from '~/hooks/useScanResults'; import { PIPELINE_RUNS_DETAILS_PATH, COMPONENT_DETAILS_PATH, SNAPSHOT_DETAILS_PATH, } from '~/routes/paths'; import ActionMenu from '~/shared/components/action-menu/ActionMenu'; import { Duration } from '~/shared/components/duration'; import { RowFunctionArgs, TableData } from '~/shared/components/table'; import { Timestamp } from '~/shared/components/timestamp/Timestamp'; import { useNamespace } from '~/shared/providers/Namespace'; import { PipelineRunKind, TaskRunKind } from '~/types'; import { ReleaseKind, ReleasePlanKind } from '~/types/coreBuildService'; import { createCommitObjectFromPLR } from '~/utils/commits-utils'; import { getEventTypeLabel } from '~/utils/pipeline-run-filter-utils'; import { pipelineRunStatus } from '~/utils/pipeline-utils'; import { ScanResults } from '~/utils/scan/scan-utils'; import { usePipelinerunActionsLazy } from './pipelinerun-actions'; import { pipelineRunTableColumnClasses, getDynamicColumnClasses } from './PipelineRunListHeader'; import { PipelineRunTestResultCell } from './PipelineRunTestResultCell'; import { ScanStatus } from './ScanStatus'; type PipelineRunListRowProps = RowFunctionArgs< PipelineRunKind, { vulnerabilities: { [key: string]: [ScanResults, TaskRunKind[]] }; fetchedPipelineRuns: string[]; error?: unknown; releasePlan?: ReleasePlanKind; release?: ReleaseKind; releaseName?: string; integrationTestName?: string; } >; type BasePipelineRunListRowProps = PipelineRunListRowProps & { showVulnerabilities?: boolean; showWorkspace?: boolean; showTestResult?: boolean; showSnapshot?: boolean; showComponent?: boolean; showReference?: boolean; showTrigger?: boolean; }; const usePipelineRunScanResults = ( pipelineRun: PipelineRunKind, shouldShowScanResults: boolean, customData?: PipelineRunListRowProps['customData'], ) => { const pipelineRunName = pipelineRun.metadata.name; const kubearchiveEnabled = useIsOnFeatureFlag('taskruns-kubearchive'); const [scanResultsKubearchive, scanLoadedKubearchive, scanErrorKubearchive] = useKarchScanResults( shouldShowScanResults && kubearchiveEnabled ? pipelineRunName : '', ); const scanResultsTekton = React.useMemo( () => customData?.vulnerabilities?.[pipelineRunName]?.[0], [customData?.vulnerabilities, pipelineRunName], ); const scanLoadedTekton = React.useMemo( () => (customData?.fetchedPipelineRuns || []).includes(pipelineRunName), [customData?.fetchedPipelineRuns, pipelineRunName], ); return React.useMemo(() => { if (!shouldShowScanResults) { return { scanResults: undefined, scanLoaded: true, scanError: undefined }; } const scanResults = kubearchiveEnabled ? scanLoadedKubearchive ? scanResultsKubearchive || undefined : undefined : scanLoadedTekton ? scanResultsTekton || undefined : undefined; const scanLoaded = kubearchiveEnabled ? scanLoadedKubearchive : scanLoadedTekton; const scanError = kubearchiveEnabled ? scanErrorKubearchive : customData?.error; return { scanResults, scanLoaded, scanError }; }, [ shouldShowScanResults, kubearchiveEnabled, scanLoadedKubearchive, scanResultsKubearchive, scanErrorKubearchive, scanLoadedTekton, scanResultsTekton, customData?.error, ]); }; const shouldShowScanResults = (pipelineRun: PipelineRunKind): boolean => { return ( pipelineRun.metadata.labels?.[PipelineRunLabel.PIPELINE_TYPE] === PipelineRunType.BUILD && !UNFINISHED_PLR_STATUSES.includes(pipelineRunStatus(pipelineRun)) && pipelineRun.status?.completionTime !== undefined ); }; const PipelineRunAttestation = ({ pipelineRun }: { pipelineRun: PipelineRunKind }) => { const hasAttestation = pipelineRun.metadata?.annotations?.[PipelineRunLabel.CHAINS_SIGNED_ANNOTATION] === 'true'; const AttestationIcon = hasAttestation ? ClipboardCheckIcon : ExclamationTriangleIcon; return ( ); }; const BasePipelineRunListRow: React.FC> = ({ obj, showVulnerabilities, showWorkspace, showTestResult, showSnapshot, showComponent, showTrigger, showReference, customData, }) => { const namespace = useNamespace(); const capitalize = (label: string) => { return label && label.charAt(0).toUpperCase() + label.slice(1); }; const { releaseName, integrationTestName, releasePlan, release } = customData || {}; const shouldShowScan = shouldShowScanResults(obj); const { scanResults, scanLoaded, scanError } = usePipelineRunScanResults( obj, shouldShowScan, customData, ); const status = pipelineRunStatus(obj); const isFinished = !UNFINISHED_PLR_STATUSES.includes(status); const [actions, onOpen] = usePipelinerunActionsLazy(obj); if (!obj.metadata?.labels) { obj.metadata.labels = {}; } const labels = obj.metadata.labels; const applicationName = labels?.[PipelineRunLabel.APPLICATION]; const commit = createCommitObjectFromPLR(obj); const queryString = releaseName ? `?releaseName=${encodeURIComponent(releaseName)}` : integrationTestName ? `?integrationTestName=${encodeURIComponent(integrationTestName)}` : ''; return ( <> {isFinished && } {obj.metadata?.name} {showVulnerabilities ? ( {scanError ? ( <>N/A ) : !shouldShowScan || (scanLoaded && !scanResults) ? ( '-' ) : scanLoaded ? ( ) : ( )} ) : null} {status !== runStatus.Pending ? ( ) : ( '-' )} {showTestResult ? ( ) : null} {capitalize(obj.metadata?.labels[PipelineRunLabel.PIPELINE_TYPE])} {showSnapshot ? ( {release.spec.snapshot} ) : showSnapshot ? ( - ) : null} {showWorkspace ? ( {namespace} ) : null} {showComponent ? ( {obj.metadata?.labels[PipelineRunLabel.COMPONENT] ? ( obj.metadata?.labels[PipelineRunLabel.APPLICATION] ? ( {obj.metadata?.labels[PipelineRunLabel.COMPONENT]} ) : ( obj.metadata?.labels[PipelineRunLabel.COMPONENT] ) ) : ( '-' )} ) : null} {showTrigger ? ( {getEventTypeLabel(commit?.eventType, commit?.gitProvider)} ) : null} {showReference ? ( ) : null} ); }; export const PipelineRunListRow: React.FC> = ( props, ) => ; export const PipelineRunListRowWithVulnerabilities: React.FC< React.PropsWithChildren > = (props) => ; export const PipelineRunListRowForRelease: React.FC< React.PropsWithChildren > = (props) => ( ); type PipelineRunListRowWithColumnsProps = PipelineRunListRowProps & { visibleColumns: Set; }; // Enhanced row component that uses dynamic column classes const DynamicPipelineRunListRow: React.FC< React.PropsWithChildren > = ({ obj, customData, visibleColumns }) => { const namespace = useNamespace(); const dynamicClasses = getDynamicColumnClasses(visibleColumns); const capitalize = (label: string) => { return label && label.charAt(0).toUpperCase() + label.slice(1); }; const { releaseName, integrationTestName, releasePlan, release } = customData || {}; const shouldShowScan = shouldShowScanResults(obj); const { scanResults, scanLoaded, scanError } = usePipelineRunScanResults( obj, shouldShowScan, customData, ); const status = pipelineRunStatus(obj); const isFinished = !UNFINISHED_PLR_STATUSES.includes(status); const [actions, onOpen] = usePipelinerunActionsLazy(obj); if (!obj.metadata?.labels) { obj.metadata.labels = {}; } const labels = obj.metadata.labels; const applicationName = labels?.[PipelineRunLabel.APPLICATION]; const commit = createCommitObjectFromPLR(obj); const queryString = releaseName ? `?releaseName=${encodeURIComponent(releaseName)}` : integrationTestName ? `?integrationTestName=${encodeURIComponent(integrationTestName)}` : ''; return ( <> {visibleColumns.has('name') && ( {isFinished && } {obj.metadata?.name} )} {visibleColumns.has('started') && ( )} {visibleColumns.has('vulnerabilities') && ( {scanError ? ( <>N/A ) : !shouldShowScan || (scanLoaded && !scanResults) ? ( '-' ) : scanLoaded ? ( ) : ( )} )} {visibleColumns.has('duration') && ( {status !== runStatus.Pending ? ( ) : ( '-' )} )} {visibleColumns.has('status') && ( )} {visibleColumns.has('testResult') && ( )} {visibleColumns.has('type') && ( {capitalize(obj.metadata?.labels[PipelineRunLabel.PIPELINE_TYPE])} )} {visibleColumns.has('snapshot') && ( {release.spec.snapshot} )} {visibleColumns.has('snapshot') && (!release?.spec?.snapshot || !releasePlan?.spec?.application) && ( - )} {visibleColumns.has('namespace') && ( {namespace} )} {visibleColumns.has('component') && ( {obj.metadata?.labels[PipelineRunLabel.COMPONENT] ? ( obj.metadata?.labels[PipelineRunLabel.APPLICATION] ? ( {obj.metadata?.labels[PipelineRunLabel.COMPONENT]} ) : ( obj.metadata?.labels[PipelineRunLabel.COMPONENT] ) ) : ( '-' )} )} {visibleColumns.has('trigger') && ( {getEventTypeLabel(commit?.eventType, commit?.gitProvider)} )} {visibleColumns.has('reference') && ( )} ); }; // New row component that works with visible columns - now uses dynamic classes export const PipelineRunListRowWithColumns: React.FC< React.PropsWithChildren > = (props) => ;