fix(app): filters toggle layout, constant spacing, one active-count helper
This commit is contained in:
1 parent
c25a994c0e
commit
7a129dc763
3 files changed
+25
-8
No files matched your search
@@ -44,3 +44,8 @@ export function filterSheets(
|
||||
sheet.latest_round?.status === filters.roundStatus),
|
||||
)
|
||||
}
|
||||
|
||||
/** How many of the four filters are not empty. */
|
||||
export function activeFilterCount(filters: SheetFilters): number {
|
||||
return Object.values(filters).filter(Boolean).length
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
ROUND_STATUSES,
|
||||
SHEET_STATUSES,
|
||||
VERSION_STATUSES,
|
||||
activeFilterCount,
|
||||
filterSheets,
|
||||
type SheetFilters,
|
||||
} from '@/admin/filters'
|
||||
@@ -307,7 +308,7 @@ const FILTERS_PANEL_ID = 'admin-sheets-filters'
|
||||
/** Phone only: « Filtres » or « Filtres (n) », n the filters that are not empty. */
|
||||
function FiltersToggle({ view }: { view: ListView }) {
|
||||
const t = useT()
|
||||
const active = Object.values(view.filters).filter(Boolean).length
|
||||
const active = activeFilterCount(view.filters)
|
||||
return (
|
||||
<Button
|
||||
ref={view.toggleRef}
|
||||
@@ -318,9 +319,11 @@ function FiltersToggle({ view }: { view: ListView }) {
|
||||
onClick={() => view.setOpen((o) => !o)}
|
||||
className="min-h-11 w-full justify-between sm:hidden"
|
||||
>
|
||||
{active === 0
|
||||
? t('admin.sheets.filters')
|
||||
: t('admin.sheets.filters_active').replace('{count}', String(active))}
|
||||
<span className="flex-1 text-left">
|
||||
{active === 0
|
||||
? t('admin.sheets.filters')
|
||||
: t('admin.sheets.filters_active').replace('{count}', String(active))}
|
||||
</span>
|
||||
<Icon
|
||||
name="chevron-down"
|
||||
size={16}
|
||||
@@ -336,7 +339,7 @@ function FiltersToggle({ view }: { view: ListView }) {
|
||||
/** Phone only, inside the panel, while at least one filter is not empty. */
|
||||
function ResetFilters({ view }: { view: ListView }) {
|
||||
const t = useT()
|
||||
if (!Object.values(view.filters).some(Boolean)) return null
|
||||
if (activeFilterCount(view.filters) === 0) return null
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
@@ -363,7 +366,7 @@ const PANEL =
|
||||
function Filters(props: ResultsProps) {
|
||||
const { view } = props
|
||||
const state = view.open
|
||||
? 'max-sm:mt-3 max-sm:grid-rows-[1fr]'
|
||||
? 'max-sm:grid-rows-[1fr]'
|
||||
: 'max-sm:grid-rows-[0fr] max-sm:invisible'
|
||||
return (
|
||||
<div>
|
||||
@@ -373,7 +376,7 @@ function Filters(props: ResultsProps) {
|
||||
data-open={view.open}
|
||||
className={`${PANEL} ${state}`}
|
||||
>
|
||||
<div className="-m-1 min-h-0 overflow-hidden p-1 sm:overflow-visible">
|
||||
<div className="-m-1 min-h-0 overflow-hidden p-1 max-sm:pt-4 sm:overflow-visible">
|
||||
<FilterGrid {...props} />
|
||||
<ResetFilters view={view} />
|
||||
</div>
|
||||
@@ -457,7 +460,7 @@ function Results({ sheets, species, view }: ResultsProps) {
|
||||
const t = useT()
|
||||
const shown = useShownSheets(sheets, view)
|
||||
if (sheets.length === 0) return <EmptyLine text={t('admin.sheets.empty')} />
|
||||
const filtering = Object.values(view.filters).some(Boolean)
|
||||
const filtering = activeFilterCount(view.filters) > 0
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<CountLine shown={shown.length} total={sheets.length} />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { OfficialSheetAdminSummary } from '@faunosteo/supabase'
|
||||
import { NO_FILTER, activeFilterCount } from '@/admin/filters'
|
||||
import { searchSheets, sortSheets } from '@/admin/sheetList'
|
||||
|
||||
const sheet = (id: string, fr: string, en: string, at: string) =>
|
||||
@@ -42,3 +43,11 @@ describe('sortSheets', () => {
|
||||
expect(ids(input)).toBe('za')
|
||||
})
|
||||
})
|
||||
|
||||
describe('activeFilterCount', () => {
|
||||
it('counts the filters that are not empty', () => {
|
||||
expect(activeFilterCount(NO_FILTER)).toBe(0)
|
||||
const two = { ...NO_FILTER, species: 'equine', roundStatus: 'open' }
|
||||
expect(activeFilterCount(two)).toBe(2)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user