Merge pull request #14753 from Budibase/view-calculation-only-check-visible-fields

Only check visible fields when checking group by view calculations.
This commit is contained in:
Sam Rose 2024-10-10 09:34:21 +01:00 committed by GitHub
commit 41143a7ff4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 8 deletions

View File

@ -133,9 +133,7 @@ export async function buildSqlFieldList(
let fields: string[] = []
if (sdk.views.isView(source)) {
fields = Object.keys(helpers.views.basicFields(source)).filter(
key => source.schema?.[key]?.visible !== false
)
fields = Object.keys(helpers.views.basicFields(source))
} else {
fields = extractRealFields(source)
}

View File

@ -800,6 +800,34 @@ describe.each([
)
}
})
isInternal &&
it("shouldn't trigger a complex type check on a group by field if field is invisible", async () => {
const table = await config.api.table.save(
saveTableRequest({
schema: {
field: {
name: "field",
type: FieldType.JSON,
},
},
})
)
await config.api.viewV2.create(
{
tableId: table._id!,
name: generator.guid(),
type: ViewV2Type.CALCULATION,
schema: {
field: { visible: false },
},
},
{
status: 201,
}
)
})
})
describe("update", () => {

View File

@ -68,9 +68,7 @@ async function buildInternalFieldList(
const { relationships, allowedFields } = opts || {}
let schemaFields: string[] = []
if (sdk.views.isView(source)) {
schemaFields = Object.keys(helpers.views.basicFields(source)).filter(
key => source.schema?.[key]?.visible !== false
)
schemaFields = Object.keys(helpers.views.basicFields(source))
} else {
schemaFields = Object.keys(source.schema).filter(
key => source.schema[key].visible !== false

View File

@ -33,6 +33,13 @@ export function calculationFields(view: UnsavedViewV2) {
return pickBy(view.schema || {}, isCalculationField)
}
export function basicFields(view: UnsavedViewV2) {
return pickBy(view.schema || {}, field => !isCalculationField(field))
export function isVisible(field: ViewFieldMetadata) {
return field.visible !== false
}
export function basicFields(view: UnsavedViewV2, opts?: { visible?: boolean }) {
const { visible = true } = opts || {}
return pickBy(view.schema || {}, field => {
return !isCalculationField(field) && (!visible || isVisible(field))
})
}