diff --git a/packages/bbui/package.json b/packages/bbui/package.json index 18e2924198..7e57282b2c 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -52,7 +52,7 @@ "@spectrum-css/icon": "^3.0.1", "@spectrum-css/illustratedmessage": "^3.0.2", "@spectrum-css/inputgroup": "^3.0.2", - "@spectrum-css/label": "^2.0.9", + "@spectrum-css/label": "^2.0.10", "@spectrum-css/link": "^3.1.1", "@spectrum-css/menu": "^3.0.1", "@spectrum-css/modal": "^3.0.1", @@ -64,6 +64,7 @@ "@spectrum-css/radio": "^3.0.2", "@spectrum-css/search": "^3.0.2", "@spectrum-css/sidenav": "^3.0.2", + "@spectrum-css/statuslight": "^3.0.2", "@spectrum-css/switch": "^1.0.2", "@spectrum-css/table": "^3.0.1", "@spectrum-css/tabs": "^3.0.1", diff --git a/packages/bbui/src/Badge/Badge.svelte b/packages/bbui/src/Badge/Badge.svelte new file mode 100644 index 0000000000..737d4133d8 --- /dev/null +++ b/packages/bbui/src/Badge/Badge.svelte @@ -0,0 +1,27 @@ + + + + + diff --git a/packages/bbui/src/StatusLight/StatusLight.svelte b/packages/bbui/src/StatusLight/StatusLight.svelte new file mode 100644 index 0000000000..f56fee0c2a --- /dev/null +++ b/packages/bbui/src/StatusLight/StatusLight.svelte @@ -0,0 +1,41 @@ + + +
+ +
diff --git a/packages/bbui/src/Tags/Tag.svelte b/packages/bbui/src/Tags/Tag.svelte index 906065cc71..f7089decdb 100644 --- a/packages/bbui/src/Tags/Tag.svelte +++ b/packages/bbui/src/Tags/Tag.svelte @@ -1,6 +1,8 @@ - - + {#if loaded && enrichedApps.length} + +
+ Apps + + + + +
+
+
+ +
+
+
+ + diff --git a/packages/builder/src/stores/portal/apps.js b/packages/builder/src/stores/portal/apps.js index e0dfe112b5..f0cee6147c 100644 --- a/packages/builder/src/stores/portal/apps.js +++ b/packages/builder/src/stores/portal/apps.js @@ -1,15 +1,49 @@ import { writable } from "svelte/store" import { get } from "builderStore/api" +import { AppStatus } from "../../constants" export function createAppStore() { const store = writable([]) - async function load(status = "") { + async function load() { try { - const res = await get(`/api/applications?status=${status}`) + const res = await get(`/api/applications?status=all`) const json = await res.json() if (res.ok && Array.isArray(json)) { - store.set(json) + // Merge apps into one sensible list + let appMap = {} + let devApps = json.filter(app => app.status === AppStatus.DEV) + let deployedApps = json.filter(app => app.status === AppStatus.DEPLOYED) + + // First append all dev app version + devApps.forEach(app => { + const id = app.appId.substring(8) + appMap[id] = { + ...app, + devId: app.appId, + devRev: app._rev, + } + }) + + // Then merge with all prod app versions + deployedApps.forEach(app => { + const id = app.appId.substring(4) + appMap[id] = { + ...appMap[id], + ...app, + prodId: app.appId, + prodRev: app._rev, + } + }) + + // Transform into an array and clean up + const apps = Object.values(appMap) + apps.forEach(app => { + app.appId = app.devId.substring(8) + delete app._id + delete app._rev + }) + store.set(apps) } else { store.set([]) } diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index 81686ea267..29617a7dff 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -18,9 +18,9 @@ const StaticDatabases = { } const AppStatus = { - DEV: "dev", + DEV: "development", ALL: "all", - DEPLOYED: "PUBLISHED", + DEPLOYED: "published", } const DocumentTypes = { diff --git a/packages/server/src/integrations/postgres.js b/packages/server/src/integrations/postgres.js index c6a24577b3..d567db7ba0 100644 --- a/packages/server/src/integrations/postgres.js +++ b/packages/server/src/integrations/postgres.js @@ -1,4 +1,6 @@ -const { Client } = require("pg") +const { Pool } = require("pg") + +let pool const SCHEMA = { docs: "https://node-postgres.com", @@ -51,31 +53,39 @@ const SCHEMA = { class PostgresIntegration { constructor(config) { this.config = config - this.client = new Client(config) - this.connect() + if (!pool) { + pool = new Pool(this.config) + } } - async connect() { - return this.client.connect() + async query(sql) { + try { + this.client = await pool.connect() + return await this.client.query(sql) + } catch (err) { + throw new Error(err) + } finally { + this.client.release() + } } async create({ sql }) { - const response = await this.client.query(sql) + const response = await this.query(sql) return response.rows.length ? response.rows : [{ created: true }] } async read({ sql }) { - const response = await this.client.query(sql) + const response = await this.query(sql) return response.rows } async update({ sql }) { - const response = await this.client.query(sql) + const response = await this.query(sql) return response.rows.length ? response.rows : [{ updated: true }] } async delete({ sql }) { - const response = await this.client.query(sql) + const response = await this.query(sql) return response.rows.length ? response.rows : [{ deleted: true }] } }