From b90a16207c250c7a109b3c8a36a1e94d5cb0eac0 Mon Sep 17 00:00:00 2001 From: "Rmi Rahir (rar)" Date: Mon, 26 Jun 2023 09:33:26 +0000 Subject: [PATCH] [FIX] Filters: fix filter id on sheet duplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The internal state of the filter plugin requires that the id in the table mapping matches the id of the related FilterTable object. closes odoo/o-spreadsheet#2635 Task: 3384840 X-original-commit: 4a28f6ea01ab5dc2a0fd21a0fd62271ca277ca92 Signed-off-by: Lucas Lefèvre (lul) --- src/plugins/core/filters.ts | 9 ++++++++- tests/plugins/filters.test.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plugins/core/filters.ts b/src/plugins/core/filters.ts index 5e35ef3f6..7f691c8b8 100644 --- a/src/plugins/core/filters.ts +++ b/src/plugins/core/filters.ts @@ -103,7 +103,14 @@ export class FiltersPlugin extends CorePlugin implements FiltersSt this.history.update("tables", filterTables); break; case "DUPLICATE_SHEET": - this.history.update("tables", cmd.sheetIdTo, deepCopy(this.tables[cmd.sheetId])); + const tables: Record = {}; + for (const filterTable of Object.values(this.tables[cmd.sheetId] || {})) { + if (filterTable) { + const newFilterTable = deepCopy(filterTable); + tables[newFilterTable.id] = newFilterTable; + } + } + this.history.update("tables", cmd.sheetIdTo, tables); break; case "ADD_COLUMNS_ROWS": this.onAddColumnsRows(cmd); diff --git a/tests/plugins/filters.test.ts b/tests/plugins/filters.test.ts index 3604d4077..925f27939 100644 --- a/tests/plugins/filters.test.ts +++ b/tests/plugins/filters.test.ts @@ -148,6 +148,22 @@ describe("Filters plugin", () => { expect(getFilterValues(model, sheet2Id)).toMatchObject([{ zone: "A1:A3", value: ["D"] }]); }); + test("Can delete row/columns on duplicated sheet with filters", () => { + createFilter(model, "B1:B3"); + updateFilter(model, "B1", ["C"]); + + const sheet2Id = "42"; + model.dispatch("DUPLICATE_SHEET", { + sheetId: sheetId, + sheetIdTo: sheet2Id, + }); + expect(getFilterValues(model, sheet2Id)).toMatchObject([{ zone: "B1:B3", value: ["C"] }]); + deleteColumns(model, ["A"], sheet2Id); + + expect(getFilterValues(model, sheetId)).toMatchObject([{ zone: "B1:B3", value: ["C"] }]); + expect(getFilterValues(model, sheet2Id)).toMatchObject([{ zone: "A1:A3", value: ["C"] }]); + }); + test("Filter is disabled if its header row is hidden by the user", () => { createFilter(model, "A1:A3"); setCellContent(model, "A2", "28");