Fixing issues with the application API, it utilised /api/:appId heavily which is a route that matches nearly everything.

This commit is contained in:
mike12345567 2020-11-19 16:55:59 +00:00
parent e8f55f577b
commit 87528c8d55
9 changed files with 64 additions and 119 deletions

View File

@ -24,6 +24,11 @@ export class Screen extends BaseStructure {
} }
} }
normalStyle(styling) {
this._json.props._styles.normal = styling
return this
}
component(name) { component(name) {
this._json.props._component = name this._json.props._component = name
return this return this

View File

@ -9,7 +9,7 @@
async function deleteApp() { async function deleteApp() {
loading = true loading = true
const id = $params.application const id = $params.application
await del(`/api/${id}`) await del(`/api/applications/${id}`)
loading = false loading = false
$goto("/") $goto("/")
} }

View File

@ -149,7 +149,7 @@
}) })
// Select Correct Application/DB in prep for creating user // Select Correct Application/DB in prep for creating user
const applicationPkg = await get(`/api/${appJson._id}/appPackage`) const applicationPkg = await get(`/api/applications/${appJson._id}/appPackage`)
const pkg = await applicationPkg.json() const pkg = await applicationPkg.json()
if (applicationPkg.ok) { if (applicationPkg.ok) {
backendUiStore.actions.reset() backendUiStore.actions.reset()

View File

@ -3,6 +3,8 @@
import { map, join } from "lodash/fp" import { map, join } from "lodash/fp"
import iframeTemplate from "./iframeTemplate" import iframeTemplate from "./iframeTemplate"
import { pipe } from "../../../helpers" import { pipe } from "../../../helpers"
import { Screen } from "../../../builderStore/store/screenTemplates/utils/Screen"
import { Component } from "../../../builderStore/store/screenTemplates/utils/Component"
let iframe let iframe
let styles = "" let styles = ""
@ -21,114 +23,50 @@
return componentName || "element" return componentName || "element"
} }
const screenPlaceholder = { const headingStyle = {
name: "Screen Placeholder", width: "500px",
route: "*", padding: "8px",
props: {
_id: "screenslot-placeholder",
_component: "@budibase/standard-components/container",
_styles: {
normal: {
flex: "1 1 auto",
},
hover: {},
active: {},
selected: {},
},
_code: "",
className: "",
onLoad: [],
type: "div",
_children: [
{
_id: "51a1b494-0fa4-49c3-90cc-c2a6c7a3f888",
_component: "@budibase/standard-components/container",
_styles: {
normal: {
display: "flex",
"flex-direction": "column",
"align-items": "center",
flex: "1 1 auto",
},
hover: {},
active: {},
selected: {},
},
_code: "",
className: "",
onLoad: [],
type: "div",
_instanceId: "inst_40d9036_4c81114e2bf145ab8721978c66e09a10",
_instanceName: "Container",
_children: [
{
_id: "90a52cd0-f215-46c1-b29b-e28f9e7edf72",
_component: "@budibase/standard-components/heading",
_styles: {
normal: {
width: "500px",
padding: "8px",
},
hover: {},
active: {},
selected: {},
},
_code: "",
className: "",
text: "Screen Slot",
type: "h1",
_instanceId: "inst_40d9036_4c81114e2bf145ab8721978c66e09a10",
_instanceName: "Heading",
_children: [],
},
{
_id: "71a3da65-72c6-4c43-8c6a-49871c07b77d",
_component: "@budibase/standard-components/text",
_styles: {
normal: {
"max-width": "",
"text-align": "left",
width: "500px",
padding: "8px",
},
hover: {},
active: {},
selected: {},
},
_code: "",
text:
"The screens that you create will be displayed inside this box.",
type: "none",
_instanceId: "inst_40d9036_4c81114e2bf145ab8721978c66e09a10",
_instanceName: "Text",
},
{
_id: "8af80374-460d-497b-a5d8-7dd2ec4a7bbc",
_component: "@budibase/standard-components/text",
_styles: {
normal: {
"max-width": "",
"text-align": "left",
width: "500px",
padding: "8px",
},
hover: {},
active: {},
selected: {},
},
_code: "",
text:
"This box is just a placeholder, to show you the position of screens.",
type: "none",
_instanceId: "inst_40d9036_4c81114e2bf145ab8721978c66e09a10",
_instanceName: "Text",
},
],
},
],
_instanceName: "Content Placeholder",
},
} }
const textStyle = {
...headingStyle,
"max-width": "",
"text-align": "left",
}
const heading = new Component("@budibase/standard-components/heading")
.normalStyle(headingStyle)
.type("h1")
.text("Screen Slot")
.instanceName("Heading")
const textScreenDisplay = new Component("@budibase/standard-components/text")
.normalStyle(textStyle)
.instanceName("Text")
.type("none")
.text("The screens that you create will be displayed inside this box. This box is just a placeholder, to show you the position of screens.")
const container = new Component("@budibase/standard-components/container")
.normalStyle({
display: "flex",
"flex-direction": "column",
"align-items": "center",
flex: "1 1 auto",
})
.type("div")
.instanceName("Container")
.addChild(heading)
.addChild(textScreenDisplay)
const screenPlaceholder = new Screen()
.name("Screen Placeholder")
.route("*")
.component("@budibase/standard-components/container")
.mainType("div")
.instanceName("Content Placeholder")
.normalStyle({
flex: "1 1 auto",
})
.addChild(container)
.json()
// TODO: this ID is attached to how the screen slot is rendered, confusing, would be better a type etc
screenPlaceholder.props._id = "screenslot-placeholder"
$: hasComponent = !!$store.currentPreviewItem $: hasComponent = !!$store.currentPreviewItem

