Skip to content

Commit

Permalink
Merge branch 'v3-ui' into ai-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shogunpurple authored Oct 31, 2024
2 parents 8478c3f + 20ed18a commit 3b31559
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 32 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
10 changes: 4 additions & 6 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 @@ -1579,7 +1579,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 +1594,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
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>.`
)
})
})
})
102 changes: 102 additions & 0 deletions packages/server/src/api/routes/tests/viewV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3659,6 +3659,108 @@ describe.each([
)
})

it("should be able to filter on relationships", async () => {
const companies = await config.api.table.save(
saveTableRequest({
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
},
})
)

const employees = await config.api.table.save(
saveTableRequest({
schema: {
age: {
type: FieldType.NUMBER,
name: "age",
},
name: {
type: FieldType.STRING,
name: "name",
},
company: {
type: FieldType.LINK,
name: "company",
tableId: companies._id!,
relationshipType: RelationshipType.ONE_TO_MANY,
fieldName: "company",
},
},
})
)

const view = await config.api.viewV2.create({
tableId: employees._id!,
name: generator.guid(),
type: ViewV2Type.CALCULATION,
queryUI: {
groups: [
{
filters: [
{
operator: BasicOperator.EQUAL,
field: "company.name",
value: "Aperture Science Laboratories",
},
],
},
],
},
schema: {
sum: {
visible: true,
calculationType: CalculationType.SUM,
field: "age",
},
},
})

const apertureScience = await config.api.row.save(
companies._id!,
{
name: "Aperture Science Laboratories",
}
)

const blackMesa = await config.api.row.save(companies._id!, {
name: "Black Mesa",
})

await Promise.all([
config.api.row.save(employees._id!, {
name: "Alice",
age: 25,
company: apertureScience._id,
}),
config.api.row.save(employees._id!, {
name: "Bob",
age: 30,
company: apertureScience._id,
}),
config.api.row.save(employees._id!, {
name: "Charly",
age: 27,
company: blackMesa._id,
}),
config.api.row.save(employees._id!, {
name: "Danny",
age: 15,
company: blackMesa._id,
}),
])

const { rows } = await config.api.viewV2.search(view.id, {
query: {},
})

expect(rows).toHaveLength(1)
expect(rows[0].sum).toEqual(55)
})

it("should be able to filter rows on the view itself", async () => {
const table = await config.api.table.save(
saveTableRequest({
Expand Down
8 changes: 5 additions & 3 deletions packages/server/src/sdk/app/applications/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export async function fetch(status: AppStatus, user: ContextUser) {
const all = status === AppStatus.ALL
let apps = (await dbCore.getAllApps({ dev, all })) as App[]

const enrichedUser = await groups.enrichUserRolesFromGroups({
// need to type this correctly - add roles back in to convert from ContextUser to User
const completeUser: User = {
...user,
roles: user.roles || {},
})
roles: user?.roles || {},
}
const enrichedUser = await groups.enrichUserRolesFromGroups(completeUser)
apps = filterAppList(enrichedUser, apps)

const appIds = apps
Expand Down
23 changes: 14 additions & 9 deletions packages/worker/src/api/controllers/global/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,21 @@ export const tenantUserLookup = async (ctx: any) => {
* So the account holder may not be found until further pagination has occurred
*/
export const accountHolderLookup = async (ctx: Ctx) => {
const users = await userSdk.core.getAllUsers()
const response = await userSdk.core.getExistingAccounts(
users.map(u => u.email)
)
const holder = response[0]
if (!holder) {
return
try {
const users = await userSdk.core.getAllUsers()
const response = await userSdk.core.getExistingAccounts(
users.map(u => u.email)
)
const holder = response[0]
if (!holder) {
ctx.body = null
return
}
holder._id = users.find(u => u.email === holder.email)?._id
ctx.body = holder
} catch (e) {
ctx.body = null
}
holder._id = users.find(u => u.email === holder.email)?._id
ctx.body = holder
}

/*
Expand Down

0 comments on commit 3b31559

Please sign in to comment.