mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 10:43:07 +00:00
Collection actionPlan -> activity (labels "Atividade"/"Atividades"), campo
campaignDemand.actionPlan -> activity, rota /campanha/planos ->
/campanha/atividades (criacao em atividades/nova), sidebar "Atividades" e
rotulos alinhados a entidade ("Tipo de atividade", "Origem da atividade",
"Resultado da atividade"). Valores de enum kind/status/origin inalterados.
Schema movido por migration data-preserving escrita a mao
(20260725_213000_rename_action_plan_to_activity): 4 tabelas, 3 enums, 2
colunas, 39 indices (4 pkeys inclusos), 14 FKs e 2 sequences, cada statement
guardado na existencia do objeto de origem, com down() simetrico. O gerador do
Payload emitiria DROP+CREATE e nao ve o indice parcial escrito a mao
action_plan_upcoming_start_at_idx, entao a lista veio de
pg_indexes/pg_constraint/pg_type/pg_sequences e o snapshot .json foi derivado
do anterior por transformacao textual -- validado por migrate:create __probe
sem mudanca de schema. A mesma migration alinha os 8 indices fosseis %plaza%
que a remodelagem de municipios deixou (renomeou as colunas plaza_id, nao os
indices).
Guard: o describe "banned campaign terminology" de
codebaseConventions.unit.spec.ts virou tabela de termos varrendo src+tests+
scripts (migrations fora -- historia congelada), banindo os compostos
actionPlan, a copy "plano de acao" e a rota antiga, mas nao plan/plano isolado
(colidiria com os planos de assinatura da Fase 2). Allowlist: o proprio spec,
scripts/generate-remodel-municipalities-migration.mjs e o comentario historico
em campaignMigrationReconciliation.int.spec.ts.
Plano: docs/plans/renomear-plano-acao-para-atividade.md
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
/**
|
|
* Shared factory behind the detail-page tab helpers (município, atividade):
|
|
* querystring-tab resolution with per-tab preserved params and
|
|
* canonical hrefs. Each detail page declares its config in its own
|
|
* `*DetailTabUi.ts` module and re-exports the generated helpers.
|
|
*/
|
|
export type DetailTabSearchParams = Record<string, string | string[] | undefined>
|
|
|
|
const firstValue = (value: string | string[] | undefined): string | undefined =>
|
|
Array.isArray(value) ? value[0] : value
|
|
|
|
const appendQueryValue = (
|
|
params: URLSearchParams,
|
|
key: string,
|
|
value: string | string[] | undefined,
|
|
) => {
|
|
for (const item of Array.isArray(value) ? value : [value]) {
|
|
if (item !== undefined) params.append(key, item)
|
|
}
|
|
}
|
|
|
|
export const createDetailTabHelpers = <Tab extends string>({
|
|
tabs,
|
|
defaultTab,
|
|
tabQueryKeys,
|
|
basePath,
|
|
forcedTab,
|
|
}: {
|
|
tabs: readonly Tab[]
|
|
defaultTab: Tab
|
|
/** Query params each tab preserves when linked to. */
|
|
tabQueryKeys: Record<Tab, readonly string[]>
|
|
basePath: (slug: string) => string
|
|
/** Params that force a tab regardless of `?tab=` (e.g. `?newUpdate=1`). */
|
|
forcedTab?: (searchParams: DetailTabSearchParams) => Tab | null
|
|
}) => {
|
|
const isAllowedTab = (value: string | undefined): value is Tab => tabs.includes(value as Tab)
|
|
|
|
const resolveTab = (searchParams: DetailTabSearchParams): Tab => {
|
|
const forced = forcedTab?.(searchParams)
|
|
if (forced) return forced
|
|
|
|
const requestedTab = firstValue(searchParams.tab)
|
|
return isAllowedTab(requestedTab) ? requestedTab : defaultTab
|
|
}
|
|
|
|
const buildTabHref = (slug: string, tab: Tab, searchParams: DetailTabSearchParams): string => {
|
|
const params = new URLSearchParams()
|
|
for (const key of tabQueryKeys[tab]) {
|
|
appendQueryValue(params, key, searchParams[key])
|
|
}
|
|
params.set('tab', tab)
|
|
|
|
return `${basePath(slug)}?${params.toString()}`
|
|
}
|
|
|
|
const getTabRedirect = (slug: string, searchParams: DetailTabSearchParams): string | null => {
|
|
const activeTab = resolveTab(searchParams)
|
|
const requestedTab = searchParams.tab
|
|
if (typeof requestedTab === 'string' && requestedTab === activeTab) return null
|
|
|
|
return buildTabHref(slug, activeTab, searchParams)
|
|
}
|
|
|
|
return { resolveTab, buildTabHref, getTabRedirect }
|
|
}
|