This commit is contained in:
Sam Rose 2024-10-08 11:50:16 +01:00
parent 863ce48cfa
commit 9b3ab049a4
No known key found for this signature in database
3 changed files with 52 additions and 1 deletions

View File

@ -26,6 +26,8 @@ import {
BBReferenceFieldSubType, BBReferenceFieldSubType,
NumericCalculationFieldMetadata, NumericCalculationFieldMetadata,
ViewV2Schema, ViewV2Schema,
canGroupBy,
ViewV2Type,
} from "@budibase/types" } from "@budibase/types"
import { generator, mocks } from "@budibase/backend-core/tests" import { generator, mocks } from "@budibase/backend-core/tests"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils" import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
@ -721,6 +723,34 @@ describe.each([
}, },
}) })
}) })
it.only("cannot use complex types as group-by fields", async () => {
const complexTypes = Object.values(FieldType).filter(
type => !canGroupBy(type)
)
for (const type of complexTypes) {
const field = { name: "field", type } as FieldSchema
const table = await config.api.table.save(
saveTableRequest({ schema: { field } })
)
await config.api.viewV2.create(
{
tableId: table._id!,
name: generator.guid(),
type: ViewV2Type.CALCULATION,
schema: {
field: { visible: true },
},
},
{
status: 400,
body: {
message: "",
},
}
)
}
})
}) })
describe("update", () => { describe("update", () => {

View File

@ -1,6 +1,7 @@
import { import {
CalculationType, CalculationType,
FieldType, FieldType,
isNumeric,
PermissionLevel, PermissionLevel,
RelationSchemaField, RelationSchemaField,
RenameColumn, RenameColumn,
@ -103,7 +104,7 @@ async function guardCalculationViewSchema(
) )
} }
if (!isCount && !helpers.schema.isNumeric(targetSchema)) { if (!isCount && !isNumeric(targetSchema.type)) {
throw new HTTPError( throw new HTTPError(
`Calculation field "${name}" references field "${schema.field}" which is not a numeric field`, `Calculation field "${name}" references field "${schema.field}" which is not a numeric field`,
400 400

View File

@ -127,6 +127,26 @@ export const JsonTypes = [
FieldType.ARRAY, FieldType.ARRAY,
] ]
export const NumericTypes = [FieldType.NUMBER, FieldType.BIGINT]
export function isNumeric(type: FieldType) {
return NumericTypes.includes(type)
}
export const GroupByTypes = [
FieldType.STRING,
FieldType.LONGFORM,
FieldType.OPTIONS,
FieldType.NUMBER,
FieldType.BOOLEAN,
FieldType.DATETIME,
FieldType.BIGINT,
]
export function canGroupBy(type: FieldType) {
return GroupByTypes.includes(type)
}
export interface RowAttachment { export interface RowAttachment {
size: number size: number
name: string name: string