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

fix(studio): inject program path to code before sending for execution

This commit is contained in:
2022-09-21 01:57:01 +05:00
parent efd2e1450e
commit edc2e2a302
2 changed files with 34 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
import { RunTimeType } from '../../../context/appContext'
export const getLanguageFromExtension = (extension: string) => { export const getLanguageFromExtension = (extension: string) => {
if (extension === 'js') return 'javascript' if (extension === 'js') return 'javascript'
@@ -12,3 +14,26 @@ export const getSelection = (editor: any) => {
const selection = editor?.getModel().getValueInRange(editor?.getSelection()) const selection = editor?.getModel().getValueInRange(editor?.getSelection())
return selection ?? '' 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
}

View File

@@ -10,7 +10,7 @@ import {
} from 'react' } from 'react'
import { DiffEditorDidMount, EditorDidMount, monaco } from 'react-monaco-editor' import { DiffEditorDidMount, EditorDidMount, monaco } from 'react-monaco-editor'
import { SelectChangeEvent } from '@mui/material' import { SelectChangeEvent } from '@mui/material'
import { getSelection } from '../helper' import { getSelection, programPathInjection } from '../helper'
import { AppContext, RunTimeType } from '../../../../context/appContext' import { AppContext, RunTimeType } from '../../../../context/appContext'
import { AlertSeverityType } from '../../../../components/snackbar' import { AlertSeverityType } from '../../../../components/snackbar'
import { import {
@@ -151,7 +151,14 @@ const useEditor = ({
const runCode = (code: string) => { const runCode = (code: string) => {
setIsLoading(true) setIsLoading(true)
axios axios
.post(`/SASjsApi/code/execute`, { code, runTime: selectedRunTime }) .post(`/SASjsApi/code/execute`, {
code: programPathInjection(
code,
selectedFilePath,
selectedRunTime as RunTimeType
),
runTime: selectedRunTime
})
.then((res: any) => { .then((res: any) => {
setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '') setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '')
setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '') setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '')