Merge remote-tracking branch 'origin/v3-ui' into feature/automation-branching-ux
This commit is contained in:
commit
48752cea1c
|
@ -15,7 +15,7 @@ import { getViews, saveView } from "../view/utils"
|
||||||
import viewTemplate from "../view/viewBuilder"
|
import viewTemplate from "../view/viewBuilder"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import { context, events, features } from "@budibase/backend-core"
|
import { context, events, features, HTTPError } from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
Database,
|
Database,
|
||||||
|
@ -145,14 +145,21 @@ export async function importToRows(
|
||||||
// the real schema of the table passed in, not the clone used for
|
// the real schema of the table passed in, not the clone used for
|
||||||
// incrementing auto IDs
|
// incrementing auto IDs
|
||||||
for (const [fieldName, schema] of Object.entries(originalTable.schema)) {
|
for (const [fieldName, schema] of Object.entries(originalTable.schema)) {
|
||||||
const rowVal = Array.isArray(row[fieldName])
|
if (schema.type === FieldType.LINK) {
|
||||||
? row[fieldName]
|
throw new HTTPError(
|
||||||
: [row[fieldName]]
|
`Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`,
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(schema.type === FieldType.OPTIONS ||
|
(schema.type === FieldType.OPTIONS ||
|
||||||
schema.type === FieldType.ARRAY) &&
|
schema.type === FieldType.ARRAY) &&
|
||||||
row[fieldName]
|
row[fieldName]
|
||||||
) {
|
) {
|
||||||
|
const rowVal = Array.isArray(row[fieldName])
|
||||||
|
? row[fieldName]
|
||||||
|
: [row[fieldName]]
|
||||||
let merged = [...schema.constraints!.inclusion!, ...rowVal]
|
let merged = [...schema.constraints!.inclusion!, ...rowVal]
|
||||||
let superSet = new Set(merged)
|
let superSet = new Set(merged)
|
||||||
schema.constraints!.inclusion = Array.from(superSet)
|
schema.constraints!.inclusion = Array.from(superSet)
|
||||||
|
|
|
@ -1823,6 +1823,39 @@ describe.each([
|
||||||
expect(row.autoId).toEqual(3)
|
expect(row.autoId).toEqual(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
isInternal &&
|
||||||
|
it("should reject bulkImporting relationship fields", async () => {
|
||||||
|
const table1 = await config.api.table.save(saveTableRequest())
|
||||||
|
const table2 = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
schema: {
|
||||||
|
relationship: {
|
||||||
|
name: "relationship",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: table1._id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "relationship",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const table1Row1 = await config.api.row.save(table1._id!, {})
|
||||||
|
await config.api.row.bulkImport(
|
||||||
|
table2._id!,
|
||||||
|
{
|
||||||
|
rows: [{ relationship: [table1Row1._id!] }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 400,
|
||||||
|
body: {
|
||||||
|
message:
|
||||||
|
'Can\'t bulk import relationship fields for internal databases, found value in field "relationship"',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("should be able to bulkImport rows", async () => {
|
it("should be able to bulkImport rows", async () => {
|
||||||
const table = await config.api.table.save(
|
const table = await config.api.table.save(
|
||||||
saveTableRequest({
|
saveTableRequest({
|
||||||
|
|
Loading…
Reference in New Issue