diff --git a/client/src/app/shared/components/simple-task-viewer/simple-document-viewer.tsx b/client/src/app/shared/components/simple-task-viewer/simple-document-viewer.tsx index 326c0318d5..5cefa983fd 100644 --- a/client/src/app/shared/components/simple-task-viewer/simple-document-viewer.tsx +++ b/client/src/app/shared/components/simple-task-viewer/simple-document-viewer.tsx @@ -1,5 +1,9 @@ import * as React from "react"; -import { CodeEditor, Language } from "@patternfly/react-code-editor"; +import { + CodeEditor, + CodeEditorControl, + Language, +} from "@patternfly/react-code-editor"; import { Button, EmptyState, @@ -15,6 +19,7 @@ import { import { css } from "@patternfly/react-styles"; import editorStyles from "@patternfly/react-styles/css/components/CodeEditor/code-editor"; import CodeIcon from "@patternfly/react-icons/dist/esm/icons/code-icon"; +import UndoIcon from "@patternfly/react-icons/dist/esm/icons/undo-icon"; import "./viewer.css"; @@ -75,27 +80,40 @@ export const SimpleDocumentViewer = ({ React.useEffect(() => { setCode(undefined); - if (documentId) { - if (currentLanguage === Language.yaml) { - fetch(documentId, currentLanguage).then((yaml) => { - setCode(yaml.toString()); - focusAndHomePosition(); - }); - } else { - fetch(documentId, currentLanguage).then((json) => { - setCode(JSON.stringify(json, undefined, 2)); - focusAndHomePosition(); - }); - } - } + documentId && fetchDocument(documentId); }, [documentId, currentLanguage]); + const fetchDocument = (documentId: number) => { + if (currentLanguage === Language.yaml) { + fetch(documentId, currentLanguage).then((yaml) => { + setCode(yaml.toString()); + focusAndHomePosition(); + }); + } else { + fetch(documentId, currentLanguage).then((json) => { + setCode(JSON.stringify(json, undefined, 2)); + focusAndHomePosition(); + }); + } + }; + const focusAndHomePosition = () => { if (editorRef.current) { editorRef.current.focus(); editorRef.current.setPosition({ column: 0, lineNumber: 1 }); } }; + const refreshControl = ( + } + aria-label="refresh-task" + tooltipProps={{ content: "Refresh" }} + onClick={() => { + documentId && fetchDocument(documentId); + }} + isVisible={code !== ""} + /> + ); return ( ({ } customControls={[ -
- + {refreshControl} +
- - - - - JSON - - } - buttonId="code-language-select-json" - isSelected={currentLanguage === "json"} - isDisabled={!code && currentLanguage !== "json"} - onChange={() => setCurrentLanguage(Language.json)} - /> - - - - - YAML - - } - buttonId="code-language-select-yaml" - isSelected={currentLanguage === "yaml"} - isDisabled={!code && currentLanguage !== "yaml"} - onChange={() => setCurrentLanguage(Language.yaml)} - /> - -
, + + + + + + JSON + + } + buttonId="code-language-select-json" + isSelected={currentLanguage === "json"} + isDisabled={!code && currentLanguage !== "json"} + onChange={() => setCurrentLanguage(Language.json)} + /> + + + + + YAML + + } + buttonId="code-language-select-yaml" + isSelected={currentLanguage === "yaml"} + isDisabled={!code && currentLanguage !== "yaml"} + onChange={() => setCurrentLanguage(Language.yaml)} + /> + +
+ , ]} /> );