diff --git a/packages/builder/src/components/userInterface/PageLayout.svelte b/packages/builder/src/components/userInterface/PageLayout.svelte index 9837e6df35..932fc0a4f0 100644 --- a/packages/builder/src/components/userInterface/PageLayout.svelte +++ b/packages/builder/src/components/userInterface/PageLayout.svelte @@ -32,11 +32,11 @@ icon="ri-layout-3-line" text="Master Screen" withArrow - selected={$store.currentComponentInfo._id === _layout.component.props._id} - opened={$store.currentPreviewItem.name === _layout.title} + selected={$store.currentComponentInfo?._id === _layout.component.props._id} + opened={$store.currentPreviewItem?.name === _layout.title} on:click={setCurrentScreenToLayout} /> -{#if $store.currentPreviewItem.name === _layout.title && _layout.component.props._children} +{#if $store.currentPreviewItem?.name === _layout.title && _layout.component.props._children} updatedTable.schema[colName] == null - ) + let deletedColumns = [] + if (oldTable && oldTable.schema && updatedTable.schema) { + deletedColumns = Object.keys(oldTable.schema).filter( + colName => updatedTable.schema[colName] == null + ) + } // check for renaming of columns or deleted columns if (rename || deletedColumns.length !== 0) { const rows = await db.allDocs( diff --git a/packages/standard-components/src/api.js b/packages/standard-components/src/api.js index 7d9be3db56..98fb8abd32 100644 --- a/packages/standard-components/src/api.js +++ b/packages/standard-components/src/api.js @@ -1,3 +1,52 @@ +/** + * TODO: this entire file should be removed, this has simply been updated to fix a bug until SDK comes along fixing + * all these sort of inconsistency issues. + */ +const COOKIE_SEPARATOR = ";" +const APP_PREFIX = "app_" +const KEY_VALUE_SPLIT = "=" + +function confirmAppId(possibleAppId) { + return possibleAppId && possibleAppId.startsWith(APP_PREFIX) + ? possibleAppId + : undefined +} + +function tryGetFromCookie() { + const cookie = window.document.cookie + .split(COOKIE_SEPARATOR) + .find(cookie => cookie.trim().startsWith("budibase:currentapp")) + let appId + if (cookie && cookie.split(KEY_VALUE_SPLIT).length === 2) { + appId = cookie.split("=")[1] + } + return confirmAppId(appId) +} + +function tryGetFromPath() { + const appId = location.pathname.split("/")[1] + return confirmAppId(appId) +} + +function tryGetFromSubdomain() { + const parts = window.location.host.split(".") + const appId = parts[1] ? parts[0] : undefined + return confirmAppId(appId) +} + +function getAppId() { + const functions = [tryGetFromSubdomain, tryGetFromPath, tryGetFromCookie] + // try getting the app Id in order + let appId + for (let func of functions) { + appId = func() + if (appId) { + break + } + } + return appId +} + const apiCall = method => async ( url, body, @@ -5,17 +54,15 @@ const apiCall = method => async ( "Content-Type": "application/json", } ) => { - const appId = location.pathname.split("/")[1] + const appId = getAppId() if (appId) { headers["x-budibase-app-id"] = appId } - const response = await fetch(url, { + return await fetch(url, { method: method, body: body && JSON.stringify(body), headers, }) - - return response } export const post = apiCall("POST")