From ac6057480e64426774a9152a3fe9d52c659c9275 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 11 Aug 2022 15:30:59 +0100 Subject: [PATCH] Enrich component definitions with custom components --- .../server/src/api/controllers/component.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/component.js b/packages/server/src/api/controllers/component.js index 2d0aaea23a..d43caf3fdd 100644 --- a/packages/server/src/api/controllers/component.js +++ b/packages/server/src/api/controllers/component.js @@ -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 }