import React from 'react'; import { Modal } from 'react-bootstrap'; import { ArtifactService } from '../pipeline/config/triggers/artifacts/ArtifactService'; import { decodeUnicodeBase64 } from '../utils'; type IManifestYamlProps = { linkName: string; modalTitle: string; } & ({ manifestText: string; manifestUri?: never } | { manifestText?: never; manifestUri: string }); export function ManifestYaml({ linkName, modalTitle, manifestText, manifestUri }: IManifestYamlProps) { const [modalVisible, setModalVisible] = React.useState(false); const toggle = () => setModalVisible(!modalVisible); const [fetchedManifestText, setFetchedManifestText] = React.useState('Loading...'); const [error, setError] = React.useState(null); React.useEffect(() => { if (manifestUri) { ArtifactService.getArtifactByContentReference(manifestUri) .then((manifest) => setFetchedManifestText(decodeUnicodeBase64(manifest.reference))) .catch((e) => setError(`Error: ${typeof e !== 'string' ? e.data?.message ?? JSON.stringify(e) : e}`)); } }, []); return ( <> {linkName}

{modalTitle}

{error ? (

{error}

) : null}