View File

@ -13,7 +13,7 @@
let promise = getPackage() let promise = getPackage()
async function getPackage() { async function getPackage() {
const res = await get(`/api/${application}/appPackage`) const res = await get(`/api/applications/${application}/appPackage`)
const pkg = await res.json() const pkg = await res.json()
if (res.ok) { if (res.ok) {

View File

@ -51,7 +51,7 @@ const addWindowGlobals = (window, page, screens) => {
} }
export const makePage = props => ({ props }) export const makePage = props => ({ props })
export const makeScreen = (route, props) => ({ props, route }) export const makeScreen = (route, props) => ({ props, routing: { route, accessLevelId: "" } })
export const timeout = ms => new Promise(resolve => setTimeout(resolve, ms)) export const timeout = ms => new Promise(resolve => setTimeout(resolve, ms))

View File

@ -6,15 +6,15 @@ const { BUILDER } = require("../../utilities/security/permissions")
const router = Router() const router = Router()
router router
.get("/api/:appId/definition", controller.fetchAppDefinition) .get("/api/applications/:appId/definition", controller.fetchAppDefinition)
.get("/api/applications", authorized(BUILDER), controller.fetch) .get("/api/applications", authorized(BUILDER), controller.fetch)
.get( .get(
"/api/:appId/appPackage", "/api/applications/:appId/appPackage",
authorized(BUILDER), authorized(BUILDER),
controller.fetchAppPackage controller.fetchAppPackage
) )
.put("/api/:appId", authorized(BUILDER), controller.update) .put("/api/applications/:appId", authorized(BUILDER), controller.update)
.post("/api/applications", authorized(BUILDER), controller.create) .post("/api/applications", authorized(BUILDER), controller.create)
.delete("/api/:appId", authorized(BUILDER), controller.delete) .delete("/api/applications/:appId", authorized(BUILDER), controller.delete)
module.exports = router module.exports = router

View File

@ -23,17 +23,19 @@ exports.mainRoutes = [
screenRoutes, screenRoutes,
userRoutes, userRoutes,
applicationRoutes, applicationRoutes,
rowRoutes, automationRoutes,
tableRoutes,
viewRoutes, viewRoutes,
componentRoutes, componentRoutes,
automationRoutes,
accesslevelRoutes, accesslevelRoutes,
apiKeysRoutes, apiKeysRoutes,
templatesRoutes, templatesRoutes,
analyticsRoutes, analyticsRoutes,
webhookRoutes, webhookRoutes,
routingRoutes, routingRoutes,
// these need to be handled last as they still use /api/:tableId
// this could be breaking as koa may recognise other routes as this
tableRoutes,
rowRoutes,
] ]
exports.authRoutes = authRoutes exports.authRoutes = authRoutes

View File

@ -109,7 +109,7 @@ exports.clearApplications = async request => {
.set(exports.defaultHeaders()) .set(exports.defaultHeaders())
for (let app of res.body) { for (let app of res.body) {
const appId = app._id const appId = app._id
await request.delete(`/api/${appId}`).set(exports.defaultHeaders(appId)) await request.delete(`/api/applications/${appId}`).set(exports.defaultHeaders(appId))
} }
} }