Skip to content

Commit

Permalink
[FIX] Filters: fix filter id on sheet duplication
Browse files Browse the repository at this point in the history
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#2632

Task: 3384840
X-original-commit: 4a28f6ea01ab5dc2a0fd21a0fd62271ca277ca92
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
Topdev97 committed Jun 26, 2023
1 parent e113f94 commit 670b148
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugins/core/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ export class FiltersPlugin extends CorePlugin<FiltersState> 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<FilterTableId, FilterTable | undefined> = {};
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);
Expand Down
16 changes: 16 additions & 0 deletions tests/plugins/filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 670b148

Please sign in to comment.