Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2020 from botpress/ya-code-editor-mobx
feat(code-editor): added some enhancements and mobx
- Loading branch information
Showing
25 changed files
with
914 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
copyFiles: ['src/botpress.d.ts', 'src/typings/node.d.ts'] | ||
copyFiles: ['src/botpress.d.ts', 'src/typings/node.d.ts', 'src/typings/bot.config.schema.json'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,68 @@ | ||
import * as sdk from 'botpress/sdk' | ||
|
||
import { EditorErrorStatus } from './editorError' | ||
import { EditorByBot } from './typings' | ||
|
||
export default async (bp: typeof sdk, editorByBot: EditorByBot) => { | ||
const router = bp.http.createRouterForBot('code-editor') | ||
|
||
router.get('/files', async (req, res) => { | ||
router.get('/files', async (req, res, next) => { | ||
try { | ||
res.send(await editorByBot[req.params.botId].fetchFiles()) | ||
} catch (err) { | ||
bp.logger.attachError(err).error('Error fetching files') | ||
res.sendStatus(500) | ||
next(err) | ||
} | ||
}) | ||
|
||
router.get('/config', async (req, res) => { | ||
router.get('/config', async (req, res, next) => { | ||
const { allowGlobal, includeBotConfig } = editorByBot[req.params.botId].getConfig() | ||
try { | ||
res.send({ isGlobalAllowed: await editorByBot[req.params.botId].isGlobalAllowed() }) | ||
res.send({ isGlobalAllowed: allowGlobal, isBotConfigIncluded: includeBotConfig }) | ||
} catch (err) { | ||
bp.logger.attachError(err).error('Error fetching config') | ||
res.sendStatus(500) | ||
next(err) | ||
} | ||
}) | ||
|
||
router.post('/save', async (req, res) => { | ||
router.post('/save', async (req, res, next) => { | ||
try { | ||
await editorByBot[req.params.botId].saveFile(req.body) | ||
res.sendStatus(200) | ||
} catch (err) { | ||
bp.logger.attachError(err).error('Could not save file') | ||
res.sendStatus(500) | ||
next(err) | ||
} | ||
}) | ||
|
||
router.put('/rename', async (req, res) => { | ||
router.put('/rename', async (req, res, next) => { | ||
const { file, newName } = req.body | ||
try { | ||
await editorByBot[req.params.botId].renameFile(file, newName) | ||
res.sendStatus(200) | ||
} catch (err) { | ||
if (err.status === EditorErrorStatus.FILE_ALREADY_EXIST) { | ||
res.sendStatus(409) // conflict, file already exists | ||
return | ||
} | ||
if (err.status === EditorErrorStatus.INVALID_NAME) { | ||
res.sendStatus(412) // pre-condition fail, invalid filename | ||
return | ||
} | ||
|
||
bp.logger.attachError(err).error('Could not rename file') | ||
res.sendStatus(500) | ||
next(err) | ||
} | ||
}) | ||
|
||
// not REST, but need the whole file info in the body | ||
router.post('/remove', async (req, res) => { | ||
router.post('/remove', async (req, res, next) => { | ||
const file = req.body | ||
try { | ||
await editorByBot[req.params.botId].deleteFile(file) | ||
res.sendStatus(200) | ||
} catch (err) { | ||
bp.logger.attachError(err).error('Could not delete file') | ||
res.sendStatus(500) | ||
next(err) | ||
} | ||
}) | ||
|
||
router.get('/typings', async (req, res) => { | ||
router.get('/typings', async (req, res, next) => { | ||
try { | ||
res.send(await editorByBot[req.params.botId].loadTypings()) | ||
} catch (err) { | ||
bp.logger.attachError(err).error('Could not load typings. Code completion will not be available') | ||
res.sendStatus(500) | ||
next(err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.