import React from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { Bullseye, Spinner, Content, ContentVariants } from '@patternfly/react-core'; import { useStatusOnFavicon } from '~/hooks/useStatusOnFavicon'; import { ReleaseModel } from '~/models'; import { getErrorState } from '~/shared/utils/error-utils'; import { TrackEvents, useTrackEvent } from '~/utils/analytics'; import { downloadYamlAction } from '~/utils/common-utils'; import { useAccessReviewForModel } from '~/utils/rbac'; import { useAuth } from '../../auth/useAuth'; import { useRelease } from '../../hooks/useReleases'; import { getReleaseStatus } from '../../hooks/useReleaseStatus'; import { APPLICATION_RELEASE_DETAILS_PATH, APPLICATION_RELEASE_LIST_PATH, } from '../../routes/paths'; import { RouterParams } from '../../routes/utils'; import { useNamespace } from '../../shared/providers/Namespace'; import { releaseRerun } from '../../utils/release-actions'; import { useApplicationBreadcrumbs } from '../Applications/breadcrumbs/breadcrumb-utils'; import { DetailsPage } from '../DetailsPage'; import { createDetailsPageAction } from '../DetailsPage/utils'; const ReleaseDetailsView: React.FC = () => { const { applicationName, releaseName } = useParams(); const namespace = useNamespace(); const navigate = useNavigate(); const applicationBreadcrumbs = useApplicationBreadcrumbs(); const [release, loaded, error] = useRelease(namespace, releaseName); const [canCreateRelease] = useAccessReviewForModel(ReleaseModel, 'create'); const track = useTrackEvent(); const { user: { email }, } = useAuth(); const releaseStatus = React.useMemo( () => (loaded && release && !error ? getReleaseStatus(release) : null), [loaded, release, error], ); useStatusOnFavicon(releaseStatus); if (!loaded) { return ( ); } if (error) { return getErrorState(error, loaded, 'release'); } return ( {release.metadata.name} } baseURL={APPLICATION_RELEASE_DETAILS_PATH.createPath({ workspaceName: namespace, applicationName, releaseName, })} actions={[ { onClick: () => { track(TrackEvents.ButtonClicked, { link_name: 're-run-release', link_location: 'release-actions', release_name: releaseName, app_name: applicationName, namespace, }); void releaseRerun(release, email).then(() => { navigate( APPLICATION_RELEASE_LIST_PATH.createPath({ workspaceName: namespace, applicationName, }), ); }); }, disabledTooltip: 'You do not have access to re-run release', isDisabled: !canCreateRelease, key: 're-run-release', label: 'Re-run release', }, createDetailsPageAction(downloadYamlAction(release)), ]} tabs={[ { key: 'index', label: 'Overview', isFilled: true, }, { key: 'pipelineruns', label: 'Pipeline runs', }, { key: 'artifacts', label: 'Release artifacts', isFilled: true, }, { key: 'yaml', label: 'YAML', isFilled: true, }, ]} /> ); }; export default ReleaseDetailsView;