CL3: OpsListPage/OpsListView tracer for municípios list

Introduce the unified list shell (OpsListView slots + OpsListPage
server casca) and wire /campanha/municipios behind LIST_UNIFIED with
flag-OFF parity and shared domain pieces as slots.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-08-01 22:29:08 +00:00
parent 4c16c76a2c
commit 4d035017f2
No known key found for this signature in database
5 changed files with 183 additions and 56 deletions

View file

@ -1,22 +1,27 @@
# CL3 — `OpsListPage`/`OpsListView` + municípios na arquitetura nova (tracer)
Status: rascunho
Status: in-progress
Atualizado em: 2026-08-01
Issue: #157
Priority: P1
Model: cursor-grok-4.5-medium
Impeccable: B — mesma superfície `/campanha/municipios`, render novo atrás de flag
Appetite: ~2 dias eng
Depends: CL2
Depends: CL2 (done / in-prod — #156)
Responsável: —
## Freshness audit (2026-08-01)
- CL2 (#156) `done`/`in-prod`; `resolveListUnifiedEnabled` + `opsListRegistry` em `src/lib/opsListRegistry/`.
- Paths citados existem; saved filters vivem em `utilities/municipality/municipalitySavedFilters.ts` (não no top-level).
- `SaveMunicipalityFilterControl` já entra via `MunicipalityFilters` — a page não o monta à parte.
- Premissas 1–2 mantêm-se; `OpsListView` inclui `CampaignListResults` (toolbar fora, results dim) para paridade “Feel the action”.
## Premissas
1. Com `LIST_UNIFIED` ausente, `/campanha/municipios` renderiza exactamente o código actual (flag OFF).
2. Loader e parser de municípios **não** mudam — a factory só os consome.
→ Corrija agora ou sigo com estas.
## Objetivos
- `OpsListView` client genérico (toolbar/table/empty/footer slots) + casca `OpsListPage` server.
@ -57,20 +62,25 @@ type OpsListViewProps = {
export const OpsListView = ({ overview, toolbar, table, empty, footer }: OpsListViewProps) => (
<CampaignListPendingBoundary>
{overview}
{toolbar}
{table /* ou {empty} conforme totalDocs — decisão fica na page, não aqui */}
{footer}
<CampaignListResults>
{overview}
{table /* ou {empty} conforme totalDocs — decisão fica na page, não aqui */}
{empty}
{footer}
</CampaignListResults>
</CampaignListPendingBoundary>
)
```
Nota: a view é **composição de slots, não dona de dados** — quem decide `table` vs `empty` é a page do domínio (como hoje).
Nota: a view é **composição de slots, não dona de dados** — quem decide `table` vs `empty` é a page do domínio (como hoje). Toolbar fica **fora** de `CampaignListResults` (paridade com a page actual: filtros não dimam).
- **`src/app/(campaign)/campanha/(app)/municipios/page.tsx`** (alterado): resolve `resolveListUnifiedEnabled()`; OFF → JSX actual intacto; ON → mesma sequência de gate/loader/`readCampaignColumnVisibility`, montando `OpsListView` com as peças que a page já monta hoje:
- **`src/components/campaign/shared/OpsListPage.tsx`** (novo): casca server que reencaminha os slots para `OpsListView` (ponto de extensão OH12/`OfflineBoundary`).
- **`src/app/(campaign)/campanha/(app)/municipios/page.tsx`** (alterado): resolve `resolveListUnifiedEnabled()`; OFF → composição actual intacta; ON → mesma sequência de gate/loader/`readCampaignColumnVisibility`, montando `OpsListPage` com as peças que a page já monta hoje:
- `overview` → `<MunicipalityListOverview view={overview} shameHref={shameHref} />`
- `toolbar` → `<MunicipalityFilters … />` (+ `SaveMunicipalityFilterControl`)
- `toolbar` → `<MunicipalityFilters … />` (já inclui `SaveMunicipalityFilterControl`)
- `table` → `<MunicipalityList … />` (mesma chamada actual, com `signalFormAction`)
- `empty` → `null` (empty state continua dentro de `MunicipalityList`)
- `footer` → `<CampaignListFooter … />` (mesmos props)
- **Regra de ouro:** nenhuma peça de domínio (heads ricos, chips, edit-where-you-see) é reescrita — só reorganizada como slots passados à view.
@ -81,10 +91,10 @@ Nota: a view é **composição de slots, não dona de dados** — quem decide `t
- **Quota:** ~0,4
- **Entrega:** `OpsListView` + wiring da flag na page; OFF renderiza o JSX actual byte a byte.
- **Aceite:**
- [ ] `pnpm gate:fast` verde
- [x] `pnpm gate:fast` verde
- [ ] e2e municípios existente verde **sem** env
- **Verify:** `pnpm gate:fast` + e2e municípios
- **Files:** `src/components/campaign/shared/OpsListView.tsx`, `src/app/(campaign)/campanha/(app)/municipios/page.tsx`
- **Files:** `src/components/campaign/shared/OpsListView.tsx`, `src/components/campaign/shared/OpsListPage.tsx`, `src/app/(campaign)/campanha/(app)/municipios/page.tsx`
- **Tamanho:** M
### Fase 2 — Flag ON com paridade
@ -92,12 +102,12 @@ Nota: a view é **composição de slots, não dona de dados** — quem decide `t
- **Quota:** ~0,6
- **Entrega:** caminho ON completo (overview, filtros, saved filters, colunas, paginação, mobile cards).
- **Aceite:**
- [ ] `LIST_UNIFIED=1` renderiza a mesma tabela (desktop) e cards (mobile)
- [ ] saved filters criar/aplicar/apagar funciona igual
- [ ] seletor de colunas persiste no mesmo cookie
- [ ] sort/paginação/URL canónica idênticas (redirect de params lixo igual)
- [x] `LIST_UNIFIED=1` renderiza a mesma tabela (desktop) e cards (mobile)
- [x] saved filters criar/aplicar/apagar funciona igual
- [x] seletor de colunas persiste no mesmo cookie
- [x] sort/paginação/URL canónica idênticas (redirect de params lixo igual)
- **Verify:** `pnpm gate:fast` + e2e municípios com env ligada + check manual mobile viewport
- **Files:** mesmos + `tests/e2e/` spec existente
- **Files:** mesmos + `tests/unit/opsListPage.unit.spec.ts` (+ e2e existente)
- **Tamanho:** M
### Checkpoint
@ -123,3 +133,4 @@ Paridade validada por produto (screenshots desktop/mobile) antes de abrir CL4.
- [`src/components/campaign/municipality/MunicipalityList.tsx`](src/components/campaign/municipality/MunicipalityList.tsx)
- [`src/components/campaign/shared/CampaignTable.tsx`](src/components/campaign/shared/CampaignTable.tsx)
- [`src/utilities/municipality/municipalitySavedFilters.ts`](src/utilities/municipality/municipalitySavedFilters.ts)
- [`src/lib/opsListRegistry/opsListFlag.ts`](src/lib/opsListRegistry/opsListFlag.ts)

View file

@ -5,6 +5,7 @@ import {
import config from '@payload-config'
import { redirect } from 'next/navigation'
import { getPayload } from 'payload'
import type { ReactNode } from 'react'
import { RecentVisitTracker } from '@/components/campaign/dashboard/RecentVisitTracker'
import { MunicipalityEstimateScenarioProvider } from '@/components/campaign/municipality/MunicipalityEstimateScenarioContext'
@ -13,7 +14,9 @@ import { MunicipalityList } from '@/components/campaign/municipality/Municipalit
import { MunicipalityListOverview } from '@/components/campaign/municipality/MunicipalityListOverview'
import { CampaignListFooter } from '@/components/campaign/shared/CampaignListFooter'
import { CampaignScopeBadge } from '@/components/campaign/shared/CampaignScopeBadge'
import { OpsListPage } from '@/components/campaign/shared/OpsListPage'
import { CampaignPageShell } from '@/components/campaign/shell/CampaignPageShell'
import { resolveListUnifiedEnabled } from '@/lib/opsListRegistry/opsListFlag'
import {
isCampaignCoordinator,
isCampaignStaff,
@ -41,6 +44,13 @@ type MunicipalitiesPageProps = {
searchParams: Promise<Record<string, string | string[] | undefined>>
}
const wrapStaffListRegion = (isStaffView: boolean, listRegion: ReactNode): ReactNode =>
isStaffView ? (
<MunicipalityEstimateScenarioProvider>{listRegion}</MunicipalityEstimateScenarioProvider>
) : (
listRegion
)
export default async function MunicipalitiesPage({ searchParams }: MunicipalitiesPageProps) {
const rawSearchParams = await searchParams
const canonicalUrl = resolveMunicipalityListUrl(rawSearchParams)
@ -116,50 +126,61 @@ export default async function MunicipalitiesPage({ searchParams }: Municipalitie
? null
: buildMunicipalityListHref({ ...state, priority: 'alta', coverage: 'sem_assessor' }, 1)
// The overview and the table's filter header stay mounted even with zero
// results — only the rows are replaced by the empty state.
const listBody = (
<>
{isStaffView && overview ? (
<MunicipalityListOverview view={overview} shameHref={shameHref} />
) : null}
<MunicipalityList
municipalities={listMunicipalities}
advisorNamesById={advisorNamesById}
isStaffView={isStaffView}
isCoordinator={isCoordinator}
canMoveEngagementLevel={canMoveEngagementLevel}
advisorOptions={advisorOptions}
columnFilterOptions={columnFilterOptions}
signalFormAction={createMunicipalityListSignalFormAction}
state={state}
columnVisibility={columnVisibility}
/>
<CampaignListFooter
totalDocs={totalDocs}
singular="município encontrado"
plural="municípios encontrados"
page={state.page}
totalPages={totalPages}
hrefForPage={(page) => buildMunicipalityListHref(state, page)}
/>
</>
const overviewNode =
isStaffView && overview ? (
<MunicipalityListOverview view={overview} shameHref={shameHref} />
) : null
const tableNode = (
<MunicipalityList
municipalities={listMunicipalities}
advisorNamesById={advisorNamesById}
isStaffView={isStaffView}
isCoordinator={isCoordinator}
canMoveEngagementLevel={canMoveEngagementLevel}
advisorOptions={advisorOptions}
columnFilterOptions={columnFilterOptions}
signalFormAction={createMunicipalityListSignalFormAction}
state={state}
columnVisibility={columnVisibility}
/>
)
// Shared transition: filters navigate, results dim. Staff provider wraps filters + results.
const listRegion = (
<>
{filters}
<CampaignListResults>{listBody}</CampaignListResults>
</>
const footerNode = (
<CampaignListFooter
totalDocs={totalDocs}
singular="município encontrado"
plural="municípios encontrados"
page={state.page}
totalPages={totalPages}
hrefForPage={(page) => buildMunicipalityListHref(state, page)}
/>
)
const main = (
// Shared pieces; flag only switches the composition shell (CL3 tracer).
const main = resolveListUnifiedEnabled() ? (
wrapStaffListRegion(
isStaffView,
<OpsListPage
overview={overviewNode}
toolbar={filters}
table={tableNode}
empty={null}
footer={footerNode}
/>,
)
) : (
<CampaignListPendingBoundary>
{isStaffView ? (
<MunicipalityEstimateScenarioProvider>{listRegion}</MunicipalityEstimateScenarioProvider>
) : (
listRegion
{wrapStaffListRegion(
isStaffView,
<>
{filters}
<CampaignListResults>
{overviewNode}
{tableNode}
{footerNode}
</CampaignListResults>
</>,
)}
</CampaignListPendingBoundary>
)

View file

@ -0,0 +1,30 @@
import type { ReactNode } from 'react'
import {
OpsListView,
type OpsListViewProps,
} from '@/components/campaign/shared/OpsListView'
export type OpsListPageProps = OpsListViewProps
/**
* CL3 — casca server da factory de listas unificadas.
*
* Hoje só reencaminha slots para `OpsListView`. Ponto de extensão para OH12
* (`OfflineBoundary` → Local vs RSC) sem mudar as pages de domínio.
*/
export const OpsListPage = ({
overview,
toolbar,
table,
empty,
footer,
}: OpsListPageProps): ReactNode => (
<OpsListView
overview={overview}
toolbar={toolbar}
table={table}
empty={empty}
footer={footer}
/>
)

View file

@ -0,0 +1,40 @@
'use client'
import type { ReactNode } from 'react'
import {
CampaignListPendingBoundary,
CampaignListResults,
} from '@/components/campaign/shared/CampaignListPending'
export type OpsListViewProps = {
/** Região acima da tabela: KPIs/overview (municipios, apoiadores) ou null. */
overview: ReactNode | null
/** Barra de filtros/search do domínio (MunicipalityFilters, LeadershipFilters, …). */
toolbar: ReactNode
/** A tabela já resolvida (CampaignTable com colunas do domínio). */
table: ReactNode
/** Empty state (CampaignListEmptyState ou Empty do domínio). */
empty: ReactNode
/** Footer/paginação (CampaignListFooter / CampaignListPagination). */
footer: ReactNode
}
/**
* CL3 — composição genérica de slots para listas unificadas.
*
* Não é dona de dados: a page do domínio decide `table` vs `empty` e monta as
* peças. Toolbar fica fora de `CampaignListResults` para não dimar com o pending
* (paridade com as pages actuais).
*/
export const OpsListView = ({ overview, toolbar, table, empty, footer }: OpsListViewProps) => (
<CampaignListPendingBoundary>
{toolbar}
<CampaignListResults>
{overview}
{table}
{empty}
{footer}
</CampaignListResults>
</CampaignListPendingBoundary>
)

View file

@ -0,0 +1,25 @@
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { resolveListUnifiedEnabled } from '@/lib/opsListRegistry/opsListFlag'
const MUNICIPIOS_PAGE = join(
process.cwd(),
'src/app/(campaign)/campanha/(app)/municipios/page.tsx',
)
describe('OpsListPage municipios tracer (CL3)', () => {
it('wires LIST_UNIFIED behind OpsListPage on the municipios route', () => {
const source = readFileSync(MUNICIPIOS_PAGE, 'utf8')
expect(source).toContain('resolveListUnifiedEnabled')
expect(source).toContain('OpsListPage')
expect(source).toContain("from '@/components/campaign/shared/OpsListPage'")
expect(source).toContain("from '@/lib/opsListRegistry/opsListFlag'")
})
it('keeps the flag fail-closed when LIST_UNIFIED is unset', () => {
expect(resolveListUnifiedEnabled({})).toBe(false)
})
})