import { Diff2HtmlUI } from "diff2html/lib/ui/js/diff2html-ui-base"; import hljs from "highlight.js/lib/core"; import yaml from "highlight.js/lib/languages/yaml"; import { useEffect, useRef } from "react"; import { diffConfiguration } from "../../../utils"; import Spinner from "../../Spinner"; hljs.registerLanguage("yaml", yaml); interface ManifestDiffProps { diff?: string; isLoading: boolean; error: string; } const ManifestDiff = ({ diff, isLoading, error }: ManifestDiffProps) => { const diffContainerRef = useRef(null); useEffect(() => { if (isLoading) { // we're listening to isLoading to draw new diffs which are not // always rerender, probably because of the use of ref return; } if (diff && diffContainerRef.current) { const diff2htmlUi = new Diff2HtmlUI( diffContainerRef.current, diff, diffConfiguration, hljs ); diff2htmlUi.draw(); diff2htmlUi.highlightCode(); } }, [diff, isLoading]); if (isLoading && !error) { return ( Calculating diff... ); } return ( Manifest changes: {error ? ( Failed to get upgrade info: {error.toString()} ) : diff ? ( ) : ( No changes will happen to the cluster )} ); }; export default ManifestDiff;
Failed to get upgrade info: {error.toString()}
No changes will happen to the cluster