teqo/src/components/campaign/MunicipalityListGoalCoverageCell.tsx
Francisco Ignácio Fontoura Solla 51c13153fc E9: Fila de alocação (déficit como default do staff, frescor, coluna da vergonha)
A lista de municípios vira a fila de decisão, sem rota nova, sem coluna nova
e sem migration.

Fase 0 corrige a meta sintética do E8, que repartia a meta estadual
proporcionalmente só ao teto do campo e ignorava a votação própria (meta 2.911
para Vitória da Conquista, de 5.005 votos em 2022; 813 para Campo Formoso, de
47). `deriveSuggestedGoalsByScenario` substitui `decomposeStateGoal` e ancora a
meta na votação de 2022 por cenário — pessimista = base × (1 − margin), central
= base, otimista = base × (stateGoal ÷ Σ base), com clamp. `goalCoverage` passa
a receber `SuggestedGoalByScenario`, deixando `expectedVotes[S] ??
suggestedGoal[S]` simétrico. Só descrições do global mudaram.

Fase 1 adiciona frescor e ordenações: `declaredAt`/`estimatedAt` no select do
agregado de pledges (`lastPledgeAt`), `lastSignalAt` no view model via
`resolveMunicipalityLastSignalAt` (mesmo helper para o comparador do servidor e
a célula), e as sort keys `deficit` (novo default do staff) e `frescor`,
derivadas em memória no cenário central.

Fase 2 dobra os sinais nas células existentes: "há N dias" na coluna de última
atualização (frio ≥ 21 dias, em âmbar — vermelho já é da prioridade), badge
"sem responsável" em prioridade alta sem assessor, coluna da vergonha no
detalhe da métrica de assessoria, tooltip de cobertura nomeando o cenário e
copy Praças→Municípios.

Cortes: votos em jogo → B13, LQ/captura → E10, coluna dedicada de déficit
desnecessária.
2026-07-25 02:24:17 -03:00

62 lines
2.4 KiB
TypeScript

'use client'
import { useMunicipalityEstimateScenarioOptional } from '@/components/campaign/MunicipalityEstimateScenarioContext'
import {
formatGoalCoverageDeficitLabel,
formatGoalCoverageDeficitShortLabel,
formatGoalCoverageRatioLabel,
type MunicipalityGoalCoverage,
} from '@/utilities/goalCoverage'
import {
DEFAULT_VOTE_ESTIMATE_SCENARIO,
voteEstimateScenarioLabels,
type VoteEstimateScenario,
} from '@/utilities/voteEstimate'
/**
* E8 "conta da cadeira" list cell: reads the shared scenario picker (same
* pattern as `MunicipalityListExpectedVotesControl`) and shows the
* percent + deficit for that scenario, computed server-side for all three.
*
* `compact` (desktop table, dense) shows a short signed deficit with the
* full sentence as a `title` tooltip — same "abbreviate + title" pattern as
* `StaffMunicipalityVotesDisplay`'s "Nas lideranças" subline — so the column
* doesn't force a wide `whitespace-nowrap` cell. `default` (mobile cards,
* more room) spells the sentence out.
*/
export const MunicipalityListGoalCoverageCell = ({
coverageByScenario,
layout = 'default',
}: {
coverageByScenario: Record<VoteEstimateScenario, MunicipalityGoalCoverage>
layout?: 'default' | 'compact'
}) => {
const scenarioContext = useMunicipalityEstimateScenarioOptional()
const activeScenario = scenarioContext?.scenario ?? DEFAULT_VOTE_ESTIMATE_SCENARIO
const coverage = coverageByScenario[activeScenario]
const deficitLabel = formatGoalCoverageDeficitLabel(coverage)
// Names the scenario the figures belong to: the header sorts by `central`
// regardless of this picker (E9), so an unnamed number here would be
// ambiguous the moment the two disagree.
const scenarioLabel = voteEstimateScenarioLabels[activeScenario]
return (
<div className="flex flex-col items-start">
<span className="font-medium tabular-nums" title={`Cenário ${scenarioLabel}`}>
{formatGoalCoverageRatioLabel(coverage)}
</span>
{layout === 'compact' ? (
<span
className="text-xs text-muted-foreground tabular-nums"
title={`${deficitLabel} (cenário ${scenarioLabel})`}
>
{formatGoalCoverageDeficitShortLabel(coverage)}
</span>
) : (
<span className="text-xs text-muted-foreground tabular-nums">
{deficitLabel} · cenário {scenarioLabel}
</span>
)}
</div>
)
}