diff --git a/src/plugins/ui_core_views/filter_evaluation.ts b/src/plugins/ui_core_views/filter_evaluation.ts index a49312c616..e1c63bd64a 100644 --- a/src/plugins/ui_core_views/filter_evaluation.ts +++ b/src/plugins/ui_core_views/filter_evaluation.ts @@ -73,6 +73,9 @@ export class FilterEvaluationPlugin extends UIPlugin { case "CREATE_SHEET": this.filterValues[cmd.sheetId] = {}; break; + case "HIDE_COLUMNS_ROWS": + this.updateHiddenRows(); + break; case "UPDATE_FILTER": this.updateFilter(cmd); this.updateHiddenRows(); @@ -190,10 +193,15 @@ export class FilterEvaluationPlugin extends UIPlugin { private updateHiddenRows() { const sheetId = this.getters.getActiveSheetId(); - const filters = this.getters.getFilters(sheetId); + const filters = this.getters + .getFilters(sheetId) + .sort((filter1, filter2) => filter1.zoneWithHeaders.top - filter2.zoneWithHeaders.top); const hiddenRows = new Set(); for (let filter of filters) { + // Disable filters whose header are hidden + if (this.getters.isRowHiddenByUser(sheetId, filter.zoneWithHeaders.top)) continue; + if (hiddenRows.has(filter.zoneWithHeaders.top)) continue; const filteredValues = this.filterValues[sheetId]?.[filter.id]?.map(toLowerCase); if (!filteredValues || !filter.filteredZone) continue; for (let row = filter.filteredZone.top; row <= filter.filteredZone.bottom; row++) { diff --git a/tests/plugins/filters.test.ts b/tests/plugins/filters.test.ts index 059b46325d..3604d40777 100644 --- a/tests/plugins/filters.test.ts +++ b/tests/plugins/filters.test.ts @@ -10,6 +10,7 @@ import { deleteColumns, deleteFilter, deleteRows, + hideRows, insertCells, merge, paste, @@ -146,6 +147,29 @@ describe("Filters plugin", () => { expect(getFilterValues(model, sheetId)).toMatchObject([{ zone: "A1:A3", value: ["C"] }]); expect(getFilterValues(model, sheet2Id)).toMatchObject([{ zone: "A1:A3", value: ["D"] }]); }); + + test("Filter is disabled if its header row is hidden by the user", () => { + createFilter(model, "A1:A3"); + setCellContent(model, "A2", "28"); + updateFilter(model, "A1", ["28"]); + expect(model.getters.isRowHidden(sheetId, 1)).toBe(true); + + hideRows(model, [0]); + expect(model.getters.isRowHidden(sheetId, 1)).toBe(false); + }); + + test("Filter is disabled if its header row is hidden by another filter", () => { + createFilter(model, "A2:A3"); + setCellContent(model, "A3", "15"); + updateFilter(model, "A2", ["15"]); + expect(model.getters.isRowHidden(sheetId, 2)).toBe(true); + + createFilter(model, "B1:B2"); + setCellContent(model, "B2", "28"); + updateFilter(model, "B1", ["28"]); + expect(model.getters.isRowHidden(sheetId, 1)).toBe(true); + expect(model.getters.isRowHidden(sheetId, 2)).toBe(false); + }); }); describe("Filter Table Zone Expansion", () => {