Enrich component definitions with custom components

This commit is contained in:
Andrew Kingston 2022-08-11 15:30:59 +01:00
parent f6e67e3519
commit 58c9965bd9
1 changed files with 21 additions and 2 deletions

View File

@ -1,6 +1,7 @@
const { DocumentTypes } = require("../../db/utils")
const { DocumentTypes, getPluginParams } = require("../../db/utils")
const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
const { getAppDB } = require("@budibase/backend-core/context")
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
exports.fetchAppComponentDefinitions = async function (ctx) {
const db = getAppDB()
@ -9,7 +10,6 @@ exports.fetchAppComponentDefinitions = async function (ctx) {
let componentManifests = await Promise.all(
app.componentLibraries.map(async library => {
let manifest = await getComponentLibraryManifest(library)
return {
manifest,
library,
@ -30,5 +30,24 @@ exports.fetchAppComponentDefinitions = async function (ctx) {
}
}
}
// Add custom components
const globalDB = getGlobalDB()
const response = await globalDB.allDocs(
getPluginParams(null, {
include_docs: true,
})
)
response.rows
.map(row => row.doc)
.filter(plugin => plugin.schema.type === "component")
.forEach(plugin => {
const fullComponentName = `plugin/${plugin.name}/${plugin.version}`
definitions[fullComponentName] = {
component: fullComponentName,
...plugin.schema.schema,
}
})
ctx.body = definitions
}