Merge branch 'v3-ui' of github.com:budibase/budibase into feature/automation-branching-ux
This commit is contained in:
commit
d31275ee8c
|
@ -529,7 +529,7 @@ class InternalBuilder {
|
||||||
if (!matchesTableName) {
|
if (!matchesTableName) {
|
||||||
updatedKey = filterKey.replace(
|
updatedKey = filterKey.replace(
|
||||||
new RegExp(`^${relationship.column}.`),
|
new RegExp(`^${relationship.column}.`),
|
||||||
`${aliases![relationship.tableName]}.`
|
`${aliases?.[relationship.tableName] || relationship.tableName}.`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
updatedKey = filterKey
|
updatedKey = filterKey
|
||||||
|
@ -1579,7 +1579,7 @@ class InternalBuilder {
|
||||||
query = this.addFilters(query, filters, { relationship: true })
|
query = this.addFilters(query, filters, { relationship: true })
|
||||||
|
|
||||||
// handle relationships with a CTE for all others
|
// handle relationships with a CTE for all others
|
||||||
if (relationships?.length) {
|
if (relationships?.length && aggregations.length === 0) {
|
||||||
const mainTable =
|
const mainTable =
|
||||||
this.query.tableAliases?.[this.query.endpoint.entityId] ||
|
this.query.tableAliases?.[this.query.endpoint.entityId] ||
|
||||||
this.query.endpoint.entityId
|
this.query.endpoint.entityId
|
||||||
|
@ -1594,11 +1594,9 @@ class InternalBuilder {
|
||||||
// add JSON aggregations attached to the CTE
|
// add JSON aggregations attached to the CTE
|
||||||
return this.addJsonRelationships(cte, tableName, relationships)
|
return this.addJsonRelationships(cte, tableName, relationships)
|
||||||
}
|
}
|
||||||
// no relationships found - return query
|
|
||||||
else {
|
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
update(opts: QueryOptions): Knex.QueryBuilder {
|
update(opts: QueryOptions): Knex.QueryBuilder {
|
||||||
const { body, filters } = this.query
|
const { body, filters } = this.query
|
||||||
|
|
|
@ -554,7 +554,12 @@
|
||||||
cachedSettings = { ...allSettings }
|
cachedSettings = { ...allSettings }
|
||||||
initialSettings = cachedSettings
|
initialSettings = cachedSettings
|
||||||
} else {
|
} else {
|
||||||
Object.keys(allSettings).forEach(key => {
|
// We need to compare all keys from both the current and previous settings, as
|
||||||
|
// keys may have disappeared in the current set which would otherwise be ignored
|
||||||
|
// if we only checked the current set keys
|
||||||
|
const keys = new Set(Object.keys(allSettings))
|
||||||
|
Object.keys(cachedSettings).forEach(key => keys.add(key))
|
||||||
|
keys.forEach(key => {
|
||||||
const same = propsAreSame(allSettings[key], cachedSettings[key])
|
const same = propsAreSame(allSettings[key], cachedSettings[key])
|
||||||
if (!same) {
|
if (!same) {
|
||||||
// Updated cachedSettings (which is assigned by reference to
|
// Updated cachedSettings (which is assigned by reference to
|
||||||
|
|
|
@ -500,6 +500,10 @@ const rowActionHandler = async action => {
|
||||||
sourceId: resourceId,
|
sourceId: resourceId,
|
||||||
rowId,
|
rowId,
|
||||||
})
|
})
|
||||||
|
// Refresh related datasources
|
||||||
|
await dataSourceStore.actions.invalidateDataSource(resourceId, {
|
||||||
|
invalidateRelationships: true,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlerMap = {
|
const handlerMap = {
|
||||||
|
|
|
@ -682,7 +682,19 @@ export class ExternalRequest<T extends Operation> {
|
||||||
filters = this.prepareFilters(id, filters || {}, table)
|
filters = this.prepareFilters(id, filters || {}, table)
|
||||||
const relationships = buildExternalRelationships(table, this.tables)
|
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 =
|
const incRelationships =
|
||||||
|
aggregations.length === 0 &&
|
||||||
config.includeSqlRelationships === IncludeRelationship.INCLUDE
|
config.includeSqlRelationships === IncludeRelationship.INCLUDE
|
||||||
|
|
||||||
// clean up row on ingress using schema
|
// clean up row on ingress using schema
|
||||||
|
@ -709,17 +721,6 @@ export class ExternalRequest<T extends Operation> {
|
||||||
throw "Deletion must be filtered"
|
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 = {
|
let json: QueryJson = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
datasourceId: this.datasource._id!,
|
datasourceId: this.datasource._id!,
|
||||||
|
|
|
@ -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 () => {
|
it("should be able to filter rows on the view itself", async () => {
|
||||||
const table = await config.api.table.save(
|
const table = await config.api.table.save(
|
||||||
saveTableRequest({
|
saveTableRequest({
|
||||||
|
|
Loading…
Reference in New Issue