Merge pull request #182 from fsolla/cursor/pool-i156-cc5b501f-ae59

CL2 — opsListRegistry + tipos + flag + slugs v1
This commit is contained in:
Francisco Solla 2026-08-01 19:24:54 -03:00 committed by GitHub
commit 4c16c76a2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 252 additions and 0 deletions

View file

@ -0,0 +1,11 @@
/**
* CL2 — feature flag for the unified list factory (CL3+).
*
* When disabled, existing list routes keep their current implementation.
*/
const TRUTHY = new Set(['1', 'true'])
export const resolveListUnifiedEnabled = (
env: Record<string, string | undefined> = process.env,
): boolean => TRUTHY.has(env.LIST_UNIFIED ?? '')

View file

@ -0,0 +1,125 @@
/**
* CL2 — client-safe metadata for the eight v1 campaign list domains.
*
* SSOT for slug → route/gate/sort/column-picker lives in
* `docs/plans/lista-unificada-campanha-spec.md` § Escopo travado.
* Loaders and URL parsers stay in `utilities/` — this module never imports them.
*
* `atividades` is intentionally absent: cards + tabs (Pass 2 D5) are out of scope
* for the unified list factory — `getOpsListDomain('atividades')` returns `null`.
*/
import type { CampaignListId } from '@/lib/campaignColumnVisibility'
export const opsListDomains = [
'municipios',
'liderancas',
'dobradinhas',
'demandas',
'assessores',
'territorios',
'apoiadores',
'organizacoes',
] as const
export type OpsListDomainId = (typeof opsListDomains)[number]
export type OpsListDomainMeta = {
id: OpsListDomainId
routePath: string
gate: 'staff' | 'noLeader' | 'unrestricted'
columnListId: CampaignListId | null
savedFilters: boolean
sortModel: 'url' | 'fixed' | 'memory'
canonicalRedirect: boolean
layout: 'table'
}
export const opsListRegistry: Record<OpsListDomainId, OpsListDomainMeta> = {
municipios: {
id: 'municipios',
routePath: '/campanha/municipios',
gate: 'noLeader',
columnListId: 'municipios',
savedFilters: true,
sortModel: 'url',
canonicalRedirect: true,
layout: 'table',
},
liderancas: {
id: 'liderancas',
routePath: '/campanha/liderancas',
gate: 'staff',
columnListId: 'liderancas',
savedFilters: false,
sortModel: 'url',
canonicalRedirect: true,
layout: 'table',
},
dobradinhas: {
id: 'dobradinhas',
routePath: '/campanha/dobradinhas',
gate: 'staff',
columnListId: 'dobradinhas',
savedFilters: false,
sortModel: 'url',
canonicalRedirect: true,
layout: 'table',
},
demandas: {
id: 'demandas',
routePath: '/campanha/demandas',
gate: 'staff',
columnListId: 'demandas',
savedFilters: false,
sortModel: 'fixed',
canonicalRedirect: false,
layout: 'table',
},
assessores: {
id: 'assessores',
routePath: '/campanha/assessores',
gate: 'unrestricted',
columnListId: null,
savedFilters: false,
sortModel: 'fixed',
canonicalRedirect: false,
layout: 'table',
},
territorios: {
id: 'territorios',
routePath: '/campanha/territorios',
gate: 'noLeader',
columnListId: 'territorios',
savedFilters: false,
sortModel: 'memory',
canonicalRedirect: true,
layout: 'table',
},
apoiadores: {
id: 'apoiadores',
routePath: '/campanha/apoiadores',
gate: 'staff',
columnListId: 'apoiadores',
savedFilters: false,
sortModel: 'url',
canonicalRedirect: true,
layout: 'table',
},
organizacoes: {
id: 'organizacoes',
routePath: '/campanha/organizacoes',
gate: 'staff',
columnListId: 'organizacoes',
savedFilters: false,
sortModel: 'fixed',
canonicalRedirect: false,
layout: 'table',
},
}
const isOpsListDomainId = (slug: string): slug is OpsListDomainId =>
opsListDomains.some((domainId) => domainId === slug)
export const getOpsListDomain = (slug: string): OpsListDomainMeta | null =>
isOpsListDomainId(slug) ? opsListRegistry[slug] : null

