- stateDeputyListUrl.ts / stateDeputyListFilters.ts: contrato de URL/filtro próprio (sort/dir, filtro de Partido multi + sentinela "Sem partido"), espelhando municipalityListUrl.ts (paginação/resolveListUrl) e territoryListUrl.ts (sort keys/labels) - stateDeputyData.ts: where/sort resolvidos no banco + facet de partido (loadStateDeputyPartyFacet), select estreito na query principal - StateDeputySortableHead / StateDeputyHeaderFilter / StateDeputyFilters: wrappers finos sobre o chrome compartilhado (shared/CampaignSortableHead, CampaignHeaderFilterPopover), paridade mobile incluída - dobradinhas/page.tsx: redirect canônico em duas fases, CampaignTable sempre montada com caption + empty state, resumo de ordenação aria-live - Correção pós-entrega (design review): "Sem partido" no mobile + caption da tabela + copy plural do empty state - /simplify (1ª rodada): buildStateDeputyPartyOptions compartilhado, remove discriminante filterParam redundante, dedupe/if mortos em stateDeputyListUrl.ts - /simplify (2ª rodada, pós-rebase): remove cast/type morto em stateDeputyData.ts, stateDeputyColumns usa StateDeputyFilterOption em vez de duplicar a forma, inlinea parsePartiesParam; extrai truncatedNamesLabel compartilhado em campaignListUrl.ts (3º call site — municipalityListFilters e territoryListFilters tinham a mesma função com nomes distintos) Gate verde (tsc, lint, format, check:cycles, 396 testes, build); Aikido 0 achados nos 7 arquivos tocados nesta rodada. Docs: docs/plans/ordenacao-filtros-lista-dobradinhas.md, docs/roadmap.md, .cursor/rules/projects/nucleos-eleitorais.mdc.
65 lines
2 KiB
TypeScript
65 lines
2 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
|
|
import { CampaignSortableHead } from '@/components/campaign/shared/CampaignSortableHead'
|
|
import { StateDeputyHeaderFilter } from '@/components/campaign/stateDeputy/StateDeputyHeaderFilter'
|
|
import type { StateDeputyFilterOption } from '@/utilities/stateDeputyListFilters'
|
|
import {
|
|
buildStateDeputySortHref,
|
|
defaultStateDeputyListSortDir,
|
|
resolveStateDeputyListSort,
|
|
stateDeputyListSortLabels,
|
|
type StateDeputyListSortKey,
|
|
type StateDeputyListState,
|
|
} from '@/utilities/stateDeputyListUrl'
|
|
|
|
type StateDeputySortableHeadProps = {
|
|
state: StateDeputyListState
|
|
sortKey: StateDeputyListSortKey
|
|
children?: ReactNode
|
|
align?: 'left' | 'center' | 'right'
|
|
className?: string
|
|
} &
|
|
// Only one filterable column exists (Partido) — presence of `filterOptions`
|
|
// is the discriminant, unlike Territory's region|coverage `filterParam`.
|
|
(| { filterOptions: StateDeputyFilterOption[]; hasNoPartyOption: boolean }
|
|
| { filterOptions?: undefined; hasNoPartyOption?: undefined }
|
|
)
|
|
|
|
export const StateDeputySortableHead = ({
|
|
state,
|
|
sortKey,
|
|
children,
|
|
align = 'left',
|
|
className,
|
|
filterOptions,
|
|
hasNoPartyOption,
|
|
}: StateDeputySortableHeadProps) => {
|
|
const { sort: activeSort, dir } = resolveStateDeputyListSort(state)
|
|
const active = activeSort === sortKey
|
|
const nextDir = active ? (dir === 'asc' ? 'desc' : 'asc') : defaultStateDeputyListSortDir()
|
|
|
|
return (
|
|
<CampaignSortableHead
|
|
active={active}
|
|
align={align}
|
|
className={className}
|
|
dir={dir}
|
|
href={buildStateDeputySortHref(state, sortKey)}
|
|
nextDir={nextDir}
|
|
sortLabel={stateDeputyListSortLabels[sortKey]}
|
|
filter={
|
|
filterOptions ? (
|
|
<StateDeputyHeaderFilter
|
|
state={state}
|
|
options={filterOptions}
|
|
hasNoParty={hasNoPartyOption}
|
|
/>
|
|
) : null
|
|
}
|
|
>
|
|
{children ?? stateDeputyListSortLabels[sortKey]}
|
|
</CampaignSortableHead>
|
|
)
|
|
}
|