diff --git a/src/plugins/core/filters.ts b/src/plugins/core/filters.ts index 0aa853e587..4153628dc7 100644 --- a/src/plugins/core/filters.ts +++ b/src/plugins/core/filters.ts @@ -99,7 +99,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 84f327d667..eca9ba20fc 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");