mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
Merge pull request #199 from fsolla/cursor/pool-i162-f7cd7874-0af3
CL8 — Contrato, saved filters, cleanup e redirect canónico (#162)
This commit is contained in:
commit
2926b4a1ef
15 changed files with 236 additions and 36 deletions
|
|
@ -39,3 +39,7 @@ CAMPAIGN_EMAIL_FROM_NAME=Campanha Jorge Solla
|
||||||
# Ops hybrid RSC/local (OH*). Compile-time; set to 1/true to enable estimate outbox + CAS.
|
# Ops hybrid RSC/local (OH*). Compile-time; set to 1/true to enable estimate outbox + CAS.
|
||||||
# Absent or 0 keeps /campanha identical to main. See docs/plans/ops-hibrido-rsc-local-spec.md
|
# Absent or 0 keeps /campanha identical to main. See docs/plans/ops-hibrido-rsc-local-spec.md
|
||||||
OPS_HYBRID=
|
OPS_HYBRID=
|
||||||
|
|
||||||
|
# Unified list factory (CL*). Compile-time; set to 1/true to render lists via OpsListPage.
|
||||||
|
# Absent or 0 keeps the legacy list shells. See docs/plans/lista-unificada-campanha-spec.md
|
||||||
|
LIST_UNIFIED=
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ Conteúdo movido do `AGENTS.md` em 2026-07-30 (fatiamento do paradigma de agente
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
**Recently resolved (2026-08-01):** **CL8** (Issue #162) — contrato das 8 listas v1: pin slug↔rota (`opsListRegistryRoutes`), saved filters municípios intactos com `LIST_UNIFIED` (e2e tracer), `resolveDemandListUrl` + `resolveOrganizationListUrl` (redirect canónico; registry `canonicalRedirect: true`). Plano: [`cl8-contrato-cleanup.md`](docs/plans/cl8-contrato-cleanup.md).
|
||||||
|
|
||||||
**Recently resolved (2026-08-01):** **CL6** (Issue #159) — territórios: paginação real + sort no loader (`selectTerritoryOverviewPage` / `loadTerritoryOverviewPage`), `page` no contrato URL, registry `sortModel: 'url'`, `/campanha/territorios` atrás de `LIST_UNIFIED` com paridade OFF. Plano: [`cl6-territorios-factory.md`](docs/plans/cl6-territorios-factory.md).
|
**Recently resolved (2026-08-01):** **CL6** (Issue #159) — territórios: paginação real + sort no loader (`selectTerritoryOverviewPage` / `loadTerritoryOverviewPage`), `page` no contrato URL, registry `sortModel: 'url'`, `/campanha/territorios` atrás de `LIST_UNIFIED` com paridade OFF. Plano: [`cl6-territorios-factory.md`](docs/plans/cl6-territorios-factory.md).
|
||||||
**Recently resolved (2026-08-01):** **OH4** (Issue #166) — `GET /campanha/api/ops-sync` full snapshot: `buildOpsSnapshot` (`overrideAccess: false`, queries em paralelo, truncamento 50 updates/município), 401/403 staff gate, pins int advisor/leader. Plano: [`oh4-ops-sync-route.md`](docs/plans/oh4-ops-sync-route.md).
|
**Recently resolved (2026-08-01):** **OH4** (Issue #166) — `GET /campanha/api/ops-sync` full snapshot: `buildOpsSnapshot` (`overrideAccess: false`, queries em paralelo, truncamento 50 updates/município), 401/403 staff gate, pins int advisor/leader. Plano: [`oh4-ops-sync-route.md`](docs/plans/oh4-ops-sync-route.md).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# CL8 — Contrato, saved filters, cleanup e decisão de canonical redirect
|
# CL8 — Contrato, saved filters, cleanup e decisão de canonical redirect
|
||||||
|
|
||||||
Status: rascunho
|
Status: entregue (CL8, #162)
|
||||||
Atualizado em: 2026-08-01
|
Atualizado em: 2026-08-01
|
||||||
Issue: #162
|
Issue: #162
|
||||||
Priority: P1
|
Priority: P1
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ Tabela canónica dos metadados v1. Planos filhos (**CL2+**) citam esta secção
|
||||||
| `municipios` | `/campanha/municipios` | `noLeader` | `municipios` | `true` | `url` | `true` |
|
| `municipios` | `/campanha/municipios` | `noLeader` | `municipios` | `true` | `url` | `true` |
|
||||||
| `liderancas` | `/campanha/liderancas` | `staff` | `liderancas` | `false` | `url` | `true` |
|
| `liderancas` | `/campanha/liderancas` | `staff` | `liderancas` | `false` | `url` | `true` |
|
||||||
| `dobradinhas` | `/campanha/dobradinhas` | `staff` | `dobradinhas` | `false` | `url` | `true` |
|
| `dobradinhas` | `/campanha/dobradinhas` | `staff` | `dobradinhas` | `false` | `url` | `true` |
|
||||||
| `demandas` | `/campanha/demandas` | `staff` | `demandas` | `false` | `fixed` (`-createdAt`) | `false` |
|
| `demandas` | `/campanha/demandas` | `staff` | `demandas` | `false` | `fixed` (`-createdAt`) | `true` (CL8) |
|
||||||
| `assessores` | `/campanha/assessores` | `unrestricted` | `'assessores'` (CL5) | `false` | `fixed` (sort `name`) | `true` (CL5) |
|
| `assessores` | `/campanha/assessores` | `unrestricted` | `'assessores'` (CL5) | `false` | `fixed` (sort `name`) | `true` (CL5) |
|
||||||
| `territorios` | `/campanha/territorios` | `noLeader` | `territorios` | `false` | `memory` → `url` em CL6a | `true` (sem `page` → com `page` em CL6a) |
|
| `territorios` | `/campanha/territorios` | `noLeader` | `territorios` | `false` | `memory` → `url` em CL6a | `true` (sem `page` → com `page` em CL6a) |
|
||||||
| `apoiadores` | `/campanha/apoiadores` | `staff` † | `apoiadores` | `false` | `url` | `true` |
|
| `apoiadores` | `/campanha/apoiadores` | `staff` † | `apoiadores` | `false` | `url` | `true` |
|
||||||
| `organizacoes` | `/campanha/organizacoes` | `staff` | `organizacoes` | `false` | `fixed` (`name`) | `false` |
|
| `organizacoes` | `/campanha/organizacoes` | `staff` | `organizacoes` | `false` | `fixed` (`name`) | `true` (CL8) |
|
||||||
|
|
||||||
† `apoiadores` hoje: `requireCampaignPageActor()` sem gate + `canAccessSupporterArea` (= staff). Registry pina `staff` como alvo da factory.
|
† `apoiadores` hoje: `requireCampaignPageActor()` sem gate + `canAccessSupporterArea` (= staff). Registry pina `staff` como alvo da factory.
|
||||||
|
|
||||||
|
|
@ -61,18 +61,18 @@ Campos de implementação (CL2), fora desta tabela: `layout: 'table'`, tipagem `
|
||||||
|
|
||||||
## Resolução de conflitos por domínio
|
## Resolução de conflitos por domínio
|
||||||
|
|
||||||
| Conflito | Resolução travada |
|
| Conflito | Resolução travada |
|
||||||
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| Canonical redirect ausente (assessores, demandas, organizações) | Assessores: criar `resolveAdvisorListUrl` no pré-work (CL5a). Demandas/organizações: manter parse actual na v1 (`canonicalRedirect: false` no registry); migrar redirect só se CL8 medir custo máximo 0,5d/domínio. |
|
| Canonical redirect ausente (assessores, demandas, organizações) | Assessores: `resolveAdvisorListUrl` (CL5). Demandas/organizações: `resolveDemandListUrl` / `resolveOrganizationListUrl` (CL8). |
|
||||||
| Sort divergente (URL vs fixo vs memória) | Não unificar. Registry declara `sortModel: 'url' \| 'fixed' \| 'memory'`. |
|
| Sort divergente (URL vs fixo vs memória) | Não unificar. Registry declara `sortModel: 'url' \| 'fixed' \| 'memory'`. |
|
||||||
| Territórios sem paginação real | CL6a obrigatório: paginação server 25 + sort no loader antes de migrar. |
|
| Territórios sem paginação real | CL6a obrigatório: paginação server 25 + sort no loader antes de migrar. |
|
||||||
| Assessores fora de `CampaignTable` | CL5a obrigatório: reescrever em `CampaignTable` + URL canónico. |
|
| Assessores fora de `CampaignTable` | CL5a obrigatório: reescrever em `CampaignTable` + URL canónico. |
|
||||||
| Seletor de colunas (allowlist fixa) | Registry mapeia slug → `columnListId`; pré-work adiciona `assessores` à allowlist se usar picker. |
|
| Seletor de colunas (allowlist fixa) | Registry mapeia slug → `columnListId`; pré-work adiciona `assessores` à allowlist se usar picker. |
|
||||||
| Saved filters (só municípios) | Registry declara `savedFilters: boolean`; slot só para municípios; **não** generalizar B18. |
|
| Saved filters (só municípios) | Registry declara `savedFilters: boolean`; slot só para municípios; **não** generalizar B18. |
|
||||||
| Edit model divergente | Não unificar; células/editores ficam nas colunas do domínio. |
|
| Edit model divergente | Não unificar; células/editores ficam nas colunas do domínio. |
|
||||||
| Toolbar heterogénea | Factory expõe `toolbarSlot` por domínio. |
|
| Toolbar heterogénea | Factory expõe `toolbarSlot` por domínio. |
|
||||||
| Gate de papel diferente | Registry declara `gate`; factory resolve actor e delega ao predicado existente. |
|
| Gate de papel diferente | Registry declara `gate`; factory resolve actor e delega ao predicado existente. |
|
||||||
| Atividades cards | Fora de `opsListDomains`; rota intocada. |
|
| Atividades cards | Fora de `opsListDomains`; rota intocada. |
|
||||||
|
|
||||||
## Inventário as-built (2026-08-01)
|
## Inventário as-built (2026-08-01)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@ const allowedImageHost = process.env.NEXT_PUBLIC_SITE_URL || 'https://jorgesolla
|
||||||
|
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
distDir: process.env.NEXT_DIST_DIR || '.next',
|
distDir: process.env.NEXT_DIST_DIR || '.next',
|
||||||
// OH6/OH*: compile-time ops hybrid flag (mother spec). Inlined for client
|
// OH6/OH* + CL*: compile-time flags inlined for client islands; absent/`0`
|
||||||
// islands; absent/`0` keeps CI identical to main.
|
// keeps CI identical to main.
|
||||||
env: {
|
env: {
|
||||||
OPS_HYBRID: process.env.OPS_HYBRID ?? '',
|
OPS_HYBRID: process.env.OPS_HYBRID ?? '',
|
||||||
|
LIST_UNIFIED: process.env.LIST_UNIFIED ?? '',
|
||||||
},
|
},
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [new URL(`${allowedImageHost}/**`)],
|
remotePatterns: [new URL(`${allowedImageHost}/**`)],
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ export default defineConfig({
|
||||||
NEXT_DIST_DIR: '.next/e2e',
|
NEXT_DIST_DIR: '.next/e2e',
|
||||||
PAYLOAD_SECRET: process.env.PAYLOAD_SECRET ?? 'test-only-secret-not-used-in-production',
|
PAYLOAD_SECRET: process.env.PAYLOAD_SECRET ?? 'test-only-secret-not-used-in-production',
|
||||||
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL ?? baseURL,
|
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL ?? baseURL,
|
||||||
|
LIST_UNIFIED: process.env.LIST_UNIFIED ?? '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import config from '@payload-config'
|
import config from '@payload-config'
|
||||||
import { InboxIcon, PlusIcon } from 'lucide-react'
|
import { InboxIcon, PlusIcon } from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { redirect } from 'next/navigation'
|
||||||
import { getPayload } from 'payload'
|
import { getPayload } from 'payload'
|
||||||
|
|
||||||
import { CampaignFilterChips } from '@/components/campaign/shared/CampaignFilterChips'
|
import { CampaignFilterChips } from '@/components/campaign/shared/CampaignFilterChips'
|
||||||
|
|
@ -26,7 +27,7 @@ import { readCampaignColumnVisibility } from '@/utilities/campaignColumnVisibili
|
||||||
import {
|
import {
|
||||||
buildDemandListHref,
|
buildDemandListHref,
|
||||||
loadDemandListPageData,
|
loadDemandListPageData,
|
||||||
parseDemandListParams,
|
resolveDemandListUrl,
|
||||||
type DemandRowViewModel,
|
type DemandRowViewModel,
|
||||||
} from '@/utilities/campaignDemandData'
|
} from '@/utilities/campaignDemandData'
|
||||||
import { requireCampaignPageActor } from '@/utilities/campaignPageActor'
|
import { requireCampaignPageActor } from '@/utilities/campaignPageActor'
|
||||||
|
|
@ -96,17 +97,22 @@ const demandColumns: Array<CampaignTableColumn<DemandRowViewModel>> = [
|
||||||
|
|
||||||
export default async function DemandsPage({ searchParams }: DemandsPageProps) {
|
export default async function DemandsPage({ searchParams }: DemandsPageProps) {
|
||||||
const rawSearchParams = await searchParams
|
const rawSearchParams = await searchParams
|
||||||
|
const canonicalUrl = resolveDemandListUrl(rawSearchParams)
|
||||||
|
if (canonicalUrl.redirectHref) redirect(canonicalUrl.redirectHref)
|
||||||
|
|
||||||
const [user, payload] = await Promise.all([
|
const [user, payload] = await Promise.all([
|
||||||
requireCampaignPageActor({ gate: 'staff' }),
|
requireCampaignPageActor({ gate: 'staff' }),
|
||||||
getPayload({ config }),
|
getPayload({ config }),
|
||||||
])
|
])
|
||||||
|
|
||||||
const state = parseDemandListParams(rawSearchParams)
|
|
||||||
const { rows, totalDocs, totalPages, openCount } = await loadDemandListPageData(
|
const { rows, totalDocs, totalPages, openCount } = await loadDemandListPageData(
|
||||||
payload,
|
payload,
|
||||||
user,
|
user,
|
||||||
state,
|
canonicalUrl.state,
|
||||||
)
|
)
|
||||||
|
const resolvedUrl = resolveDemandListUrl(rawSearchParams, totalPages)
|
||||||
|
if (resolvedUrl.redirectHref) redirect(resolvedUrl.redirectHref)
|
||||||
|
const { state } = resolvedUrl
|
||||||
const columnVisibility = await readCampaignColumnVisibility('demandas')
|
const columnVisibility = await readCampaignColumnVisibility('demandas')
|
||||||
|
|
||||||
const hrefForStatus = (status?: CampaignDemandStatus) =>
|
const hrefForStatus = (status?: CampaignDemandStatus) =>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import config from '@payload-config'
|
import config from '@payload-config'
|
||||||
import { PlusIcon, SearchXIcon } from 'lucide-react'
|
import { PlusIcon, SearchXIcon } from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { redirect } from 'next/navigation'
|
||||||
import { getPayload } from 'payload'
|
import { getPayload } from 'payload'
|
||||||
|
|
||||||
import { CampaignListEmptyState } from '@/components/campaign/shared/CampaignListEmptyState'
|
import { CampaignListEmptyState } from '@/components/campaign/shared/CampaignListEmptyState'
|
||||||
|
|
@ -22,7 +23,7 @@ import { requireCampaignPageActor } from '@/utilities/campaignPageActor'
|
||||||
import {
|
import {
|
||||||
buildOrganizationListHref,
|
buildOrganizationListHref,
|
||||||
loadOrganizationListPageData,
|
loadOrganizationListPageData,
|
||||||
parseOrganizationListParams,
|
resolveOrganizationListUrl,
|
||||||
type OrganizationRowViewModel,
|
type OrganizationRowViewModel,
|
||||||
} from '@/utilities/organizationData'
|
} from '@/utilities/organizationData'
|
||||||
|
|
||||||
|
|
@ -65,13 +66,22 @@ const organizationColumns: Array<CampaignTableColumn<OrganizationRowViewModel>>
|
||||||
|
|
||||||
export default async function OrganizationsPage({ searchParams }: OrganizationsPageProps) {
|
export default async function OrganizationsPage({ searchParams }: OrganizationsPageProps) {
|
||||||
const rawSearchParams = await searchParams
|
const rawSearchParams = await searchParams
|
||||||
|
const canonicalUrl = resolveOrganizationListUrl(rawSearchParams)
|
||||||
|
if (canonicalUrl.redirectHref) redirect(canonicalUrl.redirectHref)
|
||||||
|
|
||||||
const [user, payload] = await Promise.all([
|
const [user, payload] = await Promise.all([
|
||||||
requireCampaignPageActor({ gate: 'staff' }),
|
requireCampaignPageActor({ gate: 'staff' }),
|
||||||
getPayload({ config }),
|
getPayload({ config }),
|
||||||
])
|
])
|
||||||
|
|
||||||
const state = parseOrganizationListParams(rawSearchParams)
|
const { rows, totalDocs, totalPages } = await loadOrganizationListPageData(
|
||||||
const { rows, totalDocs, totalPages } = await loadOrganizationListPageData(payload, user, state)
|
payload,
|
||||||
|
user,
|
||||||
|
canonicalUrl.state,
|
||||||
|
)
|
||||||
|
const resolvedUrl = resolveOrganizationListUrl(rawSearchParams, totalPages)
|
||||||
|
if (resolvedUrl.redirectHref) redirect(resolvedUrl.redirectHref)
|
||||||
|
const { state } = resolvedUrl
|
||||||
const columnVisibility = await readCampaignColumnVisibility('organizacoes')
|
const columnVisibility = await readCampaignColumnVisibility('organizacoes')
|
||||||
|
|
||||||
const toolbarNode = (
|
const toolbarNode = (
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ export const opsListRegistry: Record<OpsListDomainId, OpsListDomainMeta> = {
|
||||||
columnListId: 'demandas',
|
columnListId: 'demandas',
|
||||||
savedFilters: false,
|
savedFilters: false,
|
||||||
sortModel: 'fixed',
|
sortModel: 'fixed',
|
||||||
canonicalRedirect: false,
|
canonicalRedirect: true,
|
||||||
layout: 'table',
|
layout: 'table',
|
||||||
},
|
},
|
||||||
assessores: {
|
assessores: {
|
||||||
|
|
@ -113,7 +113,7 @@ export const opsListRegistry: Record<OpsListDomainId, OpsListDomainMeta> = {
|
||||||
columnListId: 'organizacoes',
|
columnListId: 'organizacoes',
|
||||||
savedFilters: false,
|
savedFilters: false,
|
||||||
sortModel: 'fixed',
|
sortModel: 'fixed',
|
||||||
canonicalRedirect: false,
|
canonicalRedirect: true,
|
||||||
layout: 'table',
|
layout: 'table',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import { isCampaignStaff } from '@/utilities/campaignAccess'
|
||||||
import {
|
import {
|
||||||
buildListHref,
|
buildListHref,
|
||||||
firstValue,
|
firstValue,
|
||||||
|
resolveListUrl,
|
||||||
strictDecimalInteger,
|
strictDecimalInteger,
|
||||||
type RawSearchParams,
|
type RawSearchParams,
|
||||||
} from '@/utilities/campaignListUrl'
|
} from '@/utilities/campaignListUrl'
|
||||||
|
|
@ -41,6 +42,11 @@ export type DemandListState = {
|
||||||
activityId?: number
|
activityId?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DemandListSearchParams = RawSearchParams
|
||||||
|
|
||||||
|
const demandListParamNames = ['status', 'kind', 'activity', 'page'] as const
|
||||||
|
const demandListParamNameSet = new Set<string>(demandListParamNames)
|
||||||
|
|
||||||
export const parseDemandListParams = (searchParams: RawSearchParams): DemandListState => {
|
export const parseDemandListParams = (searchParams: RawSearchParams): DemandListState => {
|
||||||
const rawStatus = firstValue(searchParams.status)
|
const rawStatus = firstValue(searchParams.status)
|
||||||
const rawKind = firstValue(searchParams.kind)
|
const rawKind = firstValue(searchParams.kind)
|
||||||
|
|
@ -58,21 +64,52 @@ export const parseDemandListParams = (searchParams: RawSearchParams): DemandList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildDemandListSearchParams = (
|
const demandListStateToRawParams = (
|
||||||
state: DemandListState,
|
state: DemandListState,
|
||||||
page = state.page,
|
page = state.page,
|
||||||
|
): DemandListSearchParams => ({
|
||||||
|
page: String(page),
|
||||||
|
status: state.status,
|
||||||
|
kind: state.kind,
|
||||||
|
activity: state.activityId ? String(state.activityId) : undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
const serializeCanonicalDemandListSearchParams = (
|
||||||
|
canonicalState: DemandListState,
|
||||||
): URLSearchParams => {
|
): URLSearchParams => {
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
if (state.status) params.set('status', state.status)
|
if (canonicalState.status) params.set('status', canonicalState.status)
|
||||||
if (state.kind) params.set('kind', state.kind)
|
if (canonicalState.kind) params.set('kind', canonicalState.kind)
|
||||||
if (state.activityId) params.set('activity', String(state.activityId))
|
if (canonicalState.activityId) params.set('activity', String(canonicalState.activityId))
|
||||||
if (page > 1) params.set('page', String(page))
|
if (canonicalState.page > 1) params.set('page', String(canonicalState.page))
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildDemandListSearchParams = (state: DemandListState, page = state.page): URLSearchParams =>
|
||||||
|
serializeCanonicalDemandListSearchParams(
|
||||||
|
parseDemandListParams(demandListStateToRawParams(state, page)),
|
||||||
|
)
|
||||||
|
|
||||||
export const buildDemandListHref = (state: DemandListState, page: number): string =>
|
export const buildDemandListHref = (state: DemandListState, page: number): string =>
|
||||||
buildListHref(state, buildDemandListSearchParams, '/campanha/demandas', page)
|
buildListHref(state, buildDemandListSearchParams, '/campanha/demandas', page)
|
||||||
|
|
||||||
|
export const resolveDemandListUrl = (
|
||||||
|
params: DemandListSearchParams,
|
||||||
|
totalPages?: number,
|
||||||
|
): {
|
||||||
|
state: DemandListState
|
||||||
|
href: string
|
||||||
|
redirectHref?: string
|
||||||
|
} =>
|
||||||
|
resolveListUrl({
|
||||||
|
params,
|
||||||
|
paramNameSet: demandListParamNameSet,
|
||||||
|
parse: parseDemandListParams,
|
||||||
|
buildSearchParams: buildDemandListSearchParams,
|
||||||
|
basePath: '/campanha/demandas',
|
||||||
|
totalPages,
|
||||||
|
})
|
||||||
|
|
||||||
const resolveMunicipalityAndRequesterNames = async (
|
const resolveMunicipalityAndRequesterNames = async (
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
demands: CampaignDemand[],
|
demands: CampaignDemand[],
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
buildListHref,
|
buildListHref,
|
||||||
firstValue,
|
firstValue,
|
||||||
normalizedText,
|
normalizedText,
|
||||||
|
resolveListUrl,
|
||||||
strictDecimalInteger,
|
strictDecimalInteger,
|
||||||
type RawSearchParams,
|
type RawSearchParams,
|
||||||
} from '@/utilities/campaignListUrl'
|
} from '@/utilities/campaignListUrl'
|
||||||
|
|
@ -33,6 +34,11 @@ export type OrganizationListState = {
|
||||||
kind?: OrganizationKind
|
kind?: OrganizationKind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type OrganizationListSearchParams = RawSearchParams
|
||||||
|
|
||||||
|
const organizationListParamNames = ['q', 'kind', 'page'] as const
|
||||||
|
const organizationListParamNameSet = new Set<string>(organizationListParamNames)
|
||||||
|
|
||||||
export const parseOrganizationListParams = (
|
export const parseOrganizationListParams = (
|
||||||
searchParams: RawSearchParams,
|
searchParams: RawSearchParams,
|
||||||
): OrganizationListState => {
|
): OrganizationListState => {
|
||||||
|
|
@ -48,20 +54,53 @@ export const parseOrganizationListParams = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildOrganizationListSearchParams = (
|
const organizationListStateToRawParams = (
|
||||||
state: OrganizationListState,
|
state: OrganizationListState,
|
||||||
page = state.page,
|
page = state.page,
|
||||||
|
): OrganizationListSearchParams => ({
|
||||||
|
page: String(page),
|
||||||
|
q: state.q,
|
||||||
|
kind: state.kind,
|
||||||
|
})
|
||||||
|
|
||||||
|
const serializeCanonicalOrganizationListSearchParams = (
|
||||||
|
canonicalState: OrganizationListState,
|
||||||
): URLSearchParams => {
|
): URLSearchParams => {
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
if (state.q) params.set('q', state.q)
|
if (canonicalState.q) params.set('q', canonicalState.q)
|
||||||
if (state.kind) params.set('kind', state.kind)
|
if (canonicalState.kind) params.set('kind', canonicalState.kind)
|
||||||
if (page > 1) params.set('page', String(page))
|
if (canonicalState.page > 1) params.set('page', String(canonicalState.page))
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildOrganizationListSearchParams = (
|
||||||
|
state: OrganizationListState,
|
||||||
|
page = state.page,
|
||||||
|
): URLSearchParams =>
|
||||||
|
serializeCanonicalOrganizationListSearchParams(
|
||||||
|
parseOrganizationListParams(organizationListStateToRawParams(state, page)),
|
||||||
|
)
|
||||||
|
|
||||||
export const buildOrganizationListHref = (state: OrganizationListState, page: number): string =>
|
export const buildOrganizationListHref = (state: OrganizationListState, page: number): string =>
|
||||||
buildListHref(state, buildOrganizationListSearchParams, '/campanha/organizacoes', page)
|
buildListHref(state, buildOrganizationListSearchParams, '/campanha/organizacoes', page)
|
||||||
|
|
||||||
|
export const resolveOrganizationListUrl = (
|
||||||
|
params: OrganizationListSearchParams,
|
||||||
|
totalPages?: number,
|
||||||
|
): {
|
||||||
|
state: OrganizationListState
|
||||||
|
href: string
|
||||||
|
redirectHref?: string
|
||||||
|
} =>
|
||||||
|
resolveListUrl({
|
||||||
|
params,
|
||||||
|
paramNameSet: organizationListParamNameSet,
|
||||||
|
parse: parseOrganizationListParams,
|
||||||
|
buildSearchParams: buildOrganizationListSearchParams,
|
||||||
|
basePath: '/campanha/organizacoes',
|
||||||
|
totalPages,
|
||||||
|
})
|
||||||
|
|
||||||
const municipalityNamesByIds = async (
|
const municipalityNamesByIds = async (
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
ids: number[],
|
ids: number[],
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ import { expect, test } from './fixtures/campaignE2EFixtures.js'
|
||||||
* there must not be read as a regression here.
|
* there must not be read as a regression here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const listUnifiedEnabled =
|
||||||
|
process.env.LIST_UNIFIED === '1' || process.env.LIST_UNIFIED?.toLowerCase() === 'true'
|
||||||
|
|
||||||
/** 416 whole municipalities — deep enough that `?page=2` is a real page. */
|
/** 416 whole municipalities — deep enough that `?page=2` is a real page. */
|
||||||
const SAVED_RECORTE = '/campanha/municipios?priority=alta'
|
const SAVED_RECORTE = '/campanha/municipios?priority=alta'
|
||||||
|
|
||||||
|
|
@ -129,3 +132,31 @@ test.describe('Filtros salvos de Municípios', () => {
|
||||||
await expect(page.getByRole('link', { name: SAVED_NAME })).toBeVisible()
|
await expect(page.getByRole('link', { name: SAVED_NAME })).toBeVisible()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.describe('Filtros salvos com LIST_UNIFIED (CL8)', () => {
|
||||||
|
test.skip(
|
||||||
|
!listUnifiedEnabled,
|
||||||
|
'Set LIST_UNIFIED=1 on the e2e webServer to run the unified-list tracer.',
|
||||||
|
)
|
||||||
|
|
||||||
|
test('saved filters stay intact behind OpsListPage', async ({ campaign, page }) => {
|
||||||
|
test.slow()
|
||||||
|
|
||||||
|
const { fixtures } = campaign
|
||||||
|
const coordinator = await fixtures.createCampaignUser('coordinator', {
|
||||||
|
name: fixtures.value('Coordenadora Filtros Unificados'),
|
||||||
|
})
|
||||||
|
|
||||||
|
await campaign.login(page, coordinator.email!, coordinator.password)
|
||||||
|
await page.goto(SAVED_RECORTE)
|
||||||
|
await page.getByRole('button', { name: 'Salvar filtro', exact: true }).click()
|
||||||
|
await page.getByLabel('Nome do filtro').fill(SAVED_NAME)
|
||||||
|
await page.getByRole('button', { name: 'Salvar', exact: true }).click()
|
||||||
|
|
||||||
|
const shortcut = page.getByRole('link', { name: SAVED_NAME })
|
||||||
|
await expect(shortcut).toBeVisible()
|
||||||
|
await shortcut.click()
|
||||||
|
await expect(page).toHaveURL(SAVED_RECORTE, NAVIGATION)
|
||||||
|
await expect(shortcut).toHaveAttribute('aria-current', 'page', NAVIGATION)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@
|
||||||
*/
|
*/
|
||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
import { parseDemandListParams } from '@/utilities/campaignDemandData'
|
import { parseDemandListParams, resolveDemandListUrl } from '@/utilities/campaignDemandData'
|
||||||
import { parseOrganizationListParams } from '@/utilities/organizationData'
|
import {
|
||||||
|
parseOrganizationListParams,
|
||||||
|
resolveOrganizationListUrl,
|
||||||
|
} from '@/utilities/organizationData'
|
||||||
|
|
||||||
describe('parseOrganizationListParams', () => {
|
describe('parseOrganizationListParams', () => {
|
||||||
it('keeps only known organization kinds', () => {
|
it('keeps only known organization kinds', () => {
|
||||||
|
|
@ -21,6 +24,14 @@ describe('parseOrganizationListParams', () => {
|
||||||
kind: 'sindicato',
|
kind: 'sindicato',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('redirects junk params to the canonical form', () => {
|
||||||
|
expect(resolveOrganizationListUrl({ foo: 'bar', q: ' cut ', page: '01' })).toEqual({
|
||||||
|
state: { page: 1, q: 'cut' },
|
||||||
|
href: '/campanha/organizacoes?q=cut',
|
||||||
|
redirectHref: '/campanha/organizacoes?q=cut',
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('parseDemandListParams', () => {
|
describe('parseDemandListParams', () => {
|
||||||
|
|
@ -34,4 +45,20 @@ describe('parseDemandListParams', () => {
|
||||||
it('defaults to page 1 with no filters', () => {
|
it('defaults to page 1 with no filters', () => {
|
||||||
expect(parseDemandListParams({})).toEqual({ page: 1 })
|
expect(parseDemandListParams({})).toEqual({ page: 1 })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('redirects junk params to the canonical form', () => {
|
||||||
|
expect(resolveDemandListUrl({ foo: 'bar', status: 'aberta', page: '01' })).toEqual({
|
||||||
|
state: { page: 1, status: 'aberta' },
|
||||||
|
href: '/campanha/demandas?status=aberta',
|
||||||
|
redirectHref: '/campanha/demandas?status=aberta',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('clamps page above totalPages', () => {
|
||||||
|
expect(resolveDemandListUrl({ page: '9' }, 2)).toEqual({
|
||||||
|
state: { page: 2 },
|
||||||
|
href: '/campanha/demandas?page=2',
|
||||||
|
redirectHref: '/campanha/demandas?page=2',
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,11 @@ describe('opsListRegistry v1', () => {
|
||||||
expect(meta?.columnListId).toBe('territorios')
|
expect(meta?.columnListId).toBe('territorios')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('pins demandas and organizacoes canonical redirect after CL8', () => {
|
||||||
|
expect(getOpsListDomain('demandas')?.canonicalRedirect).toBe(true)
|
||||||
|
expect(getOpsListDomain('organizacoes')?.canonicalRedirect).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
it('returns null for atividades (cards layout — excluded from factory)', () => {
|
it('returns null for atividades (cards layout — excluded from factory)', () => {
|
||||||
expect(getOpsListDomain('atividades')).toBeNull()
|
expect(getOpsListDomain('atividades')).toBeNull()
|
||||||
expect(getOpsListDomain('unknown-slug')).toBeNull()
|
expect(getOpsListDomain('unknown-slug')).toBeNull()
|
||||||
|
|
|
||||||
37
tests/unit/opsListRegistryRoutes.unit.spec.ts
Normal file
37
tests/unit/opsListRegistryRoutes.unit.spec.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { existsSync, readFileSync } from 'node:fs'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
import { opsListDomains, opsListRegistry } from '@/lib/opsListRegistry/opsListRegistry'
|
||||||
|
|
||||||
|
const routePagePath = (routePath: string): string => {
|
||||||
|
const segment = routePath.replace(/^\/campanha\//, '')
|
||||||
|
return join(process.cwd(), 'src/app/(campaign)/campanha/(app)', segment, 'page.tsx')
|
||||||
|
}
|
||||||
|
|
||||||
|
const expectOpsListFactoryWiring = (source: string) => {
|
||||||
|
expect(source).toContain('resolveListUnifiedEnabled')
|
||||||
|
expect(source).toContain('OpsListPage')
|
||||||
|
expect(source).toContain("from '@/components/campaign/shared/OpsListPage'")
|
||||||
|
expect(source).toContain("from '@/lib/opsListRegistry/opsListFlag'")
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('opsListRegistry v1 routes (CL8)', () => {
|
||||||
|
it.each(opsListDomains)('%s has a route page that delegates to the list factory', (slug) => {
|
||||||
|
const { routePath } = opsListRegistry[slug]
|
||||||
|
const pagePath = routePagePath(routePath)
|
||||||
|
|
||||||
|
expect(existsSync(pagePath), `missing route file for ${slug}: ${pagePath}`).toBe(true)
|
||||||
|
expectOpsListFactoryWiring(readFileSync(pagePath, 'utf8'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('maps every registry routePath under /campanha/', () => {
|
||||||
|
for (const slug of opsListDomains) {
|
||||||
|
expect(opsListRegistry[slug].routePath).toMatch(/^\/campanha\/[a-z]+$/)
|
||||||
|
expect(routePagePath(opsListRegistry[slug].routePath)).toContain(
|
||||||
|
`/campanha/(app)/${slug}/page.tsx`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in a new issue