{#if Object.keys(blockRefs).length} {#each blocks as block, idx (block.id)} diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index 0fa93f360d..0e5a932aa0 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -400,6 +400,7 @@ width: 480px; font-size: 16px; border-radius: 4px; + cursor: default; } .block .wrap { width: 100%; diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemActions.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemActions.svelte index 1542c65650..e3014f3e56 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemActions.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemActions.svelte @@ -47,5 +47,6 @@ display: flex; gap: var(--spacing-m); padding: 8px 12px; + cursor: default; } From 0eb83239ddc861506806e68c02c6c8f40996b291 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Nov 2024 16:56:43 +0000 Subject: [PATCH 07/16] Lint --- .../automation/AutomationBuilder/DraggableCanvas.svelte | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte index 53de2bec24..f3dcbf9181 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte @@ -44,7 +44,6 @@ w: contentDims.original.w, h: contentDims.original.h, } - dragOffset = [] contentPos.update(state => ({ ...state, x: 0, @@ -135,9 +134,6 @@ // Size of the view port let viewDims = {} - // When dragging the content, maintain the drag start offset - let dragOffset = [] - // Edge around the draggable content let contentDragPadding = 200 @@ -356,7 +352,6 @@ const onViewDragEnd = () => { down = false - dragOffset = [0, 0] } const handleDragDrop = () => { @@ -381,7 +376,6 @@ viewDragOffset = [0, 0] if ($view.dragging) { - dragOffset = [0, 0] view.update(state => ({ ...state, dragging: false, @@ -491,8 +485,6 @@ return } const { x, y } = eleXY(e, viewPort) - - dragOffset = [Math.abs(x - $contentPos.x), Math.abs(y - $contentPos.y)] } const isDraggable = e => { From 1f0de9b9cb802938ffb5b2749beb549f165c8741 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Nov 2024 17:00:02 +0000 Subject: [PATCH 08/16] Remove unused --- .../automation/AutomationBuilder/DraggableCanvas.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte index f3dcbf9181..9e53015f3e 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte @@ -484,7 +484,6 @@ if (down || !viewPort) { return } - const { x, y } = eleXY(e, viewPort) } const isDraggable = e => { From 29c780a458bfa4f41baa42991407c3ba8d060194 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Nov 2024 17:31:32 +0000 Subject: [PATCH 09/16] Removed unnecessary mouse behaviour and added in a fix for dragging an element into its own drag zone. --- .../AutomationBuilder/DraggableCanvas.svelte | 12 +----------- packages/builder/src/stores/builder/automations.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte index 9e53015f3e..b1a4f37f46 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte @@ -480,12 +480,6 @@ } } - const onMoveContent = e => { - if (down || !viewPort) { - return - } - } - const isDraggable = e => { const draggable = ["draggable-view", ...draggableClasses] return draggable.some(cls => e.target.classList.contains(cls)) @@ -596,11 +590,7 @@ }} >
-
+
diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 8f54f85ef5..aa35f8ca09 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -77,6 +77,17 @@ const automationActions = store => ({ * @param {Object} automation the automaton to be mutated */ moveBlock: async (sourcePath, destPath, automation) => { + // The last part of the source node address, containing the id. + const pathSource = sourcePath.at(-1) + + // The last part of the destination node address, containing the id. + const pathEnd = destPath.at(-1) + + // If they are the same then ignore the drag and drop + if (pathSource.id === pathEnd.id) { + return + } + // Use core delete to remove and return the deleted block // from the automation const { deleted, newAutomation } = store.actions.deleteBlock( @@ -89,9 +100,6 @@ const automationActions = store => ({ const newRefs = {} store.actions.traverse(newRefs, newAutomation) - // The last part of the destination node address, containing the id. - const pathEnd = destPath.at(-1) - let finalPath // If dropping in a branch-step dropzone you need to find // the updated parent step route then add the branch details again From 5ccd20a00b02f09f14b586801219e9fa591f4202 Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 27 Nov 2024 10:07:15 +0000 Subject: [PATCH 10/16] Added checks to ignore a drag and drop if it doesn't alter the tree structure --- packages/builder/src/stores/builder/automations.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 08d5cbe816..d9e9f39f0f 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -84,8 +84,18 @@ const automationActions = store => ({ // The last part of the destination node address, containing the id. const pathEnd = destPath.at(-1) - // If they are the same then ignore the drag and drop - if (pathSource.id === pathEnd.id) { + // Check if dragging a step into its own drag zone + const isOwnDragzone = pathSource.id === pathEnd.id + + // Check if dragging the first branch step into the branch node drag zone + const isFirstBranchStep = + pathEnd.branchStepId && + pathEnd.branchIdx === pathSource.branchIdx && + pathSource.stepIdx === 0 + + // If dragging into an area that will not affect the tree structure + // Ignore the drag and drop. + if (isOwnDragzone || isFirstBranchStep) { return } From 2a1d002d7fbc083e90ed62a8b2c834bcc0074d69 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 11 Dec 2024 11:05:11 +0000 Subject: [PATCH 11/16] Fix client error SVG --- packages/client/src/components/ClientApp.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 1610f36bdc..2840d82f47 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -2,7 +2,7 @@ import { writable, get } from "svelte/store" import { setContext, onMount } from "svelte" import { Layout, Heading, Body } from "@budibase/bbui" - import ErrorSVG from "@budibase/frontend-core/assets/error.svg" + import ErrorSVG from "@budibase/frontend-core/assets/error.svg?raw" import { Constants, CookieUtils } from "@budibase/frontend-core" import { getThemeClassNames } from "@budibase/shared-core" import Component from "./Component.svelte" From 635049ab0f641913022fa39d61bef35cdd203f59 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 12 Dec 2024 14:02:52 +0000 Subject: [PATCH 12/16] Making sure table IDs input are correctly formatted for comparison. --- globalSetup.ts | 8 ++++---- packages/backend-core/src/sql/utils.ts | 8 ++++++++ packages/server/src/api/controllers/row/index.ts | 12 +++++++----- .../server/src/api/controllers/row/utils/utils.ts | 12 +++++++----- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/globalSetup.ts b/globalSetup.ts index ec4f38b388..0b0e276b49 100644 --- a/globalSetup.ts +++ b/globalSetup.ts @@ -4,8 +4,8 @@ import { getContainerRuntimeClient, } from "testcontainers" import { ContainerInfo } from "dockerode" -import path from "path" -import lockfile from "proper-lockfile" +import * as path from "path" +import * as lockfile from "proper-lockfile" import { execSync } from "child_process" interface DockerContext { @@ -29,8 +29,8 @@ function getCurrentDockerContext(): DockerContext { async function getBudibaseContainers() { const client = await getContainerRuntimeClient() - const conatiners = await client.container.list() - return conatiners.filter( + const containers = await client.container.list() + return containers.filter( container => container.Labels["com.budibase"] === "true" && container.Labels["org.testcontainers"] === "true" diff --git a/packages/backend-core/src/sql/utils.ts b/packages/backend-core/src/sql/utils.ts index 1b80ff337d..f1e0c4c5ce 100644 --- a/packages/backend-core/src/sql/utils.ts +++ b/packages/backend-core/src/sql/utils.ts @@ -66,6 +66,14 @@ export function buildExternalTableId(datasourceId: string, tableName: string) { return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}` } +export function checkTableId(tableId: string) { + if (isExternalTableID(tableId) && tableId.includes(" ")) { + return encodeURIComponent(tableId) + } else { + return tableId + } +} + export function breakExternalTableId(tableId: string) { const parts = tableId.split(DOUBLE_SEPARATOR) let datasourceId = parts.shift() diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 0463c0a565..77c05abb95 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -288,19 +288,21 @@ function replaceTableNamesInFilters( for (const key of Object.keys(filter)) { const matches = key.match(`^(?.+)\\.(?.+)`) - const relation = matches?.groups?.["relation"] + // this is the possible table name which we need to check if it needs to be converted + const relatedTableName = matches?.groups?.["relation"] const field = matches?.groups?.["field"] - if (!relation || !field) { + if (!relatedTableName || !field) { continue } - const table = allTables.find(r => r._id === tableId)! - if (Object.values(table.schema).some(f => f.name === relation)) { + const table = allTables.find(r => r._id === tableId) + const isColumnName = !!table?.schema[relatedTableName] + if (!table || isColumnName) { continue } - const matchedTable = allTables.find(t => t.name === relation) + const matchedTable = allTables.find(t => t.name === relatedTableName) const relationship = Object.values(table.schema).find( f => isRelationshipField(f) && f.tableId === matchedTable?._id ) diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts index 5b60143792..b729d7470d 100644 --- a/packages/server/src/api/controllers/row/utils/utils.ts +++ b/packages/server/src/api/controllers/row/utils/utils.ts @@ -1,6 +1,6 @@ import * as utils from "../../../../db/utils" -import { docIds } from "@budibase/backend-core" +import { docIds, sql } from "@budibase/backend-core" import { Ctx, DatasourcePlusQueryResponse, @@ -65,19 +65,21 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } { const { sourceId } = ctx.params if (docIds.isViewId(sourceId)) { return { - tableId: utils.extractViewInfoFromID(sourceId).tableId, + tableId: sql.utils.checkTableId( + utils.extractViewInfoFromID(sourceId).tableId + ), viewId: sourceId, } } - return { tableId: ctx.params.sourceId } + return { tableId: sql.utils.checkTableId(ctx.params.sourceId) } } // now check for old way of specifying table ID if (ctx.params?.tableId) { - return { tableId: ctx.params.tableId } + return { tableId: sql.utils.checkTableId(ctx.params.tableId) } } // check body for a table ID if (ctx.request.body?.tableId) { - return { tableId: ctx.request.body.tableId } + return { tableId: sql.utils.checkTableId(ctx.request.body.tableId) } } throw new Error("Unable to find table ID in request") } From 7f62f32adc59e911c9d3e5f52492f472c77b36b9 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 12 Dec 2024 15:55:39 +0000 Subject: [PATCH 13/16] Adding test case for tables with spaces. --- .../src/api/routes/tests/search.spec.ts | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 67f303aac3..e97f48afbe 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -71,18 +71,27 @@ if (descriptions.length) { let tableOrViewId: string let rows: Row[] - async function basicRelationshipTables(type: RelationshipType) { + async function basicRelationshipTables( + type: RelationshipType, + opts?: { + tableName?: string + primaryColumn?: string + otherColumn?: string + } + ) { const relatedTable = await createTable({ - name: { name: "name", type: FieldType.STRING }, + name: { name: opts?.tableName || "name", type: FieldType.STRING }, }) + + const columnName = opts?.primaryColumn || "productCat" + //@ts-ignore - API accepts this structure, will build out rest of definition const tableId = await createTable({ - name: { name: "name", type: FieldType.STRING }, - //@ts-ignore - API accepts this structure, will build out rest of definition - productCat: { + name: { name: opts?.tableName || "name", type: FieldType.STRING }, + [columnName]: { type: FieldType.LINK, relationshipType: type, - name: "productCat", - fieldName: "product", + name: columnName, + fieldName: opts?.otherColumn || "product", tableId: relatedTable, constraints: { type: "array", @@ -2776,6 +2785,42 @@ if (descriptions.length) { }) }) + isSql && + describe("relationship - table with spaces", () => { + let primaryTable: Table, row: Row + + beforeAll(async () => { + const { relatedTable, tableId } = + await basicRelationshipTables( + RelationshipType.ONE_TO_MANY, + { + tableName: "table with spaces", + primaryColumn: "related", + otherColumn: "related", + } + ) + tableOrViewId = tableId + primaryTable = relatedTable + + row = await config.api.row.save(primaryTable._id!, { + name: "foo", + }) + + await config.api.row.save(tableOrViewId, { + name: "foo", + related: [row._id], + }) + }) + + it("should be able to search by table name with spaces", async () => { + await expectQuery({ + equal: { + ["table with spaces.name"]: "foo", + }, + }).toContain([{ name: "foo" }]) + }) + }) + isSql && describe.each([ RelationshipType.MANY_TO_ONE, From eca009920ce2dcb8b10940a59267fa87f8d8a0c4 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 12 Dec 2024 16:00:28 +0000 Subject: [PATCH 14/16] Fixing some type issue found during the frontend-core updates. --- packages/server/src/api/controllers/permission.ts | 4 ++-- packages/types/src/api/web/app/permission.ts | 2 +- packages/types/src/api/web/global/self.ts | 2 +- packages/types/src/documents/app/app.ts | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/controllers/permission.ts b/packages/server/src/api/controllers/permission.ts index 2ef197dbca..e38c736c20 100644 --- a/packages/server/src/api/controllers/permission.ts +++ b/packages/server/src/api/controllers/permission.ts @@ -9,7 +9,7 @@ import { RemovePermissionRequest, RemovePermissionResponse, FetchResourcePermissionInfoResponse, - FetchBuiltinPermissionsRequest, + FetchBuiltinPermissionsResponse, FetchPermissionLevelsRequest, } from "@budibase/types" import { @@ -22,7 +22,7 @@ import { PermissionUpdateType } from "../../sdk/app/permissions" const SUPPORTED_LEVELS = CURRENTLY_SUPPORTED_LEVELS export function fetchBuiltin( - ctx: UserCtx + ctx: UserCtx ) { ctx.body = Object.values(permissions.getBuiltinPermissions()) } diff --git a/packages/types/src/api/web/app/permission.ts b/packages/types/src/api/web/app/permission.ts index 1a19fb0834..407dc2be86 100644 --- a/packages/types/src/api/web/app/permission.ts +++ b/packages/types/src/api/web/app/permission.ts @@ -1,6 +1,6 @@ import { BuiltinPermission, PermissionLevel } from "../../../sdk" -export type FetchBuiltinPermissionsRequest = BuiltinPermission[] +export type FetchBuiltinPermissionsResponse = BuiltinPermission[] export type FetchPermissionLevelsRequest = string[] diff --git a/packages/types/src/api/web/global/self.ts b/packages/types/src/api/web/global/self.ts index 4ba51d2cd5..5f21a8ddc5 100644 --- a/packages/types/src/api/web/global/self.ts +++ b/packages/types/src/api/web/global/self.ts @@ -1,7 +1,7 @@ import { DevInfo, User } from "../../../documents" export interface GenerateAPIKeyRequest { - userId: string + userId?: string } export interface GenerateAPIKeyResponse extends DevInfo {} diff --git a/packages/types/src/documents/app/app.ts b/packages/types/src/documents/app/app.ts index 06fca8307c..e31dd1e9ac 100644 --- a/packages/types/src/documents/app/app.ts +++ b/packages/types/src/documents/app/app.ts @@ -28,6 +28,7 @@ export interface App extends Document { upgradableVersion?: string snippets?: Snippet[] creationVersion?: string + updatedBy?: string } export interface AppInstance { From c5407d36ac08ea21f4bd72233a537ddb136990c3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 12 Dec 2024 16:44:14 +0000 Subject: [PATCH 15/16] Update to account for type fixes --- packages/frontend-core/src/api/other.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/api/other.ts b/packages/frontend-core/src/api/other.ts index b676a00fe7..c39538fd7b 100644 --- a/packages/frontend-core/src/api/other.ts +++ b/packages/frontend-core/src/api/other.ts @@ -1,5 +1,5 @@ import { - FetchBuiltinPermissionsRequest, + FetchBuiltinPermissionsResponse, FetchIntegrationsResponse, GetEnvironmentResponse, GetVersionResponse, @@ -11,7 +11,7 @@ export interface OtherEndpoints { getSystemStatus: () => Promise getBudibaseVersion: () => Promise getIntegrations: () => Promise - getBasePermissions: () => Promise + getBasePermissions: () => Promise getEnvironment: () => Promise } From f857c36e09813c3224be4afaa5d6809f0612ccbf Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 12 Dec 2024 16:50:21 +0000 Subject: [PATCH 16/16] PR comments. --- packages/backend-core/src/sql/utils.ts | 10 +++------- packages/server/src/api/controllers/row/utils/utils.ts | 10 ++++------ packages/server/src/db/utils.ts | 10 ++++++++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/backend-core/src/sql/utils.ts b/packages/backend-core/src/sql/utils.ts index f1e0c4c5ce..14127a189f 100644 --- a/packages/backend-core/src/sql/utils.ts +++ b/packages/backend-core/src/sql/utils.ts @@ -59,15 +59,11 @@ export function isExternalTable(table: Table) { } export function buildExternalTableId(datasourceId: string, tableName: string) { - // encode spaces - if (tableName.includes(" ")) { - tableName = encodeURIComponent(tableName) - } - return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}` + return `${datasourceId}${DOUBLE_SEPARATOR}${encodeURIComponent(tableName)}` } -export function checkTableId(tableId: string) { - if (isExternalTableID(tableId) && tableId.includes(" ")) { +export function encodeTableId(tableId: string) { + if (isExternalTableID(tableId)) { return encodeURIComponent(tableId) } else { return tableId diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts index b729d7470d..baa811fe90 100644 --- a/packages/server/src/api/controllers/row/utils/utils.ts +++ b/packages/server/src/api/controllers/row/utils/utils.ts @@ -65,21 +65,19 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } { const { sourceId } = ctx.params if (docIds.isViewId(sourceId)) { return { - tableId: sql.utils.checkTableId( - utils.extractViewInfoFromID(sourceId).tableId - ), + tableId: utils.extractViewInfoFromID(sourceId).tableId, viewId: sourceId, } } - return { tableId: sql.utils.checkTableId(ctx.params.sourceId) } + return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) } } // now check for old way of specifying table ID if (ctx.params?.tableId) { - return { tableId: sql.utils.checkTableId(ctx.params.tableId) } + return { tableId: sql.utils.encodeTableId(ctx.params.tableId) } } // check body for a table ID if (ctx.request.body?.tableId) { - return { tableId: sql.utils.checkTableId(ctx.request.body.tableId) } + return { tableId: sql.utils.encodeTableId(ctx.request.body.tableId) } } throw new Error("Unable to find table ID in request") } diff --git a/packages/server/src/db/utils.ts b/packages/server/src/db/utils.ts index 6c1065e847..70c69b3c60 100644 --- a/packages/server/src/db/utils.ts +++ b/packages/server/src/db/utils.ts @@ -1,4 +1,10 @@ -import { context, db as dbCore, docIds, utils } from "@budibase/backend-core" +import { + context, + db as dbCore, + docIds, + utils, + sql, +} from "@budibase/backend-core" import { DatabaseQueryOpts, Datasource, @@ -328,7 +334,7 @@ export function extractViewInfoFromID(viewId: string) { const regex = new RegExp(`^(?.+)${SEPARATOR}([^${SEPARATOR}]+)$`) const res = regex.exec(viewId) return { - tableId: res!.groups!["tableId"], + tableId: sql.utils.encodeTableId(res!.groups!["tableId"]), } }