Skip to content

Commit

Permalink
Merge pull request #14753 from Budibase/view-calculation-only-check-v…
Browse files Browse the repository at this point in the history
…isible-fields

Only check visible fields when checking group by view calculations.
  • Loading branch information
samwho authored Oct 10, 2024
2 parents a47b0d9 + 55be64b commit 41143a7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/server/src/api/controllers/row/utils/sqlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
28 changes: 28 additions & 0 deletions packages/server/src/api/routes/tests/viewV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/server/src/sdk/app/rows/search/internal/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions packages/shared-core/src/helpers/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}

0 comments on commit 41143a7

Please sign in to comment.