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