Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Filters: fix filter id on sheet duplication #2631

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/plugins/core/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah putain, deepCopy doesn't deep copy... 🤦‍♂️

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