import React, { useEffect, useRef, useState } from 'react' import axios from 'axios' import Box from '@mui/material/Box' import { Button, Paper, Stack, Tab, Tooltip } from '@mui/material' import { makeStyles } from '@mui/styles' import Editor, { EditorDidMount } from 'react-monaco-editor' import { useLocation } from 'react-router-dom' import { TabContext, TabList, TabPanel } from '@mui/lab' const useStyles = makeStyles(() => ({ root: { fontSize: '1rem', color: 'gray', '&.Mui-selected': { color: 'black' } }, subMenu: { marginTop: '25px', display: 'flex', justifyContent: 'center' }, runButton: { display: 'flex', alignItems: 'center', padding: '5px 5px', minWidth: 'unset' } })) const Studio = () => { const location = useLocation() const [fileContent, setFileContent] = useState('') const [log, setLog] = useState('') const [ctrlPressed, setCtrlPressed] = useState(false) const [webout, setWebout] = useState('') const [tab, setTab] = React.useState('1') const handleTabChange = (_e: any, newValue: string) => { setTab(newValue) } const editorRef = useRef(null as any) const handleEditorDidMount: EditorDidMount = (editor) => { editor.focus() editorRef.current = editor } const getSelection = () => { const editor = editorRef.current as any const selection = editor?.getModel().getValueInRange(editor?.getSelection()) return selection ?? '' } const handleRunBtnClick = () => runCode(getSelection() || fileContent) const runCode = (code: string) => { axios .post(`/SASjsApi/code/execute`, { code }) .then((res: any) => { const parsedLog = res?.data?.log .map((logLine: any) => logLine.line) .join('\n') setLog(parsedLog) setWebout(`${res.data?._webout}`) setTab('2') // Scroll to bottom of log window.scrollTo(0, document.body.scrollHeight) }) .catch((err) => console.log(err)) } const handleKeyDown = (event: any) => { if (event.ctrlKey) { if (event.key === 'v') { setCtrlPressed(false) } if (event.key === 'Enter') runCode(getSelection() || fileContent) if (!ctrlPressed) setCtrlPressed(true) } } const handleKeyUp = (event: any) => { if (!event.ctrlKey && ctrlPressed) setCtrlPressed(false) } useEffect(() => { const content = localStorage.getItem('fileContent') ?? '' setFileContent(content) }, []) useEffect(() => { if (fileContent.length) { localStorage.setItem('fileContent', fileContent) } }, [fileContent]) useEffect(() => { const params = new URLSearchParams(location.search) const programPath = params.get('_program') if (programPath?.length) axios .get(`/SASjsApi/drive/file?filePath=${programPath}`) .then((res: any) => setFileContent(res.data.fileContent)) .catch((err) => console.log(err)) }, [location.search]) const classes = useStyles() return (
{/* */} { if (val) setFileContent(val) }} />

Press CTRL + ENTER to run SAS code

SAS Log

{log}
{webout}
) } export default Studio