Skip to content

Commit

Permalink
[FIX] FilterEvaluationPlugin: insert/remove rows on data filter header
Browse files Browse the repository at this point in the history
This commit addresses two issues in the FilterEvaluationPlugin:

1. Previously, when inserting a row above or below a data filter header, hidden
rows inside the data filter were not being updated, causing a state inconsistency
issue. This commit ensures that hidden rows inside the data filter header are
correctly updated when rows are inserted above or below the header.

2. Another issue occurred when removing a row above the data filter header while
certain rows were filtered. This led to a mismatch in the data filter state,
revealing hidden rows. This commit fixes this problem by updating the handling
of hidden rows inside the data filter header during row removal.

Task: 3546012
X-original-commit: 841da08
Part-of: #3159
  • Loading branch information
dhrp-odoo committed Nov 16, 2023
1 parent 389a6eb commit 6283dae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugins/ui_core_views/filter_evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class FilterEvaluationPlugin extends UIPlugin {
case "EVALUATE_CELLS":
case "ACTIVATE_SHEET":
case "REMOVE_FILTER_TABLE":
case "ADD_COLUMNS_ROWS":
case "REMOVE_COLUMNS_ROWS":
this.isEvaluationDirty = true;
break;
case "START":
Expand Down
37 changes: 37 additions & 0 deletions tests/plugins/filter_evaluation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Model } from "../../src";
import { toZone } from "../../src/helpers";
import { UID } from "../../src/types";
import {
addRows,
createFilter,
deleteFilter,
deleteRows,
hideColumns,
hideRows,
setBorder,
Expand Down Expand Up @@ -164,4 +166,39 @@ describe("Filter Evaluation Plugin", () => {
});
expect(model.getters.getFilter({ sheetId: "sh2", col: 0, row: 0 })).toBeTruthy();
});

test("Inserting rows above or below the data filter header updates the filtered rows", () => {
const model = new Model();

createFilter(model, "A1:A2");
setCellContent(model, "A2", "Hi");

updateFilter(model, "A1", ["Hi"]);
expect(model.getters.isRowFiltered(sheetId, 1)).toEqual(true);

addRows(model, "before", 0, 1);
expect(model.getters.isRowFiltered(sheetId, 1)).toEqual(false);
expect(model.getters.isRowFiltered(sheetId, 2)).toEqual(true);

addRows(model, "after", 1, 1);
expect(model.getters.isRowFiltered(sheetId, 2)).toEqual(false);
expect(model.getters.isRowFiltered(sheetId, 3)).toEqual(true);
});

test("Removing rows above the data filter header updates the filtered rows", () => {
const model = new Model();

createFilter(model, "A4:A6");
setCellContent(model, "A5", "Hi");
setCellContent(model, "A6", "Hi");

updateFilter(model, "A4", ["Hi"]);
expect(model.getters.isRowFiltered(sheetId, 4)).toEqual(true);
expect(model.getters.isRowFiltered(sheetId, 5)).toEqual(true);

deleteRows(model, [0, 1, 2]);

expect(model.getters.isRowFiltered(sheetId, 1)).toEqual(true);
expect(model.getters.isRowFiltered(sheetId, 2)).toEqual(true);
});
});

0 comments on commit 6283dae

Please sign in to comment.