mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
fix(studio): inject program path to code before sending for execution
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { RunTimeType } from '../../../context/appContext'
|
||||
|
||||
export const getLanguageFromExtension = (extension: string) => {
|
||||
if (extension === 'js') return 'javascript'
|
||||
|
||||
@@ -12,3 +14,26 @@ export const getSelection = (editor: any) => {
|
||||
const selection = editor?.getModel().getValueInRange(editor?.getSelection())
|
||||
return selection ?? ''
|
||||
}
|
||||
|
||||
export const programPathInjection = (
|
||||
code: string,
|
||||
path: string,
|
||||
runtime: RunTimeType
|
||||
) => {
|
||||
if (path) {
|
||||
if (runtime === RunTimeType.JS) {
|
||||
return `const _PROGRAM = '${path}';\n${code}`
|
||||
}
|
||||
if (runtime === RunTimeType.PY) {
|
||||
return `_PROGRAM = '${path}';\n${code}`
|
||||
}
|
||||
if (runtime === RunTimeType.R) {
|
||||
return `._PROGRAM = '${path}';\n${code}`
|
||||
}
|
||||
if (runtime === RunTimeType.SAS) {
|
||||
return `%let _program = '${path}';\n${code}`
|
||||
}
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from 'react'
|
||||
import { DiffEditorDidMount, EditorDidMount, monaco } from 'react-monaco-editor'
|
||||
import { SelectChangeEvent } from '@mui/material'
|
||||
import { getSelection } from '../helper'
|
||||
import { getSelection, programPathInjection } from '../helper'
|
||||
import { AppContext, RunTimeType } from '../../../../context/appContext'
|
||||
import { AlertSeverityType } from '../../../../components/snackbar'
|
||||
import {
|
||||
@@ -151,7 +151,14 @@ const useEditor = ({
|
||||
const runCode = (code: string) => {
|
||||
setIsLoading(true)
|
||||
axios
|
||||
.post(`/SASjsApi/code/execute`, { code, runTime: selectedRunTime })
|
||||
.post(`/SASjsApi/code/execute`, {
|
||||
code: programPathInjection(
|
||||
code,
|
||||
selectedFilePath,
|
||||
selectedRunTime as RunTimeType
|
||||
),
|
||||
runTime: selectedRunTime
|
||||
})
|
||||
.then((res: any) => {
|
||||
setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '')
|
||||
setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '')
|
||||
|
||||
Reference in New Issue
Block a user