diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 54725503b9..35cd8b09f6 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -216,9 +216,9 @@ export const getFrontendStore = () => { if (pageName == null) { pageName = state.pages.main.name } - for (let screenToDelete of Array.isArray(screenToDelete) - ? screenToDelete - : [screenToDelete]) { + for (let screenToDelete of Array.isArray(screensToDelete) + ? screensToDelete + : [screensToDelete]) { // Remove screen from current page as well // TODO: Should be done server side state.pages[pageName]._screens = state.pages[ 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 + ) + } + // check for renaming of columns or deleted columns + if (rename || deletedColumns.length !== 0) { + const rows = await db.allDocs( + getRowParams(updatedTable._id, null, { + include_docs: true, + }) + ) + updatedRows = rows.rows.map(({ doc }) => { + if (rename) { + doc[rename.updated] = doc[rename.old] + delete doc[rename.old] + } else if (deletedColumns.length !== 0) { + deletedColumns.forEach(colName => delete doc[colName]) + } + return doc + }) + delete updatedTable._rename + } + return updatedRows +} + exports.fetch = async function(ctx) { const db = new CouchDB(ctx.user.appId) const body = await db.allDocs( @@ -33,7 +63,6 @@ exports.save = async function(ctx) { views: {}, ...rest, } - let renameDocs = [] // if the table obj had an _id then it will have been retrieved let oldTable @@ -65,20 +94,10 @@ exports.save = async function(ctx) { ctx.throw(400, "Cannot rename a linked column.") } else if (_rename && tableToSave.primaryDisplay === _rename.old) { ctx.throw(400, "Cannot rename the display column.") - } else if (_rename) { - const rows = await db.allDocs( - getRowParams(tableToSave._id, null, { - include_docs: true, - }) - ) - renameDocs = rows.rows.map(({ doc }) => { - doc[_rename.updated] = doc[_rename.old] - delete doc[_rename.old] - return doc - }) - delete tableToSave._rename } + let updatedRows = await checkForColumnUpdates(db, oldTable, tableToSave) + // update schema of non-statistics views when new columns are added for (let view in tableToSave.views) { const tableView = tableToSave.views[view] @@ -100,8 +119,8 @@ exports.save = async function(ctx) { // don't perform any updates until relationships have been // checked by the updateLinks function - if (renameDocs.length !== 0) { - await db.bulkDocs(renameDocs) + if (updatedRows && updatedRows.length !== 0) { + await db.bulkDocs(updatedRows) } const result = await db.post(tableToSave) tableToSave._rev = result.rev 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")