-
Notifications
You must be signed in to change notification settings - Fork 0
feat: #13 filter facets #65
Merged
+690
−51
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
466e27a
feat: #13 hasReviews filter and reviewed count
evenkkl 391f176
feat: #13 filter panel with facet counts
evenkkl f478298
docs: #13 describe filters, facet counts and AI usage
evenkkl 443daab
style: #13 format AI usage log
evenkkl 4eff9a8
Merge remote-tracking branch 'origin/main' into feat/13-filter-facets
evenkkl c1781ba
fix: #13 filter button on small screens
evenkkl 9e9b537
docs: #13 reconcile README with pagination
evenkkl 71bdddc
Merge remote-tracking branch 'origin/main' into feat/13-filter-facets
evenkkl 9639a76
fix: #13 keep selected filters in facets
evenkkl 6061a5a
feat: #13 filters dropdown on all screens
evenkkl 03064d7
test: #13 PostgreSQL tests for filters and facets
evenkkl ffaa0cf
docs: #13 clarify facet counts
evenkkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| .filter-panel h2 { | ||
| margin: 0 0 0.75rem; | ||
| font-size: 1.3rem; | ||
| letter-spacing: -0.025em; | ||
| } | ||
| .filter-panel fieldset { | ||
| border: 0; | ||
| border-top: 1px solid var(--border); | ||
| margin: 0; | ||
| padding: 0.75rem 0 1rem; | ||
| } | ||
| .filter-panel legend { | ||
| padding: 0; | ||
| font-size: 0.75rem; | ||
| font-weight: 700; | ||
| text-transform: uppercase; | ||
| letter-spacing: 0.1em; | ||
| color: var(--muted); | ||
| } | ||
| .filter-panel label { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| padding: 0.25rem 0; | ||
| } | ||
| .filter-count { | ||
| margin-left: auto; | ||
| font-size: 0.8rem; | ||
| color: var(--chip-text); | ||
| background: var(--chip-bg); | ||
| border-radius: 999px; | ||
| padding: 0 0.5rem; | ||
| } | ||
| .clear-filters { | ||
| background: var(--surface); | ||
| color: var(--text); | ||
| border: 1px solid var(--border-strong); | ||
| } | ||
| .filter-toggle { | ||
| display: none; | ||
| width: 100%; | ||
| background: var(--surface); | ||
| color: var(--text); | ||
| border: 1px solid var(--border-strong); | ||
| text-align: left; | ||
| } | ||
| @media (max-width: 700px) { | ||
| /* The button names the panel here, so the heading is kept for screen readers only. */ | ||
| .filter-panel h2 { | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| overflow: hidden; | ||
| clip-path: inset(50%); | ||
| white-space: nowrap; | ||
| } | ||
| .filter-toggle { | ||
| display: block; | ||
| } | ||
| .filter-options:not(.open) { | ||
| display: none; | ||
| } | ||
| .filter-options.open { | ||
| padding-top: 0.75rem; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { fireEvent, render, screen } from '@testing-library/react'; | ||
| import axe from 'axe-core'; | ||
| import FilterPanel from './FilterPanel.js'; | ||
|
|
||
| type Props = Parameters<typeof FilterPanel>[0]; | ||
|
|
||
| function renderPanel(over: Partial<Props> = {}) { | ||
| const props: Props = { | ||
| genres: [], | ||
| decades: [], | ||
| reviewed: false, | ||
| genreFacets: [ | ||
| { genre: { id: '4', name: 'Rock' }, count: 7 }, | ||
| { genre: { id: '2', name: 'Jazz' }, count: 0 }, | ||
| ], | ||
| decadeFacets: [ | ||
| { decade: 1970, count: 3 }, | ||
| { decade: 1990, count: 0 }, | ||
| ], | ||
| reviewedCount: 2, | ||
| onGenresChange: vi.fn(), | ||
| onDecadesChange: vi.fn(), | ||
| onReviewedChange: vi.fn(), | ||
| onClear: vi.fn(), | ||
| ...over, | ||
| }; | ||
| return { props, ...render(<FilterPanel {...props} />) }; | ||
| } | ||
|
|
||
| describe('FilterPanel', () => { | ||
| it('shows each option with its count', () => { | ||
| renderPanel(); | ||
| expect(screen.getByRole('checkbox', { name: 'Rock 7 albums' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('checkbox', { name: '1970s 3 albums' })).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole('checkbox', { name: 'Has reviews 2 albums' }), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('hides options that would return nothing', () => { | ||
| renderPanel({ reviewedCount: 0 }); | ||
| expect(screen.queryByRole('checkbox', { name: /Jazz/ })).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('checkbox', { name: /1990s/ })).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('group', { name: 'Reviews' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('keeps a selected option visible so it can be unticked', () => { | ||
| renderPanel({ decades: [1990] }); | ||
| expect(screen.getByRole('checkbox', { name: /1990s/ })).toBeChecked(); | ||
| }); | ||
|
|
||
| it('adds and removes values from the selection', () => { | ||
| const { props } = renderPanel({ genres: ['4'] }); | ||
| fireEvent.click(screen.getByRole('checkbox', { name: /Rock/ })); | ||
| expect(props.onGenresChange).toHaveBeenCalledWith([]); | ||
| fireEvent.click(screen.getByRole('checkbox', { name: /1970s/ })); | ||
| expect(props.onDecadesChange).toHaveBeenCalledWith([1970]); | ||
| fireEvent.click(screen.getByRole('checkbox', { name: /Has reviews/ })); | ||
| expect(props.onReviewedChange).toHaveBeenCalledWith(true); | ||
| }); | ||
|
|
||
| it('offers Clear filters only while a filter is active', () => { | ||
| renderPanel(); | ||
| expect(screen.queryByRole('button', { name: 'Clear filters' })).toBeNull(); | ||
| }); | ||
|
|
||
| it('clears every filter', () => { | ||
| const { props } = renderPanel({ reviewed: true }); | ||
| fireEvent.click(screen.getByRole('button', { name: 'Clear filters' })); | ||
| expect(props.onClear).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('toggles the options from the Filters button and counts active filters', () => { | ||
| renderPanel({ genres: ['4'], reviewed: true }); | ||
| const button = screen.getByRole('button', { name: 'Filters (2)' }); | ||
| expect(button).toHaveAttribute('aria-expanded', 'false'); | ||
| expect(button).toHaveAttribute('aria-controls', 'filter-options'); | ||
| fireEvent.click(button); | ||
| expect(button).toHaveAttribute('aria-expanded', 'true'); | ||
| }); | ||
|
|
||
| it('has no axe violations', async () => { | ||
| const { container } = renderPanel({ genres: ['4'] }); | ||
| const results = await axe.run(container, { | ||
| rules: { 'color-contrast': { enabled: false } }, | ||
| }); | ||
| expect(results.violations.map((violation) => violation.id)).toEqual([]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.