import * as React from 'react'; import { Link } from 'react-router-dom'; import { DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm, ModalVariant, } from '@patternfly/react-core'; import dayjs from 'dayjs'; import { PIPELINERUN_DETAILS_PATH } from '@routes/paths'; import { ComponentProps, createModalLauncher } from '~/components/modal/createModalLauncher'; import { useModalLauncher } from '~/components/modal/ModalProvider'; import { StatusIconWithTextLabel } from '~/components/topology/StatusIcon'; import { FeatureFlagIndicator } from '~/feature-flags/FeatureFlagIndicator'; import { useLatestBuildPipelineRunForComponentV2 } from '~/hooks/useLatestPushBuildPipeline'; import { useTaskRunsForPipelineRuns } from '~/hooks/useTaskRunsV2'; import PipelineRunLogs from '~/shared/components/pipeline-run-logs/PipelineRunLogs'; import { EmptyBox, LoadingBox } from '~/shared/components/status-box/StatusBox'; import { useNamespace } from '~/shared/providers/Namespace'; import { getErrorState } from '~/shared/utils/error-utils'; import { ComponentKind } from '~/types'; import { pipelineRunStatus } from '~/utils/pipeline-utils'; import './BuildLogViewer.scss'; type BuildLogViewerProps = ComponentProps & { component: ComponentKind; }; export const BuildLogViewer: React.FC> = ({ component, }) => { const namespace = useNamespace(); const [pipelineRun, loaded, pipelineRunError] = useLatestBuildPipelineRunForComponentV2( component.metadata.namespace, component.metadata.name, ); const [taskRuns, taskRunsLoaded, taskRunsError] = useTaskRunsForPipelineRuns( pipelineRun?.metadata?.namespace, pipelineRun?.metadata?.name, ); const plrStatus = React.useMemo( () => loaded && pipelineRun && pipelineRunStatus(pipelineRun), [loaded, pipelineRun], ); if (!loaded) { return ; } if (pipelineRunError) { return getErrorState(pipelineRunError, loaded, 'pipeline run'); } if (!pipelineRun) { return ; } return ( <>
{`Build pipeline run log for ${component.metadata.name}`}
Component {component.metadata.name} Build pipeline run {pipelineRun && loaded && ( {pipelineRun.metadata?.name} )} Build start date {pipelineRun && loaded && dayjs(new Date(pipelineRun.metadata.creationTimestamp)).format( 'MMMM DD, YYYY, h:mm A', )}
{!(pipelineRun && taskRunsLoaded) ? ( ) : taskRunsError ? ( getErrorState(taskRunsError, taskRunsLoaded, 'task runs') ) : ( )}
); }; export const buildLogViewerLauncher = createModalLauncher(BuildLogViewer, { className: 'build-log-viewer', 'data-test': 'view-build-logs-modal', variant: ModalVariant.large, }); export const useBuildLogViewerModal = (component: ComponentKind) => { const showModal = useModalLauncher(); return React.useCallback( () => showModal(buildLogViewerLauncher({ component })), [component, showModal], ); };