Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('WorkshopFilterMenu', () => {
it('closes on Escape from inside the filter panel and restores trigger focus', async () => {
const user = userEvent.setup()
mountMenu()
const trigger = screen.getByRole('button', { name: 'Filter' })
const trigger = screen.getByRole('button', { name: 'Use cases' })
await user.click(trigger)
const dialog = await screen.findByRole('dialog')
const useCase = within(dialog).getByRole('button', {
Expand Down
13 changes: 9 additions & 4 deletions apps/website/src/components/workshop/WorkshopFilterMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useVisualViewport } from '../../composables/useVisualViewport'
import type { UseCase } from '../../config/models-catalogue'
import type { Locale } from '../../i18n/translations'
import { t } from '../../i18n/translations'
import { filterLabel } from '../../lib/workshop/filter-label'
import type { FacetSheetGroup } from './FacetSheet.vue'
import FacetSheet from './FacetSheet.vue'

Expand Down Expand Up @@ -72,6 +73,10 @@ const selectedCount = computed(() =>
groups.value.reduce((total, group) => total + group.selected.length, 0)
)

const label = computed(() =>
filterLabel(groups.value, t('workshop.filter.label', locale))
)

function toggle(_facet: string, value: string) {
const useCase = useCaseOptions.find((option) => option.value === value)?.value
if (!useCase) return
Expand All @@ -85,7 +90,7 @@ function clearAll() {
}

const sheetLabels = computed(() => ({
title: t('workshop.filter.label', locale),
title: label.value,
search: t('workshop.filter.search', locale),
noMatches: t('workshop.filter.noMatches', locale),
applied: t('workshop.filter.applied', locale),
Expand All @@ -103,7 +108,7 @@ const sheetLabels = computed(() => ({
type="button"
data-testid="workshop-filter"
:aria-expanded="open"
:aria-label="t('workshop.filter.label', locale)"
:aria-label="label"
:class="
cn(
'relative inline-flex h-11 cursor-pointer items-center gap-2 rounded-2xl bg-transparency-white-t4 px-4 text-sm font-medium transition-colors outline-none hover:bg-transparency-white-t8 focus-visible:ring-3 focus-visible:ring-primary-comfy-yellow/50 max-sm:size-10 max-sm:justify-center max-sm:rounded-xl max-sm:bg-white/8 max-sm:px-0',
Expand All @@ -116,7 +121,7 @@ const sheetLabels = computed(() => ({
>
<ListFilter class="size-4 shrink-0" aria-hidden="true" />
<span class="max-sm:hidden">
{{ t('workshop.filter.label', locale) }}
{{ label }}
</span>
<span
v-if="selectedCount"
Expand Down Expand Up @@ -153,7 +158,7 @@ const sheetLabels = computed(() => ({
<div
ref="panel"
role="dialog"
:aria-label="t('workshop.filter.label', locale)"
:aria-label="label"
:aria-modal="isPhone || undefined"
data-testid="workshop-filter-menu"
:style="{
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/workshop/WorkshopModelCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<template>
<a
:href="model.href"

Check warning on line 47 in apps/website/src/components/workshop/WorkshopModelCard.vue

View workflow job for this annotation

GitHub Actions / fallow

High cognitive complexity (moderate)

Function '<template>' is hard to understand (cognitive: 19, threshold: 15). • Severity: moderate • Cyclomatic: 17 • Cognitive: 19 • Lines: 201 High cognitive complexity means deeply nested or interleaved logic. Consider flattening control flow or extracting helper functions.
class="group flex cursor-pointer flex-col gap-4 overflow-hidden rounded-4xl bg-hub-surface px-2 pt-2 pb-4 transition-colors duration-200 hover:bg-hub-surface-hover"
data-testid="workshop-model-card"
>
Expand Down Expand Up @@ -146,7 +146,7 @@
</span>
</div>

<div class="flex flex-col gap-2 px-3">
<div class="flex flex-col gap-3 px-3">
<div class="flex min-w-0 items-center gap-2 text-content-secondary">
<!-- With the mark over the thumbnail, repeating it here would say the
same thing twice. -->
Expand Down
12 changes: 6 additions & 6 deletions apps/website/src/components/workshop/WorkshopModelsGrid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ describe('WorkshopModelsGrid', () => {
const user = userEvent.setup()
render(WorkshopModelsGrid, { props: { models } })

await user.click(screen.getByRole('button', { name: 'Filter' }))
const dialog = await screen.findByRole('dialog', { name: 'Filter' })
await user.click(screen.getByRole('button', { name: 'Use cases' }))
const dialog = await screen.findByRole('dialog', { name: 'Use cases' })
await user.click(
within(dialog).getByRole('button', { name: 'Edit images 1' })
)
Expand All @@ -148,8 +148,8 @@ describe('WorkshopModelsGrid', () => {
render(WorkshopModelsGrid, { props: { models } })

await user.click(screen.getByRole('button', { name: 'Edit images' }))
await user.click(screen.getByRole('button', { name: 'Filter' }))
const dialog = await screen.findByRole('dialog', { name: 'Filter' })
await user.click(screen.getByRole('button', { name: 'Use cases' }))
const dialog = await screen.findByRole('dialog', { name: 'Use cases' })
await user.click(
within(dialog).getByRole('button', { name: 'Generate videos 1' })
)
Expand All @@ -161,8 +161,8 @@ describe('WorkshopModelsGrid', () => {
const user = userEvent.setup()
render(WorkshopModelsGrid, { props: { models } })

await user.click(screen.getByRole('button', { name: 'Filter' }))
const dialog = await screen.findByRole('dialog', { name: 'Filter' })
await user.click(screen.getByRole('button', { name: 'Use cases' }))
const dialog = await screen.findByRole('dialog', { name: 'Use cases' })
await user.type(
within(dialog).getByRole('searchbox', { name: 'Search…' }),
'video'
Expand Down
22 changes: 22 additions & 0 deletions apps/website/src/lib/workshop/filter-label.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest'

import { filterLabel } from './filter-label'

describe('filterLabel', () => {
it.for([
['the group itself when it is the only one', ['Use cases'], 'Use cases'],
[
'the generic name once a second group exists',
['Use cases', 'Output'],
'Filter'
],
['the generic name when there is nothing to filter by', [], 'Filter']
] as const)('names it after %s', ([, labels, expected]) => {
expect(
filterLabel(
labels.map((label) => ({ label })),
'Filter'
)
).toBe(expected)
})
})
13 changes: 13 additions & 0 deletions apps/website/src/lib/workshop/filter-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* What to call a filter control.
*
* A sheet with one group hides that group's name, so the control is the only
* place a reader can learn what the filter narrows. With more than one there is
* no single answer, and the generic name is the honest one.
*/
export function filterLabel(
groups: readonly { readonly label: string }[],
generic: string
): string {
return groups.length === 1 ? groups[0].label : generic
}
Loading