only fire view updated events when 2 or more groups are applied
This commit is contained in:
parent
b6fcdf301d
commit
e5453cc766
|
@ -167,17 +167,13 @@ export async function create(ctx: Ctx<CreateViewRequest, CreateViewResponse>) {
|
||||||
async function handleViewFilterEvents(existingView: ViewV2, view: ViewV2) {
|
async function handleViewFilterEvents(existingView: ViewV2, view: ViewV2) {
|
||||||
const filterGroups = view.queryUI?.groups?.length || 0
|
const filterGroups = view.queryUI?.groups?.length || 0
|
||||||
const properties = { filterGroups, tableId: view.tableId }
|
const properties = { filterGroups, tableId: view.tableId }
|
||||||
if (!existingView?.queryUI) {
|
|
||||||
await events.view.filterCreated(properties)
|
|
||||||
} else {
|
|
||||||
if (
|
if (
|
||||||
filterGroups >
|
filterGroups >= 2 &&
|
||||||
((existingView && existingView?.queryUI?.groups?.length) || 0)
|
((existingView && existingView?.queryUI?.groups?.length) || 0)
|
||||||
) {
|
) {
|
||||||
await events.view.filterUpdated(properties)
|
await events.view.filterUpdated(properties)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function handleViewEvents(existingView: ViewV2, view: ViewV2) {
|
async function handleViewEvents(existingView: ViewV2, view: ViewV2) {
|
||||||
// Grouped filters
|
// Grouped filters
|
||||||
|
|
|
@ -997,6 +997,45 @@ if (descriptions.length) {
|
||||||
expect(events.view.updated).toHaveBeenCalledTimes(1)
|
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 () => {
|
it("can update all fields", async () => {
|
||||||
const tableId = table._id!
|
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)
|
updatedView = await config.api.viewV2.get(view.id)
|
||||||
expected = {
|
expected = {
|
||||||
onEmptyFilter: EmptyFilterOption.RETURN_ALL,
|
onEmptyFilter: EmptyFilterOption.RETURN_ALL,
|
||||||
|
|
Loading…
Reference in New Issue