Type useTemplate as bool
This commit is contained in:
parent
5fe2a1d33e
commit
77c4140e76
|
@ -29,7 +29,7 @@ exports.createApp = async apiKey => {
|
||||||
const body = {
|
const body = {
|
||||||
name,
|
name,
|
||||||
url: `/${name}`,
|
url: `/${name}`,
|
||||||
useTemplate: "true",
|
useTemplate: true,
|
||||||
templateKey: "app/school-admin-panel",
|
templateKey: "app/school-admin-panel",
|
||||||
templateName: "School Admin Panel",
|
templateName: "School Admin Panel",
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ import {
|
||||||
FieldType,
|
FieldType,
|
||||||
BBReferenceFieldSubType,
|
BBReferenceFieldSubType,
|
||||||
Row,
|
Row,
|
||||||
|
BBRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
@ -127,7 +128,7 @@ function checkAppName(
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AppTemplate {
|
interface AppTemplate {
|
||||||
useTemplate?: string
|
useTemplate?: boolean
|
||||||
file?: {
|
file?: {
|
||||||
type?: string
|
type?: string
|
||||||
path: string
|
path: string
|
||||||
|
@ -151,7 +152,7 @@ async function createInstance(appId: string, template: AppTemplate) {
|
||||||
await createRoutingView()
|
await createRoutingView()
|
||||||
await createAllSearchIndex()
|
await createAllSearchIndex()
|
||||||
|
|
||||||
if (template && template.useTemplate === "true") {
|
if (template && template.useTemplate) {
|
||||||
await sdk.backups.importApp(appId, db, template)
|
await sdk.backups.importApp(appId, db, template)
|
||||||
} else {
|
} else {
|
||||||
// create the users table
|
// create the users table
|
||||||
|
@ -428,21 +429,21 @@ async function updateUserColumns(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function creationEvents(request: any, app: App) {
|
async function creationEvents(request: BBRequest<CreateAppRequest>, app: App) {
|
||||||
let creationFns: ((app: App) => Promise<void>)[] = []
|
let creationFns: ((app: App) => Promise<void>)[] = []
|
||||||
|
|
||||||
const body = request.body
|
const { useTemplate, templateKey, file } = request.body
|
||||||
if (body.useTemplate === "true") {
|
if (useTemplate) {
|
||||||
// from template
|
// from template
|
||||||
if (body.templateKey && body.templateKey !== "undefined") {
|
if (templateKey && templateKey !== "undefined") {
|
||||||
creationFns.push(a => events.app.templateImported(a, body.templateKey))
|
creationFns.push(a => events.app.templateImported(a, templateKey))
|
||||||
}
|
}
|
||||||
// from file
|
// from file
|
||||||
else if (request.files?.templateFile) {
|
else if (request.files?.templateFile) {
|
||||||
creationFns.push(a => events.app.fileImported(a))
|
creationFns.push(a => events.app.fileImported(a))
|
||||||
}
|
}
|
||||||
// from server file path
|
// from server file path
|
||||||
else if (request.body.file) {
|
else if (file) {
|
||||||
// explicitly pass in the newly created app id
|
// explicitly pass in the newly created app id
|
||||||
creationFns.push(a => events.app.duplicated(a, app.appId))
|
creationFns.push(a => events.app.duplicated(a, app.appId))
|
||||||
}
|
}
|
||||||
|
@ -452,16 +453,14 @@ async function creationEvents(request: any, app: App) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request.duplicate) {
|
creationFns.push(a => events.app.created(a))
|
||||||
creationFns.push(a => events.app.created(a))
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let fn of creationFns) {
|
for (let fn of creationFns) {
|
||||||
await fn(app)
|
await fn(app)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function appPostCreate(ctx: UserCtx, app: App) {
|
async function appPostCreate(ctx: UserCtx<CreateAppRequest, App>, app: App) {
|
||||||
const tenantId = tenancy.getTenantId()
|
const tenantId = tenancy.getTenantId()
|
||||||
await migrations.backPopulateMigrations({
|
await migrations.backPopulateMigrations({
|
||||||
type: MigrationType.APP,
|
type: MigrationType.APP,
|
||||||
|
@ -472,7 +471,7 @@ async function appPostCreate(ctx: UserCtx, app: App) {
|
||||||
await creationEvents(ctx.request, app)
|
await creationEvents(ctx.request, app)
|
||||||
|
|
||||||
// app import, template creation and duplication
|
// app import, template creation and duplication
|
||||||
if (ctx.request.body.useTemplate === "true") {
|
if (ctx.request.body.useTemplate) {
|
||||||
const { rows } = await getUniqueRows([app.appId])
|
const { rows } = await getUniqueRows([app.appId])
|
||||||
const rowCount = rows ? rows.length : 0
|
const rowCount = rows ? rows.length : 0
|
||||||
if (rowCount) {
|
if (rowCount) {
|
||||||
|
@ -742,7 +741,7 @@ export async function duplicateApp(
|
||||||
const createRequestBody: CreateAppRequest = {
|
const createRequestBody: CreateAppRequest = {
|
||||||
name: appName,
|
name: appName,
|
||||||
url: possibleUrl,
|
url: possibleUrl,
|
||||||
useTemplate: "true",
|
useTemplate: true,
|
||||||
// The app export path
|
// The app export path
|
||||||
file: {
|
file: {
|
||||||
path: tmpPath,
|
path: tmpPath,
|
||||||
|
|
|
@ -139,7 +139,7 @@ describe("/applications", () => {
|
||||||
it("creates app from template", async () => {
|
it("creates app from template", async () => {
|
||||||
const app = await config.api.application.create({
|
const app = await config.api.application.create({
|
||||||
name: utils.newid(),
|
name: utils.newid(),
|
||||||
useTemplate: "true",
|
useTemplate: true,
|
||||||
templateKey: "test",
|
templateKey: "test",
|
||||||
})
|
})
|
||||||
expect(app._id).toBeDefined()
|
expect(app._id).toBeDefined()
|
||||||
|
@ -150,7 +150,7 @@ describe("/applications", () => {
|
||||||
it("creates app from file", async () => {
|
it("creates app from file", async () => {
|
||||||
const app = await config.api.application.create({
|
const app = await config.api.application.create({
|
||||||
name: utils.newid(),
|
name: utils.newid(),
|
||||||
useTemplate: "true",
|
useTemplate: true,
|
||||||
fileToImport: "src/api/routes/tests/data/export.txt",
|
fileToImport: "src/api/routes/tests/data/export.txt",
|
||||||
})
|
})
|
||||||
expect(app._id).toBeDefined()
|
expect(app._id).toBeDefined()
|
||||||
|
@ -170,7 +170,7 @@ describe("/applications", () => {
|
||||||
it("migrates navigation settings from old apps", async () => {
|
it("migrates navigation settings from old apps", async () => {
|
||||||
const app = await config.api.application.create({
|
const app = await config.api.application.create({
|
||||||
name: utils.newid(),
|
name: utils.newid(),
|
||||||
useTemplate: "true",
|
useTemplate: true,
|
||||||
fileToImport: "src/api/routes/tests/data/old-app.txt",
|
fileToImport: "src/api/routes/tests/data/old-app.txt",
|
||||||
})
|
})
|
||||||
expect(app._id).toBeDefined()
|
expect(app._id).toBeDefined()
|
||||||
|
|
|
@ -95,7 +95,7 @@ describe("/templates", () => {
|
||||||
const app = await config.api.application.create({
|
const app = await config.api.application.create({
|
||||||
name,
|
name,
|
||||||
url,
|
url,
|
||||||
useTemplate: "true",
|
useTemplate: true,
|
||||||
templateName: "Agency Client Portal",
|
templateName: "Agency Client Portal",
|
||||||
templateKey: "app/agency-client-portal",
|
templateKey: "app/agency-client-portal",
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { Layout, App, Screen } from "../../documents"
|
||||||
export interface CreateAppRequest {
|
export interface CreateAppRequest {
|
||||||
name: string
|
name: string
|
||||||
url?: string
|
url?: string
|
||||||
useTemplate?: string
|
useTemplate?: boolean
|
||||||
templateName?: string
|
templateName?: string
|
||||||
templateKey?: string
|
templateKey?: string
|
||||||
fileToImport?: string
|
fileToImport?: string
|
||||||
|
|
Loading…
Reference in New Issue