import * as React from 'react'; import { Alert, AlertVariant, Button, ButtonVariant, pluralize, Content, ContentVariants, Modal, ModalBody, ModalFooter, ModalHeader, Truncate, } from '@patternfly/react-core'; import { Tbody, Thead, Th, Tr, Td, Table } from '@patternfly/react-table'; import SendIconUrl from '../../assets/send.svg'; import SuccessIconUrl from '../../assets/success.svg'; import { LEARN_MORE_GITLAB_OR_FORGEJO_URL } from '../../consts/documentation'; import { useKonfluxPublicInfo } from '../../hooks/useKonfluxPublicInfo'; import { PACState } from '../../hooks/usePACState'; import { ComponentModel } from '../../models'; import ExternalLink from '../../shared/components/links/ExternalLink'; import { useNamespace } from '../../shared/providers/Namespace'; import { ComponentKind } from '../../types'; import { useTrackEvent, TrackEvents } from '../../utils/analytics'; import { enablePAC, useComponentBuildStatus, getLastestImage } from '../../utils/component-utils'; import { useAccessReviewForModel } from '../../utils/rbac'; import AnalyticsButton from '../AnalyticsButton/AnalyticsButton'; import { ButtonWithAccessTooltip } from '../ButtonWithAccessTooltip'; import GitRepoLink from '../GitLink/GitRepoLink'; import { RawComponentProps } from '../modal/createModalLauncher'; import ComponentPACStateLabel from './ComponentPACStateLabel'; type Props = RawComponentProps & { components: ComponentKind[]; }; const Row: React.FC< React.PropsWithChildren<{ component: ComponentKind; onStateChange: (state: PACState) => void; }> > = ({ component, onStateChange }) => { const namespace = useNamespace(); const track = useTrackEvent(); const [konfluxInfo] = useKonfluxPublicInfo(); const applicationUrl = konfluxInfo?.integrations?.github?.application_url || ''; const [pacState, setPacState] = React.useState(PACState.loading); const onComponentStateChange = React.useCallback( (state: PACState) => { setPacState(state); onStateChange(state); }, [onStateChange], ); const [canPatchComponent] = useAccessReviewForModel(ComponentModel, 'patch'); const buildStatus = useComponentBuildStatus(component); const pacError = buildStatus?.pac?.['error-message']; const prURL = buildStatus?.pac?.['merge-url']; const latestImage = getLastestImage(component); React.useEffect(() => { onStateChange(pacState); // omit onStateChange because we only want to notify when state changes // eslint-disable-next-line react-hooks/exhaustive-deps }, [pacState]); return ( <>
{component.metadata.name}
{component.spec.source?.git && (
Code repository:{' '}
)} {latestImage && (
Image:{' '} } />
)} {(() => { switch (pacState) { case PACState.disabled: case PACState.error: return ( { void enablePAC(component).then(() => { track('Enable PAC', { component_name: component.metadata.name, app_name: component.spec.application, namespace, }); }); }} isDisabled={!canPatchComponent} tooltip="You don't have access to send a pull request" analytics={{ link_name: 'send-pull-request', link_location: 'manage-builds-pipelines', component_name: component.metadata.name, app_name: component.spec.application, namespace, }} > Send pull request ); case PACState.configureRequested: case PACState.unconfigureRequested: return ( ); case PACState.pending: return ( Merge in Git ); case PACState.ready: return ( Edit pipeline in Git ); case PACState.sample: return ( Fork sample ); default: return null; } })()} {pacState === PACState.sample ? ( To upgrade to a custom build pipeline, fork your sample and create a new component first. Then we'll send a pull request to your repository containing the default build pipeline for you to customize. ) : null} {pacState === PACState.error ? ( {applicationUrl ? ( Install GitHub Application ) : null} } > {pacError} ) : null} ); }; const CustomizePipeline: React.FC> = ({ components, onClose, modalProps, }) => { const track = useTrackEvent(); const namespace = useNamespace(); const [konfluxInfo] = useKonfluxPublicInfo(); const applicationUrl = konfluxInfo?.integrations?.github?.application_url || ''; const sortedComponents = React.useMemo( () => [...components].sort((a, b) => a.metadata.name.localeCompare(b.metadata.name)), [components], ); const [componentState, setComponentState] = React.useState<{ [name: string]: PACState }>({}); const completed = React.useMemo( () => Object.values(componentState).every( (state) => state === PACState.ready || state === PACState.sample, ), [componentState], ); const allLoading = React.useMemo( () => !Object.values(componentState).some((state) => state !== PACState.loading), [componentState], ); const count = React.useMemo( () => Object.values(componentState).filter((state) => state === PACState.ready).length, [componentState], ); const totalCount = React.useMemo( () => Object.values(componentState).filter((state) => state !== PACState.sample).length, [componentState], ); const applicationName = components[0].spec.application; const trackedOnClose = React.useCallback(() => { track(TrackEvents.ButtonClicked, { link_name: 'manage-build-pipelines-close', app_name: applicationName, namespace, }); onClose(); }, [onClose, applicationName, namespace, track]); const { isOpen, appendTo, ...rest } = modalProps || {}; return ( <> {completed ? ( ) : ( )} {'Manage build pipeline'} Konflux build pipelines are Pipelines as Code that are committed to your component's repository. To automatically build on future changes, merge the initial pull request sent to your connected repository. You must provide permission to your repository in the Konflux Git application. If you're using GitLab or Forgejo, you must grant permission by uploading a repository access token. {applicationUrl ? ( Learn more about the Git application ) : null} Learn more about GitLab or Forgejo repository access token
{alert} {sortedComponents.map((component) => ( setComponentState((prevState) => ({ ...prevState, [component.metadata.name]: pacState, })) } /> ))}
Component Build pipeline status
{totalCount > 0 ? (

{`${count} of ${pluralize(totalCount, 'component')} upgraded to custom build`}

) : undefined} Close ); }; export default CustomizePipeline;