import * as React from 'react'; import { Link, useParams } from 'react-router-dom'; import { APPLICATION_RELEASE_LIST_PATH, PIPELINE_RUNS_DETAILS_PATH, SNAPSHOT_DETAILS_PATH, } from '@routes/paths'; import { TableData, Timestamp } from '~/shared'; import { ReleasePlanKind } from '~/types/coreBuildService'; import { calculateDuration } from '~/utils/pipeline-utils'; import { getDynamicReleasePipelineColumnClasses } from './ReleasePipelineListHeader'; // Type defined in ReleasePipelineRunTab.tsx to avoid duplication type ReleasePipelineRunColumnKeys = | 'name' | 'startTime' | 'duration' | 'type' | 'snapshot' | 'namespace' | 'status' | 'completionTime'; interface PipelineRunProcessing { type: string; startTime: string | null; completionTime: string; snapshot: string; pipelineRun: string; prNamespace: string; } type PipelineRunListRowProps = { obj: PipelineRunProcessing; releasePlan: ReleasePlanKind; releaseName?: string; namespace: string; visibleColumns: Set; }; const RELEASE_DETAILS_LINK_TEXT = 'Back to release details'; const PipelineRunListRow: React.FC = ({ obj: run, releasePlan, releaseName, namespace, visibleColumns, }) => { const { applicationName } = useParams(); const showBackButton = namespace !== run?.prNamespace; const backButtonState = showBackButton ? { backButtonLink: APPLICATION_RELEASE_LIST_PATH.createPath({ workspaceName: namespace, applicationName, }), backButtonText: RELEASE_DETAILS_LINK_TEXT, } : {}; // Use dynamic classes based on visible columns const columnClasses = getDynamicReleasePipelineColumnClasses(visibleColumns); const columnComponents = { name: ( {run.pipelineRun} ), startTime: ( ), duration: ( {run.startTime ? calculateDuration(run.startTime, run.completionTime) : '-'} ), type: ( {run.type} ), snapshot: ( {run.snapshot} ), namespace: ( {run.prNamespace} ), status: ( {run.completionTime ? 'Completed' : run.startTime ? 'Running' : 'Pending'} ), completionTime: ( ), }; // Define the order of columns to maintain consistent ordering const columnOrder: ReleasePipelineRunColumnKeys[] = [ 'name', 'startTime', 'duration', 'type', 'snapshot', 'namespace', 'status', 'completionTime', ]; return ( <> {columnOrder .filter((columnKey) => visibleColumns.has(columnKey)) .map((columnKey) => columnComponents[columnKey])} ); }; export default PipelineRunListRow;