From 464696ce92c83c70b1475193466639db2f35d739 Mon Sep 17 00:00:00 2001 From: dhrp-odoo Date: Mon, 16 Oct 2023 14:12:40 +0530 Subject: [PATCH] [FIX] FiltersPlugin: removing row with data filter header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, removing rows that included the filter header failed to remove the associated data filter tables. This commit addresses the issue by ensuring the data filter tables is also removed when rows with the filter header are deleted. closes odoo/o-spreadsheet#3159 Task: 3546012 X-original-commit: d15825de4de3591839306cd5bfc253b2dd4ed9ce Signed-off-by: RĂ©mi Rahir (rar) Signed-off-by: Dhrutik Patel (dhrp) --- src/plugins/core/filters.ts | 8 ++++++++ tests/plugins/filters.test.ts | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/plugins/core/filters.ts b/src/plugins/core/filters.ts index 9c7adb1de..9a180f9a3 100644 --- a/src/plugins/core/filters.ts +++ b/src/plugins/core/filters.ts @@ -224,6 +224,14 @@ export class FiltersPlugin extends CorePlugin implements FiltersSt private onDeleteColumnsRows(cmd: RemoveColumnsRowsCommand) { for (const table of this.getFilterTables(cmd.sheetId)) { + // Remove the filter tables whose data filter headers are in the removed rows. + if (cmd.dimension === "ROW" && cmd.elements.includes(table.zone.top)) { + const tables = { ...this.tables[cmd.sheetId] }; + delete tables[table.id]; + this.history.update("tables", cmd.sheetId, tables); + continue; + } + const zone = reduceZoneOnDeletion( table.zone, cmd.dimension === "COL" ? "left" : "top", diff --git a/tests/plugins/filters.test.ts b/tests/plugins/filters.test.ts index c2693da4e..041293f50 100644 --- a/tests/plugins/filters.test.ts +++ b/tests/plugins/filters.test.ts @@ -492,15 +492,9 @@ describe("Filters plugin", () => { ]); }); - test("On the left part of the zone", () => { + test("Removing rows with filter table should remove the filter table", () => { deleteRows(model, [2]); - expect(model.getters.getFilterTables(sheetId)[0].zone).toEqual(toZone("C3:F5")); - expect(getFilterValues(model)).toEqual([ - { zone: "C3:C5", value: ["C"] }, - { zone: "D3:D5", value: ["D"] }, - { zone: "E3:E5", value: ["E"] }, - { zone: "F3:F5", value: ["F"] }, - ]); + expect(model.getters.getFilterTables(sheetId)).toEqual([]); }); test("Inside the zone", () => {