import { Link, useParams } from 'react-router-dom'; import { GROUP_RELEASE_DETAILS_PATH, COMPONENT_DETAILS_V2_PATH } from '@routes/paths'; import { RouterParams } from '@routes/utils'; import { PipelineRunLabel } from '~/consts/pipelinerun'; import { Timestamp } from '~/shared'; import { defineFilters } from '~/shared/components/Filter'; import { ColumnDefinition } from '~/shared/components/TableV2'; import { ReleaseKind } from '~/types'; import { nameSearchFilter } from '~/utils/common-filter-configs'; import { calculateDuration } from '~/utils/pipeline-utils'; import { getFinalPipelineRunFromRelease, getManagedPipelineRunFromRelease, getNamespaceAndPRName, getTenantCollectorPipelineRunFromRelease, getTenantPipelineRunFromRelease, } from '~/utils/release-utils'; import ReleaseStatusCell from './ReleaseStatusCell'; export const RELEASES_LIST_COLUMN_STATE_KEY = 'releases-list'; export const COMPONENT_GROUP_RELEASES_LIST_COLUMN_STATE_KEY = 'component-group-releases-list'; export const RELEASES_LIST_FILTERS = defineFilters()([nameSearchFilter]); const ReleaseNameLink = ({ release }: { release: ReleaseKind }) => { const { groupName } = useParams(); return ( {release.metadata.name} ); }; export const RELEASES_LIST_COLUMNS: ColumnDefinition[] = [ { id: 'name', header: 'Name', nonHidable: true, accessorFn: (obj) => obj.metadata?.name, cell: (info) => { const obj = info.row.original; return ; }, }, { id: 'created', header: 'Created', accessorFn: (obj) => obj.metadata?.creationTimestamp, cell: (info) => { return ; }, }, { id: 'duration', header: 'Duration', accessorFn: (obj) => obj.status?.startTime != null ? calculateDuration( typeof obj.status?.startTime === 'string' ? obj.status?.startTime : '', typeof obj.status?.completionTime === 'string' ? obj.status?.completionTime : '', ) : '-', }, { id: 'status', header: 'Status', accessorFn: () => null, cell: (info) => { const obj = info.row.original; return ; }, }, { id: 'component', header: 'Component', accessorFn: (obj) => obj?.metadata?.labels?.[PipelineRunLabel.COMPONENT], cell: (info) => { const componentName = info.getValue() as string | undefined; if (!componentName) return '-'; return ( {componentName} ); }, }, { id: 'releasePlan', header: 'Release Plan', accessorFn: (obj) => obj.spec.releasePlan ?? '-', }, { id: 'releaseSnapshot', header: 'Release Snapshot', accessorFn: (obj) => obj.spec.snapshot, // TODO[KFLUXUI-1720] cell: (info) => info.getValue() as string, }, { id: 'tenantCollectorPipelineRun', header: 'Tenant Collector', accessorFn: (obj) => { const [tenantCollectorPrNamespace, tenantCollectorPipelineRun] = getNamespaceAndPRName( getTenantCollectorPipelineRunFromRelease(obj), ); if (!tenantCollectorPrNamespace || !tenantCollectorPipelineRun) return '-'; return tenantCollectorPipelineRun; }, // TODO[KFLUXUI-1721] cell: (info) => info.getValue() as string, }, { id: 'tenantPipelineRun', header: 'Tenant Pipeline', accessorFn: (obj) => { const [tenantPrNamespace, tenantPipelineRun] = getNamespaceAndPRName( getTenantPipelineRunFromRelease(obj), ); if (!tenantPrNamespace || !tenantPipelineRun) return '-'; return tenantPipelineRun; }, // TODO[KFLUXUI-1721] cell: (info) => info.getValue() as string, }, { id: 'managedPipelineRun', header: 'Managed Pipeline', accessorFn: (obj) => { const [managedPrNamespace, managedPipelineRun] = getNamespaceAndPRName( getManagedPipelineRunFromRelease(obj), ); if (!managedPrNamespace || !managedPipelineRun) return '-'; return managedPipelineRun; }, // TODO[KFLUXUI-1721] cell: (info) => info.getValue() as string, }, { id: 'finalPipelineRun', header: 'Final Pipeline', accessorFn: (obj) => { const [finalPrNamespace, finalPipelineRun] = getNamespaceAndPRName( getFinalPipelineRunFromRelease(obj), ); if (!finalPrNamespace || !finalPipelineRun) return '-'; return finalPipelineRun; }, // TODO[KFLUXUI-1721] cell: (info) => info.getValue() as string, }, ];