import * as React from 'react'; import { Link } from 'react-router-dom'; import { APPLICATION_RELEASE_DETAILS_PATH, APPLICATION_RELEASE_LIST_PATH, COMPONENT_DETAILS_PATH, PIPELINERUN_DETAILS_PATH, SNAPSHOT_DETAILS_PATH, } from '@routes/paths'; import { StatusIconWithText } from '~/components/StatusIcon/StatusIcon'; import { PipelineRunLabel } from '~/consts/pipelinerun'; import { ReleaseColumnKeys, RELEASE_COLUMN_ORDER } from '~/consts/release'; import { useReleaseStatus } from '~/hooks/useReleaseStatus'; import ActionMenu from '~/shared/components/action-menu/ActionMenu'; import { RowFunctionArgs, TableData } from '~/shared/components/table'; import { Timestamp } from '~/shared/components/timestamp/Timestamp'; import { useNamespace } from '~/shared/providers/Namespace'; import { ReleaseKind } from '~/types'; import { calculateDuration } from '~/utils/pipeline-utils'; import { getNamespaceAndPRName, getTenantCollectorPipelineRunFromRelease, getManagedPipelineRunFromRelease, getTenantPipelineRunFromRelease, getFinalPipelineRunFromRelease, } from '~/utils/release-utils'; import { useReleaseActions } from './release-actions'; import { releasesTableColumnClasses, getDynamicReleaseColumnClasses } from './ReleasesListHeader'; interface ReleasesListRowProps extends RowFunctionArgs { visibleColumns?: Set; } const RELEASE_LIST_LINK_TEXT = 'Back to release list'; const ReleasesListRow: React.FC> = ({ obj, customData: { applicationName }, visibleColumns, }) => { const namespace = useNamespace(); const status = useReleaseStatus(obj); const [managedPrNamespace, managedPipelineRun] = getNamespaceAndPRName( getManagedPipelineRunFromRelease(obj), ); const [tenantPrNamespace, tenantPipelineRun] = getNamespaceAndPRName( getTenantPipelineRunFromRelease(obj), ); const [tenantCollectorPrNamespace, tenantCollectorPipelineRun] = getNamespaceAndPRName( getTenantCollectorPipelineRunFromRelease(obj), ); const [finalPrNamespace, finalPipelineRun] = getNamespaceAndPRName( getFinalPipelineRunFromRelease(obj), ); const actions = useReleaseActions(obj); const backButtonState = namespace !== managedPrNamespace ? { backButtonLink: APPLICATION_RELEASE_LIST_PATH.createPath({ workspaceName: namespace, applicationName, }), backButtonText: RELEASE_LIST_LINK_TEXT, } : {}; const columnOrder: ReleaseColumnKeys[] = RELEASE_COLUMN_ORDER as ReleaseColumnKeys[]; // Use dynamic classes if visibleColumns is provided, otherwise fall back to static classes const columnClasses = visibleColumns ? getDynamicReleaseColumnClasses(visibleColumns) : releasesTableColumnClasses; const columnComponents: Record = { name: ( {obj.metadata.name} ), created: ( ), duration: ( {obj.status?.startTime != null ? calculateDuration( typeof obj.status?.startTime === 'string' ? obj.status?.startTime : '', typeof obj.status?.completionTime === 'string' ? obj.status?.completionTime : '', ) : '-'} ), status: ( ), component: (() => { const componentName = obj.metadata?.labels?.[PipelineRunLabel.COMPONENT]; return ( {componentName ? ( {componentName} ) : ( '-' )} ); })(), releasePlan: ( {obj.spec.releasePlan} ), releaseSnapshot: ( {obj.spec.snapshot} ), tenantCollectorPipelineRun: ( {tenantCollectorPipelineRun && tenantCollectorPrNamespace ? ( {tenantCollectorPipelineRun} ) : ( '-' )} ), tenantPipelineRun: ( {tenantPipelineRun && tenantPrNamespace ? ( {tenantPipelineRun} ) : ( '-' )} ), managedPipelineRun: ( {managedPipelineRun && managedPrNamespace ? ( {managedPipelineRun} ) : ( '-' )} ), finalPipelineRun: ( {finalPipelineRun && finalPrNamespace ? ( {finalPipelineRun} ) : ( '-' )} ), }; return ( <> {visibleColumns ? columnOrder .filter((columnKey) => visibleColumns.has(columnKey)) .map((columnKey) => columnComponents[columnKey]) : Object.values(columnComponents)} ); }; export default ReleasesListRow;