import React from 'react'; import { useParams, Link, useNavigate } from 'react-router-dom'; import { Bullseye, Spinner } from '@patternfly/react-core'; import { useComponents } from '~/hooks/useComponents'; import { useNamespace } from '~/shared/providers/Namespace'; import { getErrorState } from '~/shared/utils/error-utils'; import { useApplication } from '../../hooks/useApplications'; import { ApplicationModel, ComponentModel, IntegrationTestScenarioModel } from '../../models'; import { APPLICATION_DETAILS_PATH, APPLICATION_LIST_PATH, INTEGRATION_TEST_ADD_PATH, IMPORT_PATH, } from '../../routes/paths'; import useTriggerReleaseAction from '../../shared/hooks/useTriggerReleaseAction'; import { TrackEvents, useTrackEvent } from '../../utils/analytics'; import { useAccessReviewForModel } from '../../utils/rbac'; import { useApplicationBreadcrumbs } from '../Applications/breadcrumbs/breadcrumb-utils'; import { useComponentRelationAction } from '../ComponentRelation/useComponentRelationAction'; import { createCustomizeAllPipelinesModalLauncher } from '../CustomizedPipeline/CustomizePipelinesModal'; import DetailsPage from '../DetailsPage/DetailsPage'; import { useModalLauncher } from '../modal/ModalProvider'; import { applicationDeleteModal } from '../modal/resource-modals'; import { ApplicationHeader } from './ApplicationHeader'; import './ApplicationDetails.scss'; export const ApplicationDetails: React.FC = () => { const { applicationName } = useParams(); // const track = useTrackEvent(); const namespace = useNamespace(); const [canCreateComponent] = useAccessReviewForModel(ComponentModel, 'create'); const [canPatchComponent] = useAccessReviewForModel(ComponentModel, 'patch'); const [canCreateIntegrationTest] = useAccessReviewForModel( IntegrationTestScenarioModel, 'create', ); const [canDeleteApplication] = useAccessReviewForModel(ApplicationModel, 'delete'); const defineComponentRelationAction = useComponentRelationAction(applicationName); const navigate = useNavigate(); const showModal = useModalLauncher(); const [components, componentsLoaded, componentsError] = useComponents(namespace, applicationName); const hasComponents = componentsLoaded && components.length > 0 && !componentsError; const [application, applicationLoaded, applicationError] = useApplication( namespace, applicationName, ); const track = useTrackEvent(); const appDisplayName = application?.spec?.displayName || application?.metadata?.name || ''; const applicationBreadcrumbs = useApplicationBreadcrumbs(appDisplayName, false); const { cta: triggerReleaseCta, isDisabled: triggerReleaseIsDisabled, disabledTooltip: triggerReleaseDisableTooltip, key: triggerReleaseKey, label: triggerReleaseLabel, } = useTriggerReleaseAction(); if (!applicationLoaded) { return ( ); } if (applicationError) { return getErrorState(applicationError, applicationLoaded, 'application'); } return ( } baseURL={APPLICATION_DETAILS_PATH.createPath({ workspaceName: namespace, applicationName })} actions={[ { onClick: () => { track(TrackEvents.ButtonClicked, { link_name: 'manage-build-pipelines', link_location: 'application-actions', app_name: applicationName, }); showModal(createCustomizeAllPipelinesModalLauncher(applicationName, namespace)); }, disabledTooltip: !canPatchComponent ? 'You do not have access to manage build pipelines' : 'Add component to manage build pipelines', isDisabled: !canPatchComponent || !hasComponents, key: 'manage-build-pipelines', label: 'Manage build pipelines', }, { key: 'add-component', label: 'Add component', component: ( { track(TrackEvents.ButtonClicked, { link_name: 'add-component', link_location: 'application-details-actions', app_name: applicationName, }); }} > Add component ), isDisabled: !canCreateComponent, disabledTooltip: "You don't have access to add a component", }, { key: 'add-integration-test', label: 'Add integration test', component: ( { track(TrackEvents.ButtonClicked, { link_name: 'add-integration-test', link_location: 'application-details-actions', app_name: applicationName, }); }} > Add integration test ), isDisabled: !canCreateIntegrationTest || !hasComponents, disabledTooltip: !canCreateIntegrationTest ? "You don't have access to add an integration test" : 'Add component to add an integration test', }, defineComponentRelationAction(), { key: triggerReleaseKey, label: triggerReleaseLabel, isDisabled: triggerReleaseIsDisabled || !hasComponents, disabledTooltip: triggerReleaseDisableTooltip ? triggerReleaseDisableTooltip : 'Add component to trigger release', onClick: triggerReleaseCta, }, { type: 'separator', key: 'delete-separator', label: '', }, { key: 'delete-application', label: 'Delete application', onClick: () => showModal<{ submitClicked: boolean }>( applicationDeleteModal(application), ).closed.then(({ submitClicked }) => { if (submitClicked) navigate(APPLICATION_LIST_PATH.createPath({ workspaceName: namespace })); }), isDisabled: !canDeleteApplication, disabledTooltip: "You don't have access to delete this application", }, ]} tabs={[ { key: 'index', label: 'Overview', isFilled: true, }, { key: 'activity', label: 'Activity', isFilled: true, partial: true, className: 'application-details__activity', }, { key: 'components', label: 'Components', isFilled: true, }, { key: 'integrationtests', label: 'Integration tests', }, { key: 'snapshots', label: 'Snapshots', isFilled: true, }, { key: 'releases', label: 'Releases', isFilled: true, }, { key: 'conforma-results', label: 'Conforma Results', isFilled: true, }, { key: 'dep-updates', label: 'Dependency updates', isFilled: true, }, ]} /> ); };