From a17bdc3243edbb78a849e22e3421cb40b953bc04 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 20 Sep 2021 09:58:38 +0100 Subject: [PATCH] Update app ID parsing to be able to account for new tenant ID's and fix crash whenever a dev counterpart doesn't exist for a published app --- packages/builder/src/stores/portal/apps.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/stores/portal/apps.js b/packages/builder/src/stores/portal/apps.js index 1b0e8becea..48a917534f 100644 --- a/packages/builder/src/stores/portal/apps.js +++ b/packages/builder/src/stores/portal/apps.js @@ -3,6 +3,11 @@ import { get } from "builderStore/api" import { AppStatus } from "../../constants" import api from "../../builderStore/api" +const extractAppId = id => { + const split = id?.split("_") || [] + return split.length ? split[split.length - 1] : null +} + export function createAppStore() { const store = writable([]) @@ -18,7 +23,7 @@ export function createAppStore() { // First append all dev app version devApps.forEach(app => { - const id = app.appId.substring(8) + const id = extractAppId(app.appId) appMap[id] = { ...app, devId: app.appId, @@ -28,7 +33,13 @@ export function createAppStore() { // Then merge with all prod app versions deployedApps.forEach(app => { - const id = app.appId.substring(4) + const id = extractAppId(app.appId) + + // Skip any deployed apps which don't have a dev counterpart + if (!appMap[id]) { + return + } + appMap[id] = { ...appMap[id], ...app, @@ -40,7 +51,7 @@ export function createAppStore() { // Transform into an array and clean up const apps = Object.values(appMap) apps.forEach(app => { - app.appId = app.devId.substring(8) + app.appId = extractAppId(app.devId) delete app._id delete app._rev })