diff --git a/frontend/src/components/Gallery/GalleryToolbar.test.ts b/frontend/src/components/Gallery/GalleryToolbar.test.ts index fbc55c539..10389caab 100644 --- a/frontend/src/components/Gallery/GalleryToolbar.test.ts +++ b/frontend/src/components/Gallery/GalleryToolbar.test.ts @@ -227,3 +227,47 @@ describe("GalleryToolbar sort axis", () => { wrapper.unmount(); }); }); + +describe("GalleryToolbar group-by control", () => { + const MANY_MODES = [ + { id: "none", icon: "mdi-view-agenda-outline", title: "Flat view" }, + { + id: "letter", + icon: "mdi-alphabetical-variant", + title: "Group by letter", + }, + { id: "family", icon: "mdi-family-tree", title: "Group by family" }, + ]; + + it("keeps the segmented slider for the default two modes", () => { + const wrapper = mountToolbar({}, RMenuPassthrough); + + expect( + wrapper + .findAllComponents({ name: "RSegmentedControl" }) + .some((c) => c.props("items")?.length === 2), + ).toBe(true); + wrapper.unmount(); + }); + + it("lists more than two modes in a labelled menu with the active one checked", () => { + const wrapper = mountToolbar( + { groupBy: "family", groupByItems: MANY_MODES }, + RMenuPassthrough, + ); + + expect( + wrapper + .findAllComponents({ name: "RSegmentedControl" }) + .some((c) => c.props("items") === MANY_MODES), + ).toBe(false); + const family = wrapper + .findAllComponents({ name: "RMenuItem" }) + .filter((item) => item.props("label") === "Group by family"); + expect(family.length).toBeGreaterThan(0); + expect(family.some((item) => item.props("variant") === "active")).toBe( + true, + ); + wrapper.unmount(); + }); +}); diff --git a/frontend/src/components/Gallery/GalleryToolbar.vue b/frontend/src/components/Gallery/GalleryToolbar.vue index f974c7c47..825497a24 100644 --- a/frontend/src/components/Gallery/GalleryToolbar.vue +++ b/frontend/src/components/Gallery/GalleryToolbar.vue @@ -228,6 +228,14 @@ const autofocusSearchField = computed( shouldAutofocusSearch(), ); +// Two modes fit a segmented slider; more read better as a labelled menu. +const groupByAsMenu = computed(() => effectiveGroupByItems.value.length > 2); +const activeGroupByIcon = computed( + () => + effectiveGroupByItems.value.find((i) => i.id === groupByValue.value) + ?.icon ?? "mdi-format-list-group", +); + function setGroupBy(value: GroupByMode) { emit("update:groupBy", value); } @@ -335,13 +343,37 @@ const { smAndUp } = useBreakpoint();