From f57acfdf16570f20b69bae7c0c3d97b483cfbc15 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 10 Nov 2020 15:09:54 +0000 Subject: [PATCH] Fixing #848 - standard components was not using the same API calls consistently which was breaking some things like charts. For now just make it consistent by updating it to make calls the same way as client lib does but the SDK will eventually replace all this and solve these problems. --- .../userInterface/PageLayout.svelte | 6 +- packages/server/src/api/controllers/table.js | 9 ++- packages/standard-components/src/api.js | 55 +++++++++++++++++-- 3 files changed, 60 insertions(+), 10 deletions(-) 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")