Skip to content

Commit

Permalink
[IMP] filter: allow to sort in readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLefevre committed Oct 22, 2024
1 parent 3e6858a commit 9a6f212
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/filters/filter_menu/filter_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class FilterMenu extends Component<Props, SpreadsheetChildEnv> {
this.table.range.sheetId,
this.table.range.zone
);
return !this.env.model.getters.isReadonly() && coreTable?.type !== "dynamic";
return coreTable?.type !== "dynamic";
}

private getFilterHiddenValues(position: Position): Value[] {
Expand Down
2 changes: 2 additions & 0 deletions src/types/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export const readonlyAllowedCommands = new Set<CommandTypes>([
// allow to check checkboxes, select dropdowns, use filters
"UPDATE_CELL",

"SORT_CELLS",

"COPY",

"RESIZE_SHEETVIEW",
Expand Down
34 changes: 21 additions & 13 deletions tests/table/filter_menu_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,27 @@ describe("Filter menu component", () => {
});
});

test("cannot sort filter table in readonly mode", async () => {
createTableWithFilter(model, "A10:B15");
await nextTick();
await openFilterMenu();
expect(
[...fixture.querySelectorAll(".o-filter-menu-item")].map((el) => el.textContent?.trim())
).toEqual(["Sort ascending (A ⟶ Z)", "Sort descending (Z ⟶ A)", "✓(Blanks)"]);
model.updateMode("readonly");
await nextTick();
expect(
[...fixture.querySelectorAll(".o-filter-menu-item")].map((el) => el.textContent?.trim())
).toEqual(["✓(Blanks)"]);
});
test.each(["readonly", "dashboard"] as const)(
"can sort filter table in %s mode",
async (mode) => {
createTableWithFilter(model, "A10:A13");
setCellContent(model, "A10", "letters");
setCellContent(model, "A11", "A");
setCellContent(model, "A12", "B");
setCellContent(model, "A13", "C");
model.updateMode(mode);
await nextTick();
await openFilterMenu();
await simulateClick(".o-filter-menu-item:nth-of-type(2)");
await nextTick();
expect(getCellsObject(model, sheetId)).toMatchObject({
A10: { content: "letters" },
A11: { content: "C" },
A12: { content: "B" },
A13: { content: "A" },
});
}
);

test("cannot sort dynamic table", async () => {
setCellContent(model, "A10", "=MUNIT(2)");
Expand Down

0 comments on commit 9a6f212

Please sign in to comment.