From 420a61a5a6b11dcb5eb0a652ea9cecea5c3bee5f Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 25 Jul 2022 15:01:04 +0500 Subject: [PATCH] feat(web): add difference view editor in studio --- web/src/containers/Studio/editor.tsx | 111 ++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 18 deletions(-) diff --git a/web/src/containers/Studio/editor.tsx b/web/src/containers/Studio/editor.tsx index f84495b..f206f69 100644 --- a/web/src/containers/Studio/editor.tsx +++ b/web/src/containers/Studio/editor.tsx @@ -18,8 +18,19 @@ import { } from '@mui/material' import { styled } from '@mui/material/styles' -import { RocketLaunch, MoreVert, Save, SaveAs } from '@mui/icons-material' -import Editor, { EditorDidMount } from 'react-monaco-editor' +import { + RocketLaunch, + MoreVert, + Save, + SaveAs, + Difference, + Edit +} from '@mui/icons-material' +import Editor, { + MonacoDiffEditor, + DiffEditorDidMount, + EditorDidMount +} from 'react-monaco-editor' import { TabContext, TabList, TabPanel } from '@mui/lab' import { AppContext, RunTimeType } from '../../context/appContext' @@ -71,14 +82,22 @@ const SASjsEditor = ({ const [selectedRunTime, setSelectedRunTime] = useState('') const [selectedFileExtension, setSelectedFileExtension] = useState('') const [openFilePathInputModal, setOpenFilePathInputModal] = useState(false) + const [showDiff, setShowDiff] = useState(false) const editorRef = useRef(null as any) + const diffEditorRef = useRef(null as any) + const handleEditorDidMount: EditorDidMount = (editor) => { editor.focus() editorRef.current = editor } + const handleDiffEditorDidMount: DiffEditorDidMount = (diffEditor) => { + diffEditor.focus() + diffEditorRef.current = diffEditor + } + useEffect(() => { setRunTimes(Object.values(appContext.runTimes)) }, [appContext.runTimes]) @@ -226,6 +245,8 @@ const SASjsEditor = ({ - setFileContent(val)} - /> + {showDiff ? ( + setFileContent(val)} + /> + ) : ( + setFileContent(val)} + /> + )} ) : ( @@ -286,6 +319,8 @@ const SASjsEditor = ({ handleRunBtnClick={handleRunBtnClick} /> - setFileContent(val)} - /> + {showDiff ? ( + setFileContent(val)} + /> + ) : ( + setFileContent(val)} + /> + )}

> prevFileContent: string currentFileContent: string selectedFilePath: string @@ -441,6 +490,8 @@ type FileMenuProps = { } const FileMenu = ({ + showDiff, + setShowDiff, prevFileContent, currentFileContent, selectedFilePath, @@ -490,6 +541,16 @@ const FileMenu = ({ open={!!anchorEl} onClose={() => handleMenu()} > + + +