forked from tsai/budibase
11 changed files with 88 additions and 246 deletions
@ -1,63 +0,0 @@ |
|||
import { buildCodeForScreens } from "../src/builderStore/buildCodeForScreens" |
|||
|
|||
describe("buildCodeForScreen", () => { |
|||
it("should package _code into runnable function, for simple screen props", () => { |
|||
const screen = { |
|||
props: { |
|||
_id: "1234", |
|||
_code: "render('render argument');", |
|||
}, |
|||
} |
|||
|
|||
let renderArg |
|||
const render = arg => { |
|||
renderArg = arg |
|||
} |
|||
const uiFunctions = getFunctions(screen) |
|||
|
|||
const targetfunction = uiFunctions[screen.props._id] |
|||
expect(targetfunction).toBeDefined() |
|||
|
|||
targetfunction(render) |
|||
|
|||
expect(renderArg).toBe("render argument") |
|||
}) |
|||
|
|||
it("should package _code into runnable function, for _children ", () => { |
|||
const screen = { |
|||
props: { |
|||
_id: "parent", |
|||
_code: "render('parent argument');", |
|||
_children: [ |
|||
{ |
|||
_id: "child1", |
|||
_code: "render('child 1 argument');", |
|||
}, |
|||
{ |
|||
_id: "child2", |
|||
_code: "render('child 2 argument');", |
|||
}, |
|||
], |
|||
}, |
|||
} |
|||
|
|||
let renderArg |
|||
const render = arg => { |
|||
renderArg = arg |
|||
} |
|||
const uiFunctions = getFunctions(screen) |
|||
|
|||
const targetfunction = uiFunctions["child2"] |
|||
expect(targetfunction).toBeDefined() |
|||
|
|||
targetfunction(render) |
|||
|
|||
expect(renderArg).toBe("child 2 argument") |
|||
}) |
|||
}) |
|||
|
|||
const getFunctions = screen => { |
|||
const code = buildCodeForScreens([screen]) |
|||
const func = new Function(`return ${code}`)() |
|||
return func |
|||
} |
|||
@ -1,111 +0,0 @@ |
|||
const Router = require("@koa/router") |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const joiValidator = require("../../middleware/joi-validator") |
|||
const Joi = require("joi") |
|||
const { |
|||
listScreens, |
|||
saveScreen, |
|||
compileStaticAssetsForPage, |
|||
deleteScreen, |
|||
} = require("../../utilities/builder") |
|||
const authorized = require("../../middleware/authorized") |
|||
const { BUILDER } = require("../../utilities/accessLevels") |
|||
|
|||
const router = Router() |
|||
|
|||
function generateSaveValidation() { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
_css: Joi.string().allow(""), |
|||
name: Joi.string().required(), |
|||
route: Joi.string().required(), |
|||
props: Joi.object({ |
|||
_id: Joi.string().required(), |
|||
_component: Joi.string().required(), |
|||
_children: Joi.array().required(), |
|||
_instanceName: Joi.string().required(), |
|||
_styles: Joi.object().required(), |
|||
type: Joi.string().optional(), |
|||
table: Joi.string().optional(), |
|||
}).required().unknown(true), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
function generatePatchValidation() { |
|||
return joiValidator.body( |
|||
Joi.object({ |
|||
oldname: Joi.string().required(), |
|||
newname: Joi.string().required(), |
|||
}).unknown(true) |
|||
) |
|||
} |
|||
|
|||
router.post( |
|||
"/_builder/api/:appId/pages/:pageName", |
|||
authorized(BUILDER), |
|||
async ctx => { |
|||
await compileStaticAssetsForPage( |
|||
ctx.params.appId, |
|||
ctx.params.pageName, |
|||
ctx.request.body |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
) |
|||
|
|||
router.get( |
|||
"/_builder/api/:appId/pages/:pagename/screens", |
|||
authorized(BUILDER), |
|||
async ctx => { |
|||
ctx.body = await listScreens(ctx.params.appId, ctx.params.pagename) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
) |
|||
|
|||
router.post( |
|||
"/_builder/api/:appId/pages/:pagename/screen", |
|||
authorized(BUILDER), |
|||
generateSaveValidation(), |
|||
async ctx => { |
|||
ctx.body = await saveScreen( |
|||
ctx.config, |
|||
ctx.params.appId, |
|||
ctx.params.pagename, |
|||
ctx.request.body |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
) |
|||
|
|||
router.patch( |
|||
"/_builder/api/:appname/pages/:pagename/screen", |
|||
authorized(BUILDER), |
|||
generatePatchValidation(), |
|||
async ctx => { |
|||
await renameScreen( |
|||
ctx.config, |
|||
ctx.params.appname, |
|||
ctx.params.pagename, |
|||
ctx.request.body.oldname, |
|||
ctx.request.body.newname |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
) |
|||
|
|||
router.delete( |
|||
"/_builder/api/pages/:pagename/screens/:id", |
|||
authorized(BUILDER), |
|||
async ctx => { |
|||
await deleteScreen( |
|||
ctx.config, |
|||
ctx.user.appId, |
|||
ctx.params.pagename, |
|||
ctx.params.id |
|||
) |
|||
|
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
) |
|||
|
|||
module.exports = router |
|||
Loading…
Reference in new issue