1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

Compare commits

..

3 Commits

Author SHA1 Message Date
semantic-release-bot
0a6b972c65 chore(release): 0.23.4 [skip ci]
## [0.23.4](https://github.com/sasjs/server/compare/v0.23.3...v0.23.4) (2022-10-11)

### Bug Fixes

* add action to editor ref for running code ([2412622](2412622367))
2022-10-11 15:26:38 +00:00
Allan Bowe
be11707042 Merge pull request #303 from sasjs/issue-301
fix: add action to editor ref for running code
2022-10-11 16:08:57 +01:00
2412622367 fix: add action to editor ref for running code 2022-10-10 16:51:46 +05:00
3 changed files with 69 additions and 58 deletions

View File

@@ -1,3 +1,10 @@
## [0.23.4](https://github.com/sasjs/server/compare/v0.23.3...v0.23.4) (2022-10-11)
### Bug Fixes
* add action to editor ref for running code ([2412622](https://github.com/sasjs/server/commit/2412622367eb46c40f388e988ae4606a7ec239b2))
## [0.23.3](https://github.com/sasjs/server/compare/v0.23.2...v0.23.3) (2022-10-09) ## [0.23.3](https://github.com/sasjs/server/compare/v0.23.2...v0.23.3) (2022-10-09)

View File

@@ -48,7 +48,6 @@ const SASjsEditor = ({
setTab setTab
}: SASjsEditorProps) => { }: SASjsEditorProps) => {
const { const {
ctrlPressed,
fileContent, fileContent,
isLoading, isLoading,
log, log,
@@ -64,8 +63,6 @@ const SASjsEditor = ({
handleDiffEditorDidMount, handleDiffEditorDidMount,
handleEditorDidMount, handleEditorDidMount,
handleFilePathInput, handleFilePathInput,
handleKeyDown,
handleKeyUp,
handleRunBtnClick, handleRunBtnClick,
handleTabChange, handleTabChange,
saveFile, saveFile,
@@ -99,7 +96,6 @@ const SASjsEditor = ({
original={prevFileContent} original={prevFileContent}
value={fileContent} value={fileContent}
editorDidMount={handleDiffEditorDidMount} editorDidMount={handleDiffEditorDidMount}
options={{ readOnly: ctrlPressed }}
onChange={(val) => setFileContent(val)} onChange={(val) => setFileContent(val)}
/> />
) : ( ) : (
@@ -108,7 +104,6 @@ const SASjsEditor = ({
language={getLanguageFromExtension(selectedFileExtension)} language={getLanguageFromExtension(selectedFileExtension)}
value={fileContent} value={fileContent}
editorDidMount={handleEditorDidMount} editorDidMount={handleEditorDidMount}
options={{ readOnly: ctrlPressed }}
onChange={(val) => setFileContent(val)} onChange={(val) => setFileContent(val)}
/> />
) )
@@ -176,8 +171,6 @@ const SASjsEditor = ({
{fileMenu} {fileMenu}
</Box> </Box>
<Paper <Paper
onKeyUp={handleKeyUp}
onKeyDown={handleKeyDown}
sx={{ sx={{
height: 'calc(100vh - 170px)', height: 'calc(100vh - 170px)',
padding: '10px', padding: '10px',

View File

@@ -42,7 +42,6 @@ const useEditor = ({
const [prevFileContent, setPrevFileContent] = useStateWithCallback('') const [prevFileContent, setPrevFileContent] = useStateWithCallback('')
const [fileContent, setFileContent] = useState('') const [fileContent, setFileContent] = useState('')
const [log, setLog] = useState('') const [log, setLog] = useState('')
const [ctrlPressed, setCtrlPressed] = useState(false)
const [webout, setWebout] = useState('') const [webout, setWebout] = useState('')
const [runTimes, setRunTimes] = useState<string[]>([]) const [runTimes, setRunTimes] = useState<string[]>([])
const [selectedRunTime, setSelectedRunTime] = useState('') const [selectedRunTime, setSelectedRunTime] = useState('')
@@ -148,53 +147,47 @@ const useEditor = ({
const handleRunBtnClick = () => const handleRunBtnClick = () =>
runCode(getSelection(editorRef.current as any) || fileContent) runCode(getSelection(editorRef.current as any) || fileContent)
const runCode = (code: string) => { const runCode = useCallback(
setIsLoading(true) (code: string) => {
axios setIsLoading(true)
.post(`/SASjsApi/code/execute`, { axios
code: programPathInjection( .post(`/SASjsApi/code/execute`, {
code, code: programPathInjection(
selectedFilePath, code,
selectedRunTime as RunTimeType selectedFilePath,
), selectedRunTime as RunTimeType
runTime: selectedRunTime ),
}) runTime: selectedRunTime
.then((res: any) => { })
setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '') .then((res: any) => {
setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '') setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '')
setTab('log') setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '')
setTab('log')
// Scroll to bottom of log // Scroll to bottom of log
const logElement = document.getElementById('log') const logElement = document.getElementById('log')
if (logElement) logElement.scrollTop = logElement.scrollHeight if (logElement) logElement.scrollTop = logElement.scrollHeight
}) })
.catch((err) => { .catch((err) => {
setModalTitle('Abort') setModalTitle('Abort')
setModalPayload( setModalPayload(
typeof err.response.data === 'object' typeof err.response.data === 'object'
? JSON.stringify(err.response.data) ? JSON.stringify(err.response.data)
: err.response.data : err.response.data
) )
setOpenModal(true) setOpenModal(true)
}) })
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
} },
[
const handleKeyDown = (event: any) => { selectedFilePath,
if (event.ctrlKey) { selectedRunTime,
if (event.key === 'v') { setModalPayload,
setCtrlPressed(false) setModalTitle,
} setOpenModal,
setTab
if (event.key === 'Enter') ]
runCode(getSelection(editorRef.current as any) || fileContent) )
if (!ctrlPressed) setCtrlPressed(true)
}
}
const handleKeyUp = (event: any) => {
if (!event.ctrlKey && ctrlPressed) setCtrlPressed(false)
}
const handleChangeRunTime = (event: SelectChangeEvent) => { const handleChangeRunTime = (event: SelectChangeEvent) => {
setSelectedRunTime(event.target.value as RunTimeType) setSelectedRunTime(event.target.value as RunTimeType)
@@ -223,7 +216,28 @@ const useEditor = ({
if (prevFileContent !== fileContent) return saveFile() if (prevFileContent !== fileContent) return saveFile()
} }
}) })
}, [fileContent, prevFileContent, selectedFilePath, saveFile])
editorRef.current.addAction({
// An unique identifier of the contributed action.
id: 'run-code',
// A label of the action that will be presented to the user.
label: 'Run Code',
// An optional array of keybindings for the action.
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
contextMenuGroupId: 'navigation',
contextMenuOrder: 1,
// Method that will be executed when the action is triggered.
// @param editor The editor instance is passed in as a convenience
run: function () {
runCode(getSelection(editorRef.current as any) || fileContent)
}
})
}, [fileContent, prevFileContent, selectedFilePath, saveFile, runCode])
useEffect(() => { useEffect(() => {
setRunTimes(Object.values(appContext.runTimes)) setRunTimes(Object.values(appContext.runTimes))
@@ -277,7 +291,6 @@ const useEditor = ({
}, [selectedFileExtension, runTimes]) }, [selectedFileExtension, runTimes])
return { return {
ctrlPressed,
fileContent, fileContent,
isLoading, isLoading,
log, log,
@@ -293,8 +306,6 @@ const useEditor = ({
handleDiffEditorDidMount, handleDiffEditorDidMount,
handleEditorDidMount, handleEditorDidMount,
handleFilePathInput, handleFilePathInput,
handleKeyDown,
handleKeyUp,
handleRunBtnClick, handleRunBtnClick,
handleTabChange, handleTabChange,
saveFile, saveFile,