Skip to content

Commit

Permalink
Merge branch 'v3-ui' into error-on-bulkimporting-relationship-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mike12345567 authored Oct 31, 2024
2 parents 920953a + e3b4998 commit ee9a39a
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 75 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "2.33.12",
"version": "2.33.13",
"npmClient": "yarn",
"packages": [
"packages/*",
Expand Down
19 changes: 12 additions & 7 deletions packages/backend-core/src/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class InternalBuilder {
if (!matchesTableName) {
updatedKey = filterKey.replace(
new RegExp(`^${relationship.column}.`),
`${aliases![relationship.tableName]}.`
`${aliases?.[relationship.tableName] || relationship.tableName}.`
)
} else {
updatedKey = filterKey
Expand Down Expand Up @@ -1091,7 +1091,14 @@ class InternalBuilder {
)
}
} else {
query = query.count(`* as ${aggregation.name}`)
if (this.client === SqlClient.ORACLE) {
const field = this.convertClobs(`${tableName}.${aggregation.field}`)
query = query.select(
this.knex.raw(`COUNT(??) as ??`, [field, aggregation.name])
)
} else {
query = query.count(`${aggregation.field} as ${aggregation.name}`)
}
}
} else {
const fieldSchema = this.getFieldSchema(aggregation.field)
Expand Down Expand Up @@ -1579,7 +1586,7 @@ class InternalBuilder {
query = this.addFilters(query, filters, { relationship: true })

// handle relationships with a CTE for all others
if (relationships?.length) {
if (relationships?.length && aggregations.length === 0) {
const mainTable =
this.query.tableAliases?.[this.query.endpoint.entityId] ||
this.query.endpoint.entityId
Expand All @@ -1594,10 +1601,8 @@ class InternalBuilder {
// add JSON aggregations attached to the CTE
return this.addJsonRelationships(cte, tableName, relationships)
}
// no relationships found - return query
else {
return query
}

return query
}

update(opts: QueryOptions): Knex.QueryBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
allowSelectRows={!readonly}
{customRenderers}
loading={!$fetch.loaded || !groupsLoaded}
defaultSortColumn={"__selectable"}
defaultSortColumn={"access"}
/>
<div class="pagination">
Expand Down
2 changes: 1 addition & 1 deletion packages/server/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"../string-templates"
],
"ext": "js,ts,json,svelte",
"ignore": ["**/*.spec.ts", "**/*.spec.js", "../*/dist/**/*"],
"ignore": ["**/*.spec.ts", "**/*.spec.js", "../*/dist/**/*", "client/**/*", "builder/**/*"],
"exec": "yarn build && node --no-node-snapshot ./dist/index.js"
}
23 changes: 12 additions & 11 deletions packages/server/src/api/controllers/row/ExternalRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,19 @@ export class ExternalRequest<T extends Operation> {
filters = this.prepareFilters(id, filters || {}, table)
const relationships = buildExternalRelationships(table, this.tables)

let aggregations: Aggregation[] = []
if (sdk.views.isView(this.source)) {
const calculationFields = helpers.views.calculationFields(this.source)
for (const [key, field] of Object.entries(calculationFields)) {
aggregations.push({
...field,
name: key,
})
}
}

const incRelationships =
aggregations.length === 0 &&
config.includeSqlRelationships === IncludeRelationship.INCLUDE

// clean up row on ingress using schema
Expand All @@ -709,17 +721,6 @@ export class ExternalRequest<T extends Operation> {
throw "Deletion must be filtered"
}

let aggregations: Aggregation[] = []
if (sdk.views.isView(this.source)) {
const calculationFields = helpers.views.calculationFields(this.source)
for (const [key, field] of Object.entries(calculationFields)) {
aggregations.push({
...field,
name: key,
})
}
}

let json: QueryJson = {
endpoint: {
datasourceId: this.datasource._id!,
Expand Down
10 changes: 10 additions & 0 deletions packages/server/src/api/controllers/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ const requiresMigration = async (ctx: Ctx) => {
}

export const serveApp = async function (ctx: UserCtx) {
if (ctx.url.includes("apple-touch-icon.png")) {
ctx.redirect("/builder/bblogo.png")
return
}
// no app ID found, cannot serve - return message instead
if (!context.getAppId()) {
ctx.body = "No content found - requires app ID"
return
}

const needMigrations = await requiresMigration(ctx)

const bbHeaderEmbed =
Expand Down
30 changes: 18 additions & 12 deletions packages/server/src/api/controllers/view/viewsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
RelationSchemaField,
ViewFieldMetadata,
CalculationType,
CountDistinctCalculationFieldMetadata,
CountCalculationFieldMetadata,
} from "@budibase/types"
import { builderSocket, gridSocket } from "../../../websockets"
import { helpers } from "@budibase/shared-core"
Expand All @@ -22,27 +24,31 @@ function stripUnknownFields(
if (helpers.views.isCalculationField(field)) {
if (field.calculationType === CalculationType.COUNT) {
if ("distinct" in field && field.distinct) {
return {
order: field.order,
width: field.width,
visible: field.visible,
readonly: field.readonly,
icon: field.icon,
distinct: field.distinct,
calculationType: field.calculationType,
field: field.field,
columns: field.columns,
}
const strippedField: RequiredKeys<CountDistinctCalculationFieldMetadata> =
{
order: field.order,
width: field.width,
visible: field.visible,
readonly: field.readonly,
icon: field.icon,
distinct: field.distinct,
calculationType: field.calculationType,
field: field.field,
columns: field.columns,
}
return strippedField
} else {
return {
const strippedField: RequiredKeys<CountCalculationFieldMetadata> = {
order: field.order,
width: field.width,
visible: field.visible,
readonly: field.readonly,
icon: field.icon,
calculationType: field.calculationType,
field: field.field,
columns: field.columns,
}
return strippedField
}
}
const strippedField: RequiredKeys<ViewCalculationFieldMetadata> = {
Expand Down
18 changes: 18 additions & 0 deletions packages/server/src/api/routes/tests/static.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,22 @@ describe("/static", () => {
expect(res.body.builderPreview).toBe(true)
})
})

describe("/", () => {
it("should move permanently from base call (public call)", async () => {
const res = await request.get(`/`)
expect(res.status).toEqual(301)
expect(res.text).toEqual(
`Redirecting to <a href="/builder">/builder</a>.`
)
})

it("should not error when trying to get 'apple-touch-icon.png' (public call)", async () => {
const res = await request.get(`/apple-touch-icon.png`)
expect(res.status).toEqual(302)
expect(res.text).toEqual(
`Redirecting to <a href="/builder/bblogo.png">/builder/bblogo.png</a>.`
)
})
})
})
Loading

0 comments on commit ee9a39a

Please sign in to comment.