mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
feat(web): add difference view editor in studio
This commit is contained in:
@@ -18,8 +18,19 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { styled } from '@mui/material/styles'
|
import { styled } from '@mui/material/styles'
|
||||||
|
|
||||||
import { RocketLaunch, MoreVert, Save, SaveAs } from '@mui/icons-material'
|
import {
|
||||||
import Editor, { EditorDidMount } from 'react-monaco-editor'
|
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 { TabContext, TabList, TabPanel } from '@mui/lab'
|
||||||
|
|
||||||
import { AppContext, RunTimeType } from '../../context/appContext'
|
import { AppContext, RunTimeType } from '../../context/appContext'
|
||||||
@@ -71,14 +82,22 @@ const SASjsEditor = ({
|
|||||||
const [selectedRunTime, setSelectedRunTime] = useState('')
|
const [selectedRunTime, setSelectedRunTime] = useState('')
|
||||||
const [selectedFileExtension, setSelectedFileExtension] = useState('')
|
const [selectedFileExtension, setSelectedFileExtension] = useState('')
|
||||||
const [openFilePathInputModal, setOpenFilePathInputModal] = useState(false)
|
const [openFilePathInputModal, setOpenFilePathInputModal] = useState(false)
|
||||||
|
const [showDiff, setShowDiff] = useState(false)
|
||||||
|
|
||||||
const editorRef = useRef(null as any)
|
const editorRef = useRef(null as any)
|
||||||
|
|
||||||
|
const diffEditorRef = useRef(null as any)
|
||||||
|
|
||||||
const handleEditorDidMount: EditorDidMount = (editor) => {
|
const handleEditorDidMount: EditorDidMount = (editor) => {
|
||||||
editor.focus()
|
editor.focus()
|
||||||
editorRef.current = editor
|
editorRef.current = editor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDiffEditorDidMount: DiffEditorDidMount = (diffEditor) => {
|
||||||
|
diffEditor.focus()
|
||||||
|
diffEditorRef.current = diffEditor
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRunTimes(Object.values(appContext.runTimes))
|
setRunTimes(Object.values(appContext.runTimes))
|
||||||
}, [appContext.runTimes])
|
}, [appContext.runTimes])
|
||||||
@@ -226,6 +245,8 @@ const SASjsEditor = ({
|
|||||||
<Box sx={{ marginTop: '10px' }}>
|
<Box sx={{ marginTop: '10px' }}>
|
||||||
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
|
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
|
||||||
<FileMenu
|
<FileMenu
|
||||||
|
showDiff={showDiff}
|
||||||
|
setShowDiff={setShowDiff}
|
||||||
prevFileContent={prevFileContent}
|
prevFileContent={prevFileContent}
|
||||||
currentFileContent={fileContent}
|
currentFileContent={fileContent}
|
||||||
selectedFilePath={selectedFilePath}
|
selectedFilePath={selectedFilePath}
|
||||||
@@ -243,14 +264,26 @@ const SASjsEditor = ({
|
|||||||
}}
|
}}
|
||||||
elevation={3}
|
elevation={3}
|
||||||
>
|
>
|
||||||
<Editor
|
{showDiff ? (
|
||||||
height="98%"
|
<MonacoDiffEditor
|
||||||
language="sas"
|
height="98%"
|
||||||
value={fileContent}
|
language={getLanguage(selectedFileExtension)}
|
||||||
editorDidMount={handleEditorDidMount}
|
original={prevFileContent}
|
||||||
options={{ readOnly: ctrlPressed }}
|
value={fileContent}
|
||||||
onChange={(val) => setFileContent(val)}
|
editorDidMount={handleDiffEditorDidMount}
|
||||||
/>
|
options={{ readOnly: ctrlPressed }}
|
||||||
|
onChange={(val) => setFileContent(val)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Editor
|
||||||
|
height="98%"
|
||||||
|
language={getLanguage(selectedFileExtension)}
|
||||||
|
value={fileContent}
|
||||||
|
editorDidMount={handleEditorDidMount}
|
||||||
|
options={{ readOnly: ctrlPressed }}
|
||||||
|
onChange={(val) => setFileContent(val)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
) : (
|
||||||
@@ -286,6 +319,8 @@ const SASjsEditor = ({
|
|||||||
handleRunBtnClick={handleRunBtnClick}
|
handleRunBtnClick={handleRunBtnClick}
|
||||||
/>
|
/>
|
||||||
<FileMenu
|
<FileMenu
|
||||||
|
showDiff={showDiff}
|
||||||
|
setShowDiff={setShowDiff}
|
||||||
prevFileContent={prevFileContent}
|
prevFileContent={prevFileContent}
|
||||||
currentFileContent={fileContent}
|
currentFileContent={fileContent}
|
||||||
selectedFilePath={selectedFilePath}
|
selectedFilePath={selectedFilePath}
|
||||||
@@ -304,14 +339,26 @@ const SASjsEditor = ({
|
|||||||
}}
|
}}
|
||||||
elevation={3}
|
elevation={3}
|
||||||
>
|
>
|
||||||
<Editor
|
{showDiff ? (
|
||||||
height="98%"
|
<MonacoDiffEditor
|
||||||
language="sas"
|
height="98%"
|
||||||
value={fileContent}
|
language={getLanguage(selectedFileExtension)}
|
||||||
editorDidMount={handleEditorDidMount}
|
original={prevFileContent}
|
||||||
options={{ readOnly: ctrlPressed }}
|
value={fileContent}
|
||||||
onChange={(val) => setFileContent(val)}
|
editorDidMount={handleDiffEditorDidMount}
|
||||||
/>
|
options={{ readOnly: ctrlPressed }}
|
||||||
|
onChange={(val) => setFileContent(val)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Editor
|
||||||
|
height="98%"
|
||||||
|
language={getLanguage(selectedFileExtension)}
|
||||||
|
value={fileContent}
|
||||||
|
editorDidMount={handleEditorDidMount}
|
||||||
|
options={{ readOnly: ctrlPressed }}
|
||||||
|
onChange={(val) => setFileContent(val)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<p
|
<p
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
@@ -433,6 +480,8 @@ const RunMenu = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FileMenuProps = {
|
type FileMenuProps = {
|
||||||
|
showDiff: boolean
|
||||||
|
setShowDiff: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
prevFileContent: string
|
prevFileContent: string
|
||||||
currentFileContent: string
|
currentFileContent: string
|
||||||
selectedFilePath: string
|
selectedFilePath: string
|
||||||
@@ -441,6 +490,8 @@ type FileMenuProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const FileMenu = ({
|
const FileMenu = ({
|
||||||
|
showDiff,
|
||||||
|
setShowDiff,
|
||||||
prevFileContent,
|
prevFileContent,
|
||||||
currentFileContent,
|
currentFileContent,
|
||||||
selectedFilePath,
|
selectedFilePath,
|
||||||
@@ -490,6 +541,16 @@ const FileMenu = ({
|
|||||||
open={!!anchorEl}
|
open={!!anchorEl}
|
||||||
onClose={() => handleMenu()}
|
onClose={() => handleMenu()}
|
||||||
>
|
>
|
||||||
|
<MenuItem sx={{ justifyContent: 'center' }}>
|
||||||
|
<Button
|
||||||
|
onClick={() => setShowDiff(!showDiff)}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
startIcon={showDiff ? <Edit /> : <Difference />}
|
||||||
|
>
|
||||||
|
{showDiff ? 'Edit' : 'Diff'}
|
||||||
|
</Button>
|
||||||
|
</MenuItem>
|
||||||
<MenuItem sx={{ justifyContent: 'center' }}>
|
<MenuItem sx={{ justifyContent: 'center' }}>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSaveBtnClick}
|
onClick={handleSaveBtnClick}
|
||||||
@@ -517,3 +578,17 @@ const FileMenu = ({
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getLanguage = (extension: string) => {
|
||||||
|
if (extension === 'sas') return 'sas'
|
||||||
|
|
||||||
|
if (extension === 'js') return 'javascript'
|
||||||
|
|
||||||
|
if (extension === 'ts') return 'typescript'
|
||||||
|
|
||||||
|
if (extension === 'html') return 'html'
|
||||||
|
|
||||||
|
if (extension === 'css') return 'css'
|
||||||
|
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user