Merge branch 'master' into s3-upload-fixes

This commit is contained in:
deanhannigan 2025-01-13 13:54:38 +00:00 committed by GitHub
commit bce541a84e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 53 additions and 15 deletions

View File

@ -1,19 +1,20 @@
import { Constants } from "@budibase/frontend-core"
import { Constants, APIClient } from "@budibase/frontend-core"
import { FieldTypes } from "../constants"
import { Row, Table } from "@budibase/types"
export const patchAPI = API => {
export const patchAPI = (API: APIClient) => {
/**
* Enriches rows which contain certain field types so that they can
* be properly displayed.
* The ability to create these bindings has been removed, but they will still
* exist in client apps to support backwards compatibility.
*/
const enrichRows = async (rows, tableId) => {
const enrichRows = async (rows: Row[], tableId: string) => {
if (!Array.isArray(rows)) {
return []
}
if (rows.length) {
const tables = {}
const tables: Record<string, Table> = {}
for (let row of rows) {
// Fall back to passed in tableId if row doesn't have it specified
let rowTableId = row.tableId || tableId
@ -54,7 +55,7 @@ export const patchAPI = API => {
const fetchSelf = API.fetchSelf
API.fetchSelf = async () => {
const user = await fetchSelf()
if (user && user._id) {
if (user && "_id" in user && user._id) {
if (user.roleId === "PUBLIC") {
// Don't try to enrich a public user as it will 403
return user
@ -90,13 +91,14 @@ export const patchAPI = API => {
return await enrichRows(rows, tableId)
}
// Wipe any HBS formulae from table definitions, as these interfere with
// Wipe any HBS formulas from table definitions, as these interfere with
// handlebars enrichment
const fetchTableDefinition = API.fetchTableDefinition
API.fetchTableDefinition = async tableId => {
const definition = await fetchTableDefinition(tableId)
Object.keys(definition?.schema || {}).forEach(field => {
if (definition.schema[field]?.type === "formula") {
// @ts-expect-error TODO check what use case removing that would break
delete definition.schema[field].formula
}
})

View File

@ -1,7 +1,7 @@
<script>
import { getContext, onDestroy, onMount, setContext } from "svelte"
import { builderStore } from "stores/builder.js"
import { blockStore } from "stores/blocks.js"
import { blockStore } from "stores/blocks"
const component = getContext("component")
const { styleable } = getContext("sdk")

View File

@ -3,7 +3,7 @@
import Block from "components/Block.svelte"
import BlockComponent from "components/BlockComponent.svelte"
import { makePropSafe as safe } from "@budibase/string-templates"
import { enrichSearchColumns, enrichFilter } from "utils/blocks.js"
import { enrichSearchColumns, enrichFilter } from "utils/blocks"
import { get } from "svelte/store"
export let title

View File

@ -5,7 +5,7 @@
import Block from "components/Block.svelte"
import BlockComponent from "components/BlockComponent.svelte"
import { makePropSafe as safe } from "@budibase/string-templates"
import { enrichSearchColumns, enrichFilter } from "utils/blocks.js"
import { enrichSearchColumns, enrichFilter } from "utils/blocks"
import { Utils } from "@budibase/frontend-core"
export let title

View File

@ -1,5 +1,5 @@
import { makePropSafe as safe } from "@budibase/string-templates"
import { API } from "../api/index.js"
import { API } from "../api"
import { UILogicalOperator } from "@budibase/types"
import { Constants } from "@budibase/frontend-core"

View File

@ -46,6 +46,8 @@ import { buildLogsEndpoints } from "./logs"
import { buildMigrationEndpoints } from "./migrations"
import { buildRowActionEndpoints } from "./rowActions"
export type { APIClient } from "./types"
/**
* Random identifier to uniquely identify a session in a tab. This is
* used to determine the originator of calls to the API, which is in

View File

@ -13,7 +13,7 @@ export interface SelfEndpoints {
generateAPIKey: () => Promise<string | undefined>
fetchDeveloperInfo: () => Promise<FetchAPIKeyResponse>
fetchBuilderSelf: () => Promise<GetGlobalSelfResponse>
fetchSelf: () => Promise<AppSelfResponse>
fetchSelf: () => Promise<AppSelfResponse | null>
}
export const buildSelfEndpoints = (API: BaseAPIClient): SelfEndpoints => ({

View File

@ -1,4 +1,5 @@
export { createAPIClient } from "./api"
export type { APIClient } from "./api"
export { fetchData, DataFetchMap } from "./fetch"
export type { DataFetchType } from "./fetch"
export * as Constants from "./constants"

View File

@ -97,7 +97,7 @@ export async function run({
const ctx: any = buildCtx(appId, emitter, {
body: inputs.row,
params: {
tableId: inputs.row.tableId,
tableId: decodeURIComponent(inputs.row.tableId),
},
})
try {

View File

@ -85,7 +85,7 @@ export async function run({
_rev: inputs.revision,
},
params: {
tableId: inputs.tableId,
tableId: decodeURIComponent(inputs.tableId),
},
})

View File

@ -122,9 +122,10 @@ export async function run({
sortType =
fieldType === FieldType.NUMBER ? FieldType.NUMBER : FieldType.STRING
}
// when passing the tableId in the Ctx it needs to be decoded
const ctx = buildCtx(appId, null, {
params: {
tableId,
tableId: decodeURIComponent(tableId),
},
body: {
sortType,

View File

@ -90,6 +90,8 @@ export async function run({
}
}
const tableId = inputs.row.tableId
? decodeURIComponent(inputs.row.tableId)
: inputs.row.tableId
// Base update
let rowUpdate: Record<string, any>
@ -157,7 +159,7 @@ export async function run({
},
params: {
rowId: inputs.rowId,
tableId,
tableId: tableId,
},
})
await rowController.patch(ctx)

View File

@ -2,6 +2,7 @@ import { EmptyFilterOption, SortOrder, Table } from "@budibase/types"
import * as setup from "./utilities"
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
import * as automation from "../index"
import { basicTable } from "../../tests/utilities/structures"
const NAME = "Test"
@ -13,6 +14,7 @@ describe("Test a query step automation", () => {
await automation.init()
await config.init()
table = await config.createTable()
const row = {
name: NAME,
description: "original description",
@ -153,4 +155,32 @@ describe("Test a query step automation", () => {
expect(result.steps[0].outputs.rows).toBeDefined()
expect(result.steps[0].outputs.rows.length).toBe(2)
})
it("return rows when querying a table with a space in the name", async () => {
const tableWithSpaces = await config.createTable({
...basicTable(),
name: "table with spaces",
})
await config.createRow({
name: NAME,
tableId: tableWithSpaces._id,
})
const result = await createAutomationBuilder({
name: "Return All Test",
config,
})
.appAction({ fields: {} })
.queryRows(
{
tableId: tableWithSpaces._id!,
onEmptyFilter: EmptyFilterOption.RETURN_ALL,
filters: {},
},
{ stepName: "Query table with spaces" }
)
.run()
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
expect(result.steps[0].outputs.rows.length).toBe(1)
})
})