diff --git a/Web/src/containers/SASjsDrive/main.tsx b/Web/src/containers/SASjsDrive/main.tsx index a93a701..80be724 100644 --- a/Web/src/containers/SASjsDrive/main.tsx +++ b/Web/src/containers/SASjsDrive/main.tsx @@ -14,15 +14,15 @@ const Main = (props: any) => { const baseUrl = window.location.origin const [isLoading, setIsLoading] = useState(false) + const [fileContentBeforeEdit, setFileContentBeforeEdit] = useState('') const [fileContent, setFileContent] = useState('') const [editMode, setEditMode] = useState(false) useEffect(() => { - console.log('from main', props.selectedFilePath) if (props.selectedFilePath !== '') { setIsLoading(true) axios - .get(`${baseUrl}/SASjsDrive?filepath=${props.selectedFilePath}`) + .get(`${baseUrl}/SASjsApi/files?filepath=${props.selectedFilePath}`) .then((res: any) => { setIsLoading(false) setFileContent(res.data.fileContent) @@ -32,11 +32,12 @@ const Main = (props: any) => { const handleEditSaveBtnClick = () => { if (!editMode) { + setFileContentBeforeEdit(fileContent) setEditMode(true) } else { setIsLoading(true) axios - .post(`${baseUrl}/SASjsDrive`, { + .post(`${baseUrl}/SASjsApi/files`, { filePath: props.selectedFilePath, fileContent: fileContent }) @@ -49,7 +50,17 @@ const Main = (props: any) => { const handleCancelExecuteBtnClick = () => { if (editMode) { + setFileContent(fileContentBeforeEdit) setEditMode(false) + } else { + setIsLoading(true) + axios + .get(`${baseUrl}/SASjsExecutor/do?_program=${props.selectedFilePath}`) + .then((res) => { + setIsLoading(false) + setEditMode(false) + console.log(res) + }) } } diff --git a/Web/src/containers/SASjsDrive/sideBar.tsx b/Web/src/containers/SASjsDrive/sideBar.tsx index 7f5a4de..389eb91 100644 --- a/Web/src/containers/SASjsDrive/sideBar.tsx +++ b/Web/src/containers/SASjsDrive/sideBar.tsx @@ -41,7 +41,7 @@ const SideBar = (props: any) => { const [directoryData, setDirectoryData] = useState(null) useEffect(() => { - axios.get(`${baseUrl}/SASjsExecutor`).then((res: any) => { + axios.get(`${baseUrl}/SASjsApi/executor`).then((res: any) => { if (res.data && res.data?.status === 'success') { setDirectoryData(res.data.tree) } diff --git a/src/routes/index.ts b/src/routes/index.ts index f9b522a..8148bdd 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -13,7 +13,7 @@ import { getTmpFilesFolderPath } from '../utils' const router = express.Router() router.get('/', async (_, res) => { - res.status(200).send('Welcome to @sasjs/server API') + res.sendFile(path.join(__dirname, '..', '..', 'Web', 'build', 'index.html')) }) router.post('/deploy', async (req, res) => { @@ -44,21 +44,21 @@ router.post('/deploy', async (req, res) => { }) }) -router.get('/SASjsDrive', async (req, res) => { +router.get('/SASjsApi/files', async (req, res) => { if (req.query.filepath) { const fileContent = await sasjsDrive(req.query.filepath as string, 'read') res.status(200).send({ status: 'success', fileContent: fileContent }) } else { - res.sendFile(path.join(__dirname, '..', '..', 'Web', 'build', 'index.html')) + throw 'Invalid Request: File path is not provided.' } }) -router.post('/SASjsDrive', async (req, res) => { +router.post('/SASjsApi/files', async (req, res) => { await sasjsDrive(req.body.filePath as string, 'update', req.body.fileContent) res.status(200).send({ status: 'success' }) }) -router.get('/SASjsExecutor', async (req, res) => { +router.get('/SASjsApi/executor', async (req, res) => { const tree = sasjsExecutor() res.status(200).send({ status: 'success', tree }) })