View file

@ -0,0 +1,116 @@
import { describe, expect, it } from 'vitest'
import type { CampaignListId } from '@/lib/campaignColumnVisibility'
import { resolveListUnifiedEnabled } from '@/lib/opsListRegistry/opsListFlag'
import {
getOpsListDomain,
opsListDomains,
opsListRegistry,
type OpsListDomainMeta,
} from '@/lib/opsListRegistry/opsListRegistry'
const CAMPAIGN_LIST_IDS: readonly CampaignListId[] = [
'municipios',
'liderancas',
'dobradinhas',
'organizacoes',
'demandas',
'apoiadores',
'territorios',
]
const isCampaignListId = (value: string): value is CampaignListId =>
CAMPAIGN_LIST_IDS.some((listId) => listId === value)
describe('opsListRegistry v1', () => {
it('covers exactly eight v1 slugs with matching registry entries', () => {
expect(opsListDomains).toHaveLength(8)
for (const slug of opsListDomains) {
expect(opsListRegistry[slug].id).toBe(slug)
}
})
it('keeps registry keys aligned with opsListDomains', () => {
expect(Object.keys(opsListRegistry).sort()).toEqual([...opsListDomains].sort())
})
it('matches the SSOT routePath order from lista-unificada-campanha-spec', () => {
const routePaths = opsListDomains.map((slug) => opsListRegistry[slug].routePath)
expect(routePaths).toEqual([
'/campanha/municipios',
'/campanha/liderancas',
'/campanha/dobradinhas',
'/campanha/demandas',
'/campanha/assessores',
'/campanha/territorios',
'/campanha/apoiadores',
'/campanha/organizacoes',
])
})
it.each(opsListDomains)('%s has /campanha/ routePath and table layout', (slug) => {
const meta = opsListRegistry[slug]
expect(meta.routePath.startsWith('/campanha/')).toBe(true)
expect(meta.layout).toBe('table')
expect(meta.id).toBe(slug)
})
it('pins municipios saved filters and canonical redirect', () => {
const meta = getOpsListDomain('municipios')
expect(meta).not.toBeNull()
expect(meta?.savedFilters).toBe(true)
expect(meta?.canonicalRedirect).toBe(true)
})
it('returns null for atividades (cards layout — excluded from factory)', () => {
expect(getOpsListDomain('atividades')).toBeNull()
expect(getOpsListDomain('unknown-slug')).toBeNull()
})
it('rejects invalid columnListId values at runtime', () => {
for (const slug of opsListDomains) {
const { columnListId } = opsListRegistry[slug]
if (columnListId === null) continue
expect(isCampaignListId(columnListId)).toBe(true)
}
expect(opsListRegistry.assessores.columnListId).toBeNull()
})
it('requires every meta field (no partial entries)', () => {
const requiredKeys: (keyof OpsListDomainMeta)[] = [
'id',
'routePath',
'gate',
'columnListId',
'savedFilters',
'sortModel',
'canonicalRedirect',
'layout',
]
for (const slug of opsListDomains) {
const meta = opsListRegistry[slug]
for (const key of requiredKeys) {
expect(meta[key], `${slug}.${key}`).toBeDefined()
}
}
})
})
describe('resolveListUnifiedEnabled', () => {
it('is false when LIST_UNIFIED is absent', () => {
expect(resolveListUnifiedEnabled({})).toBe(false)
expect(resolveListUnifiedEnabled({ LIST_UNIFIED: undefined })).toBe(false)
})
it('is true for "1" and "true"', () => {
expect(resolveListUnifiedEnabled({ LIST_UNIFIED: '1' })).toBe(true)
expect(resolveListUnifiedEnabled({ LIST_UNIFIED: 'true' })).toBe(true)
})
it('is false for "0" and other values', () => {
expect(resolveListUnifiedEnabled({ LIST_UNIFIED: '0' })).toBe(false)
expect(resolveListUnifiedEnabled({ LIST_UNIFIED: 'false' })).toBe(false)
expect(resolveListUnifiedEnabled({ LIST_UNIFIED: 'yes' })).toBe(false)
})
})