only fire view updated events when 2 or more groups are applied
This commit is contained in:
parent
b6fcdf301d
commit
e5453cc766
|
@ -167,16 +167,12 @@ export async function create(ctx: Ctx<CreateViewRequest, CreateViewResponse>) {
|
|||
async function handleViewFilterEvents(existingView: ViewV2, view: ViewV2) {
|
||||
const filterGroups = view.queryUI?.groups?.length || 0
|
||||
const properties = { filterGroups, tableId: view.tableId }
|
||||
if (!existingView?.queryUI) {
|
||||
await events.view.filterCreated(properties)
|
||||
} else {
|
||||
if (
|
||||
filterGroups >
|
||||
filterGroups >= 2 &&
|
||||
((existingView && existingView?.queryUI?.groups?.length) || 0)
|
||||
) {
|
||||
await events.view.filterUpdated(properties)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleViewEvents(existingView: ViewV2, view: ViewV2) {
|
||||
|
|
|
@ -997,6 +997,45 @@ if (descriptions.length) {
|
|||
expect(events.view.updated).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("handles view grouped filter events", async () => {
|
||||
view.queryUI = {
|
||||
logicalOperator: UILogicalOperator.ALL,
|
||||
onEmptyFilter: EmptyFilterOption.RETURN_ALL,
|
||||
groups: [
|
||||
{
|
||||
logicalOperator: UILogicalOperator.ALL,
|
||||
filters: [
|
||||
{
|
||||
operator: BasicOperator.EQUAL,
|
||||
field: "newField",
|
||||
value: "newValue",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
await config.api.viewV2.update(view)
|
||||
expect(events.view.filterUpdated).not.toHaveBeenCalled()
|
||||
|
||||
// @ts-ignore
|
||||
view.queryUI.groups.push({
|
||||
logicalOperator: UILogicalOperator.ALL,
|
||||
filters: [
|
||||
{
|
||||
operator: BasicOperator.EQUAL,
|
||||
field: "otherField",
|
||||
value: "otherValue",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await config.api.viewV2.update(view)
|
||||
expect(events.view.filterUpdated).toHaveBeenCalledWith({
|
||||
filterGroups: 2,
|
||||
tableId: view.tableId,
|
||||
})
|
||||
})
|
||||
|
||||
it("can update all fields", async () => {
|
||||
const tableId = table._id!
|
||||
|
||||
|
@ -1360,8 +1399,6 @@ if (descriptions.length) {
|
|||
},
|
||||
})
|
||||
|
||||
expect(events.view.filterCreated).toHaveBeenCalledTimes(1)
|
||||
|
||||
updatedView = await config.api.viewV2.get(view.id)
|
||||
expected = {
|
||||
onEmptyFilter: EmptyFilterOption.RETURN_ALL,
|
||||
|
|
Loading…
Reference in New Issue