From 155f6492d9d11c85f229a818fa8f6f4e1b35778e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Ign=C3=A1cio=20Fontoura=20Solla?= Date: Tue, 28 Jul 2026 08:20:55 -0300 Subject: [PATCH 1/4] B17: column picker on the seven CampaignTable list surfaces. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The picker shipped as a capability of CampaignTable rather than a municípios feature, so every list that already uses the shared table got it: pass `columnVisibility` and the table mounts the menu and filters the columns. Persistence is a cookie, not localStorage, and the reason is a type rather than a preference: CampaignTableColumn.cell is a function, so the column array never crosses the server/client boundary and the client cannot rebuild the table without it. The server filters, so a hidden column does not reach the RSC payload either. `campaign_columns` carries a listId -> hidden ids map in a compact form with no JSON and no percent-encoding, because document.cookie and Next's cookies() disagree about decoding. Closing the menu is the commit. The first cut debounced at 400 ms, which batches a burst rather than a reading pace, so unchecking four columns while reading their labels was four full-route refreshes — on /campanha/liderancas each one re-pays the ~229 ms / 371-statement render already ledgered P1. The timer survives at 3 s as a safety net for a menu left open; the price is that the table behind the menu no longer updates per checkbox. `defaultVisible` is gone: it was true on 10 columns and false on none, and storing only the hidden set is what makes a newly shipped column visible to everyone who never touched the picker. In exchange `label` is required, which made `head` optional — 24 columns had a head that only restated the new label. Each surface declares one mandatory column, re-filtered on the server so a stale cookie cannot leave a row without its only linked cell. The bug review caught is this codebase's recurring one: the RSC payload of toggle A arrives inside the window of toggle B, and adopting the server there undid B and then committed the set without it. Reconciliation now runs only when no write is pending, pinned red against the previous code. Municipality column ids are typed against MunicipalityListColumnId now, so the id, the B22 description and the picker label are one key; the union member `nivel` was renamed `level` to match the id and the ?level= filter. The picker's own content comparison is sameIdSet, widened to string ids. --- .cursor/rules/codebase-map.mdc | 2 +- .cursor/rules/projects/nucleos-eleitorais.mdc | 1 + AGENTS.md | 2 + docs/ARCHITECTURE.md | 2 +- docs/TECH-DEBT.md | 50 ++--- docs/plans/escala-dry-pos-b32.md | 3 + .../plans/seletor-colunas-lista-municipios.md | 41 +++- docs/roadmap.md | 6 +- .../campanha/(app)/apoiadores/page.tsx | 3 + .../campanha/(app)/demandas/page.tsx | 27 ++- .../campanha/(app)/dobradinhas/page.tsx | 16 +- .../campanha/(app)/liderancas/page.tsx | 17 +- .../campanha/(app)/municipios/page.tsx | 3 + .../campanha/(app)/organizacoes/page.tsx | 23 +- .../campanha/(app)/territorios/page.tsx | 9 +- .../municipality/MunicipalityList.tsx | 44 +++- .../campaign/municipality/TerritoryList.tsx | 4 + .../municipality/TerritoryListColumns.tsx | 22 +- .../campaign/shared/CampaignColumnPicker.tsx | 211 ++++++++++++++++++ .../campaign/shared/CampaignTable.tsx | 159 ++++++++----- .../campaign/supporter/SupporterList.tsx | 21 +- src/lib/campaignColumnVisibility.ts | 124 ++++++++++ src/lib/sameIdSet.ts | 5 +- .../campaignColumnVisibilityCookie.ts | 24 ++ src/utilities/municipalityLabels.ts | 6 +- src/utilities/municipalityListUrl.ts | 26 +++ tests/e2e/campaignColumnPicker.e2e.spec.ts | 100 +++++++++ tests/unit/campaignColumnPicker.unit.spec.ts | 152 +++++++++++++ .../campaignColumnVisibility.unit.spec.ts | 95 ++++++++ tests/unit/campaignTable.unit.spec.ts | 34 ++- 30 files changed, 1073 insertions(+), 159 deletions(-) create mode 100644 src/components/campaign/shared/CampaignColumnPicker.tsx create mode 100644 src/lib/campaignColumnVisibility.ts create mode 100644 src/utilities/campaignColumnVisibilityCookie.ts create mode 100644 tests/e2e/campaignColumnPicker.e2e.spec.ts create mode 100644 tests/unit/campaignColumnPicker.unit.spec.ts create mode 100644 tests/unit/campaignColumnVisibility.unit.spec.ts diff --git a/.cursor/rules/codebase-map.mdc b/.cursor/rules/codebase-map.mdc index c7bd5509..88c69dd7 100644 --- a/.cursor/rules/codebase-map.mdc +++ b/.cursor/rules/codebase-map.mdc @@ -27,7 +27,7 @@ Conceitos e decisões: `docs/ARCHITECTURE.md`. Operação (setup/seeds/deploy/se ## Sistema de listas (Pass 2 W1 — use, não reinvente) - URL: `utilities/campaignListUrl.ts` (parse/canonicalize/`resolveListUrl`) + módulo por domínio (`municipalityListUrl.ts`, `supporterUi.ts`, `activityUi.ts`, parsers nos `*Data.ts`). Contrato de URL congelado (B18). -- Tabela: `shared/CampaignTable.tsx` — colunas como dado (`id`, `head`, `cell`, seams `mandatory`/`defaultVisible` p/ B17); heads ricos = ilhas (`municipality/MunicipalitySortableHead` + `MunicipalityHeaderFilter`). +- Tabela: `shared/CampaignTable.tsx` — colunas como dado (`id`, `label` **obrigatório**, `head` opcional (default = `{label}`; declare só para alinhamento, `description` do B22 ou ilha de head), `cell`, `mandatory`); heads ricos = ilhas (`municipality/MunicipalitySortableHead` + `MunicipalityHeaderFilter`). Seletor de colunas (B17): passe `columnVisibility` — **um** valor, devolvido por `readCampaignColumnVisibility(listId)` (`utilities/campaignColumnVisibilityCookie.ts`, `server-only`) em quem renderiza a tabela — e ela monta o `CampaignColumnPicker` e filtra por `resolveVisibleColumns`; regra pura em `lib/campaignColumnVisibility.ts`. Só o conjunto de **ocultas** é guardado (`defaultVisible` não existe): coluna nova nasce visível. - Shells: `CampaignSearchForm`, `CampaignFilterChips`, `CampaignListFooter`, `CampaignListEmptyState`, `CampaignListPagination`, pending compartilhado em `CampaignListPending.tsx` (dima o resultado, não o controle). - Relação por chips numa célula: `shared/MunicipalityPortfolioCell` (B34) — sempre montada em `pointer-fine`, Drawer em `pointer-coarse`; costuras `minItems`/`maxItems`/`addableIds`/`draft`/`commitAction`. Serve lideranças e assessores; não escrever uma terceira. Lógica pura em `lib/municipalityPortfolio.ts`, índice em `utilities/municipalityPortfolioIndex.ts`. - Exceções documentadas: atividades = cards; `TerritoryOverviewTable` = sort no cliente; comparação de candidatos, LeaderContacts e preview de import ficam fora. diff --git a/.cursor/rules/projects/nucleos-eleitorais.mdc b/.cursor/rules/projects/nucleos-eleitorais.mdc index ffa644f1..f79ff7fc 100644 --- a/.cursor/rules/projects/nucleos-eleitorais.mdc +++ b/.cursor/rules/projects/nucleos-eleitorais.mdc @@ -7,6 +7,7 @@ alwaysApply: false ## Status +- **B17 entregue em código (2026-07-28):** seletor de colunas, e **nas sete superfícies** do sistema de listas (municípios, lideranças, dobradinhas, organizações, demandas, apoiadores, territórios), não só em municípios — o picker nasceu como capacidade do `CampaignTable` (uma prop `columnVisibility`, devolvida inteira por `readCampaignColumnVisibility(listId)`, liga o controle e filtra), então o custo marginal por lista foi `label` nas colunas e uma prop. Fora: `/campanha/assessores`, cujo `AdvisorsTable` ainda é `ui/Table` cru com `table-fixed`. **Duas premissas do plano de 24/07 morreram.** (1) `localStorage` — e o motivo é de tipo, não de gosto: `CampaignTableColumn.cell` é **função**, o array de colunas não atravessa a fronteira server/client, e esconder no cliente exigiria `data-column` + `