Merge branch 'master' into fix/views-with-hidden-relationships

This commit is contained in:
Adria Navarro 2024-12-18 12:23:09 +01:00 committed by GitHub
commit 825c517910
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 12 deletions

View File

@ -70,6 +70,10 @@ export function encodeTableId(tableId: string) {
} }
} }
export function encodeViewId(viewId: string) {
return encodeURIComponent(viewId)
}
export function breakExternalTableId(tableId: string) { export function breakExternalTableId(tableId: string) {
const parts = tableId.split(DOUBLE_SEPARATOR) const parts = tableId.split(DOUBLE_SEPARATOR)
let datasourceId = parts.shift() let datasourceId = parts.shift()

View File

@ -66,7 +66,7 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } {
if (docIds.isViewId(sourceId)) { if (docIds.isViewId(sourceId)) {
return { return {
tableId: utils.extractViewInfoFromID(sourceId).tableId, tableId: utils.extractViewInfoFromID(sourceId).tableId,
viewId: sourceId, viewId: sql.utils.encodeViewId(sourceId),
} }
} }
return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) } return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) }

View File

@ -55,7 +55,7 @@ if (descriptions.length) {
let datasource: Datasource | undefined let datasource: Datasource | undefined
function saveTableRequest( function saveTableRequest(
...overrides: Partial<Omit<SaveTableRequest, "name">>[] ...overrides: Partial<SaveTableRequest>[]
): SaveTableRequest { ): SaveTableRequest {
const req: SaveTableRequest = { const req: SaveTableRequest = {
name: generator.guid().replaceAll("-", "").substring(0, 16), name: generator.guid().replaceAll("-", "").substring(0, 16),
@ -1898,6 +1898,36 @@ if (descriptions.length) {
} }
expect(view.queryUI).toEqual(expected) expect(view.queryUI).toEqual(expected)
}) })
it("tables and views can contain whitespaces", async () => {
const table = await config.api.table.save(
saveTableRequest({
name: `table with spaces ${generator.hash()}`,
schema: {
name: {
type: FieldType.STRING,
name: "name",
},
},
})
)
const view = await config.api.viewV2.create({
tableId: table._id!,
name: `view name with spaces`,
schema: {
name: { visible: true },
},
})
expect(await getDelegate(view)).toEqual({
...view,
schema: {
id: { ...table.schema["id"], visible: false },
name: { ...table.schema["name"], visible: true },
},
})
})
}) })
describe("updating table schema", () => { describe("updating table schema", () => {

View File

@ -1,10 +1,4 @@
import { import { context, db as dbCore, docIds, utils } from "@budibase/backend-core"
context,
db as dbCore,
docIds,
utils,
sql,
} from "@budibase/backend-core"
import { import {
DatabaseQueryOpts, DatabaseQueryOpts,
Datasource, Datasource,
@ -334,7 +328,7 @@ export function extractViewInfoFromID(viewId: string) {
const regex = new RegExp(`^(?<tableId>.+)${SEPARATOR}([^${SEPARATOR}]+)$`) const regex = new RegExp(`^(?<tableId>.+)${SEPARATOR}([^${SEPARATOR}]+)$`)
const res = regex.exec(viewId) const res = regex.exec(viewId)
return { return {
tableId: sql.utils.encodeTableId(res!.groups!["tableId"]), tableId: res!.groups!["tableId"],
} }
} }

View File

@ -46,8 +46,11 @@ export class ViewV2API extends TestAPI {
} }
get = async (viewId: string) => { get = async (viewId: string) => {
return (await this._get<ViewResponseEnriched>(`/api/v2/views/${viewId}`)) return (
.data await this._get<ViewResponseEnriched>(
`/api/v2/views/${encodeURIComponent(viewId)}`
)
).data
} }
fetch = async (expectations?: Expectations) => { fetch = async (expectations?: Expectations) => {