mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 06:13:06 +00:00
B135 — Wizard Voltar aponta ao passo anterior na cadeia
Adiciona wizardChainPreviousHref simétrico ao continue da B98 e atualiza os quatro passos raiz (votos, tendência, sinal, liderança). Sub-passos intra-fluxo permanecem inalterados. Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
parent
e4df53c47c
commit
0bbb956a46
8 changed files with 220 additions and 10 deletions
57
docs/plans/wizard-voltar-passo-anterior-cadeia-impl.md
Normal file
57
docs/plans/wizard-voltar-passo-anterior-cadeia-impl.md
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Impl: Wizard — Voltar = passo imediatamente anterior (também na cadeia)
|
||||
|
||||
Status: aprovado
|
||||
Atualizado em: 2026-08-02
|
||||
Issue: #289
|
||||
Intenção: docs/plans/wizard-voltar-passo-anterior-cadeia.md
|
||||
Appetite restante: ~0,25d (helper + 4 call sites + unit)
|
||||
|
||||
## Leitura da intenção
|
||||
|
||||
- **Outcome:** Voltar no header do wizard navega ao passo imediatamente anterior — busca de município, elo anterior na cadeia B98, ou sub-passo do mesmo fluxo.
|
||||
- **O que NÃO negociar:** matriz B98 existente; sub-passos intra-fluxo (nota/corpo) continuam com Voltar local; sem migration.
|
||||
- **O que reavaliar:** hipótese de tocar só `page.tsx` — os `previousHref` vivem nos componentes de passo; corrigir no dono `wizardActionChain` + call sites.
|
||||
|
||||
## Abordagem recomendada
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Step["Passo wizard"] --> Prev["wizardChainPreviousHref"]
|
||||
Prev --> Seq["wizardChainSessionSteps(entry)"]
|
||||
Seq --> Href["wizardHrefForChainStep / busca município"]
|
||||
```
|
||||
|
||||
**Opções consideradas:**
|
||||
|
||||
- A) Helper simétrico a `wizardChainContinueHref` em `wizardActionChain.ts`
|
||||
- B) Prop `previousHref` calculada só em `page.tsx`
|
||||
- C) Histórico em `sessionStorage`
|
||||
|
||||
**Recomendação:** **A** — mesma fonte de verdade B98; componentes já recebem `entryAction` + `municipalitySlug`.
|
||||
|
||||
**Rejeitadas:** B (page não conhece sub-modos); C (frágil, fora do padrão URL).
|
||||
|
||||
### Componentes / mudanças
|
||||
|
||||
- **`wizardChainSessionSteps` / `previousWizardChainStep` / `wizardChainPreviousHref`** (`src/lib/wizardActionChain.ts`): sequência `[entry, ...wizardChainAfter(entry)]`; índice 0 → busca município; senão `wizardHrefForChainStep` do elo anterior.
|
||||
- **Passos raiz:** `WizardExpectedVotesStep`, `WizardTrendChoiceStep`, `WizardSignalTypeStep`, `WizardLeadershipStep` — trocar `previousHref` hardcoded.
|
||||
- **Inalterados:** `WizardTrendNoteStep`, `WizardSignalBodyStep` (sub-passos); `WizardMunicipalitySearchStep` (entry).
|
||||
- **Migration:** sem migration.
|
||||
- **Testes:** estender `wizardActionChain.unit.spec.ts`.
|
||||
|
||||
## Fases verificáveis
|
||||
|
||||
1. Helper + unit pins
|
||||
2. Call sites nos quatro passos raiz
|
||||
3. `pnpm gate:fast`; `pnpm push`
|
||||
|
||||
## Rabbit holes / Não escopo
|
||||
|
||||
- Voltar dentro do formulário de liderança (grid ↔ form) — `onCancel` já cobre.
|
||||
- `register-demand` fora da cadeia B98.
|
||||
|
||||
## Aceite de engenharia
|
||||
|
||||
- [x] Aceite de produto da intenção coberto
|
||||
- [x] Invariantes AGENTS/engineering-standards
|
||||
- [x] Testes unit em `wizardActionChain`
|
||||
|
|
@ -5,6 +5,7 @@ Atualizado em: 2026-08-02
|
|||
Issue: #289
|
||||
Priority: P1
|
||||
Model: composer-2.5
|
||||
<<<<<<< HEAD
|
||||
Impeccable: B — chrome/navegação nos passos `/campanha/acoes/*` (Voltar + back do SO)
|
||||
Appetite: ~0,5–1 dia eng; um contrato de “passo anterior” coerente na cadeia B98; sem migration
|
||||
Responsável: —
|
||||
|
|
@ -92,3 +93,56 @@ Mesma regra nos outros elos: do 1º passo de um subfluxo encadeado, Voltar = úl
|
|||
- Issue B98 #106 · B110 #149 · UX-1 A5 em `fluxos-acao-primeiro-inicio.md` (stub hoje)
|
||||
- `docs/plans/encadear-ajustes-wizard.md` · `docs/plans/fluxos-acao-primeiro-inicio.md`
|
||||
- Rotas `/campanha/acoes/atualizar-votos`, `/campanha/acoes/mudar-tendencia` (e demais elos B98); `registrar-pedido` só como consumidor futuro
|
||||
=======
|
||||
Impeccable: B — chrome do wizard (header mobile B75)
|
||||
Appetite: ~0,25d eng; helper puro + pins; sem migration
|
||||
Responsável: —
|
||||
|
||||
## Design (Impeccable)
|
||||
|
||||
Âncoras: `PRODUCT.md` · B75 header · B98 encadeamento · tema `campaign`.
|
||||
|
||||
Brief:
|
||||
|
||||
- **Persona:** staff no meio do wizard (principal ou encadeado).
|
||||
- **Job principal:** **Voltar** no header leva ao **passo imediatamente anterior** do ritual — busca de município, ajuste anterior na cadeia B98, ou sub-passo do mesmo fluxo (ex. nota → escolha de tendência).
|
||||
- **Anti-goals:** Voltar pular para busca de município quando o passo anterior é outro ajuste já visitado; Voltar para o mesmo passo (bug atual em tendência); gesture-only back.
|
||||
|
||||
### Wireframe (texto)
|
||||
|
||||
```text
|
||||
Cadeia votos → tendência → sinal (entry=update-votes):
|
||||
|
||||
[Voltar] em sinal → tendência (último passo)
|
||||
[Voltar] em tendência → votos (principal)
|
||||
[Voltar] em votos → busca município
|
||||
|
||||
Sub-fluxo tendência (escolha → nota):
|
||||
|
||||
[Voltar] em nota → escolha (mesmo fluxo)
|
||||
```
|
||||
|
||||
## Contexto
|
||||
|
||||
B98 encadeia ajustes após a principal; B75/B96 definem chrome com **Voltar** nas etapas `continue`. Hoje vários passos usam `wizardActionHref(slug, undefined)` ou `wizardActionHref(slug, municipio)` como `previousHref`, o que **ignora a fila** — ex. em tendência encadeada após votos, Voltar deveria ir a votos, não à busca de município; em escolha de tendência, `previousHref` com `municipio` aponta para o **mesmo** passo.
|
||||
|
||||
## Objetivos
|
||||
|
||||
- Helper puro `wizardChainPreviousHref` (ou equivalente no dono `wizardActionChain.ts`) derivado da mesma matriz B98 que `wizardChainContinueHref`.
|
||||
- Atualizar passos **raiz** de cada fluxo encadeável (votos, escolha tendência, tipo sinal, grid liderança) para usar o helper.
|
||||
- Sub-passos intra-fluxo (nota, corpo sinal) mantêm Voltar ao sub-passo anterior **dentro** do fluxo.
|
||||
- Unit pins na matriz anterior/continuar simétrica.
|
||||
|
||||
## Decisões travadas
|
||||
|
||||
- **Dono = `wizardActionChain.ts`.** Reusa `wizardChainAfter` / `resolveWizardChainEntry`; não duplicar matriz. **Rejeitado:** `previousHref` ad hoc por componente.
|
||||
- **Principal → busca município; encadeado → elo anterior.** **Rejeitado:** sempre Início; sempre busca município.
|
||||
- **Sem migration / sem server.**
|
||||
|
||||
## Aceite
|
||||
|
||||
- [ ] Voltar no passo encadeado N leva ao passo N−1 da sessão (principal + fila B98).
|
||||
- [ ] Voltar na principal leva à busca de município (com `entry` preservado quando houver).
|
||||
- [ ] Sub-passos (nota/corpo) inalterados na semântica intra-fluxo.
|
||||
- [ ] `pnpm gate:fast` verde.
|
||||
>>>>>>> befa3a8c (B135 — Wizard Voltar aponta ao passo anterior na cadeia)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import {
|
|||
} from '@/components/ui/Drawer'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import type { CampaignWizardActionId } from '@/lib/campaignActionRoutes'
|
||||
import { wizardActionHref } from '@/lib/campaignActionRoutes'
|
||||
import { recordLastActedMunicipality } from '@/lib/campaignLastActedMunicipality'
|
||||
import {
|
||||
WIZARD_LEADERSHIP_ADD_TILE_LABEL,
|
||||
|
|
@ -39,6 +38,7 @@ import {
|
|||
resolveWizardChainEntry,
|
||||
wizardChainContinueHref,
|
||||
wizardChainEndHref,
|
||||
wizardChainPreviousHref,
|
||||
} from '@/lib/wizardActionChain'
|
||||
import {
|
||||
resolveWizardLeadershipSkip,
|
||||
|
|
@ -129,7 +129,12 @@ export const WizardLeadershipStep = ({
|
|||
flowTitle={wizardFlowTitleForSlug(actionSlug)}
|
||||
stepTitle={stepTitle}
|
||||
isEntryStep={false}
|
||||
previousHref={wizardActionHref(actionSlug, undefined, { returnPath })}
|
||||
previousHref={wizardChainPreviousHref(
|
||||
entryAction,
|
||||
'update-leadership',
|
||||
municipalitySlug,
|
||||
returnPath,
|
||||
)}
|
||||
dismissHref={wizardChainEndHref(returnPath)}
|
||||
municipalityLabel={municipalityName}
|
||||
skip={skipConfig}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
DrawerTitle,
|
||||
} from '@/components/ui/Drawer'
|
||||
import type { CampaignWizardActionId } from '@/lib/campaignActionRoutes'
|
||||
import { wizardActionHref, wizardSignalHref } from '@/lib/campaignActionRoutes'
|
||||
import { wizardSignalHref } from '@/lib/campaignActionRoutes'
|
||||
import { wizardFlowTitleForSlug } from '@/lib/campaignWizardCopy'
|
||||
import {
|
||||
municipalitySignalTypeMeta,
|
||||
|
|
@ -25,7 +25,7 @@ import {
|
|||
} from '@/lib/municipalitySignalTypeMeta'
|
||||
import type { MunicipalitySignalType } from '@/lib/schemas/municipalityUpdate'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { wizardChainEndHref } from '@/lib/wizardActionChain'
|
||||
import { wizardChainEndHref, wizardChainPreviousHref } from '@/lib/wizardActionChain'
|
||||
import { resolveWizardSignalSkip, WIZARD_SIGNAL_TYPE_STEP_TITLE } from '@/lib/wizardSignalUi'
|
||||
|
||||
type WizardSignalTypeStepProps = {
|
||||
|
|
@ -53,7 +53,12 @@ export const WizardSignalTypeStep = ({
|
|||
flowTitle={wizardFlowTitleForSlug(actionSlug)}
|
||||
isEntryStep={false}
|
||||
stepTitle={WIZARD_SIGNAL_TYPE_STEP_TITLE}
|
||||
previousHref={wizardActionHref(actionSlug, undefined, { returnPath })}
|
||||
previousHref={wizardChainPreviousHref(
|
||||
entryAction,
|
||||
'register-signal',
|
||||
municipalitySlug,
|
||||
returnPath,
|
||||
)}
|
||||
dismissHref={wizardChainEndHref(returnPath)}
|
||||
municipalityLabel={municipalityName}
|
||||
contentAlign="end"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
DrawerTitle,
|
||||
} from '@/components/ui/Drawer'
|
||||
import type { CampaignWizardActionId } from '@/lib/campaignActionRoutes'
|
||||
import { wizardActionHref, wizardTrendHref } from '@/lib/campaignActionRoutes'
|
||||
import { wizardTrendHref } from '@/lib/campaignActionRoutes'
|
||||
import { wizardFlowTitleForSlug } from '@/lib/campaignWizardCopy'
|
||||
import {
|
||||
politicalTrendWizardMetaByStatus,
|
||||
|
|
@ -30,7 +30,7 @@ import {
|
|||
} from '@/lib/politicalTrendWizardUi'
|
||||
import type { PoliticalTrendStatusValue } from '@/lib/schemas/municipality'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { wizardChainEndHref } from '@/lib/wizardActionChain'
|
||||
import { wizardChainEndHref, wizardChainPreviousHref } from '@/lib/wizardActionChain'
|
||||
|
||||
type WizardTrendChoiceStepProps = {
|
||||
actionSlug: string
|
||||
|
|
@ -61,7 +61,12 @@ export const WizardTrendChoiceStep = ({
|
|||
flowTitle={wizardFlowTitleForSlug(actionSlug)}
|
||||
isEntryStep={false}
|
||||
stepTitle={wizardTrendChoiceStepTitle(currentStatus)}
|
||||
previousHref={wizardActionHref(actionSlug, municipalitySlug, { entryAction, returnPath })}
|
||||
previousHref={wizardChainPreviousHref(
|
||||
entryAction,
|
||||
'change-trend',
|
||||
municipalitySlug,
|
||||
returnPath,
|
||||
)}
|
||||
dismissHref={wizardChainEndHref(returnPath)}
|
||||
municipalityLabel={municipalityName}
|
||||
skip={skip}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import { Alert, AlertDescription } from '@/components/ui/Alert'
|
|||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/Spinner'
|
||||
import type { CampaignWizardActionId } from '@/lib/campaignActionRoutes'
|
||||
import { wizardActionHref } from '@/lib/campaignActionRoutes'
|
||||
import { postCampaignJson } from '@/lib/campaignJsonRequest'
|
||||
import { recordLastActedMunicipality } from '@/lib/campaignLastActedMunicipality'
|
||||
import {
|
||||
|
|
@ -31,6 +30,7 @@ import {
|
|||
resolveWizardChainEntry,
|
||||
wizardChainContinueHref,
|
||||
wizardChainEndHref,
|
||||
wizardChainPreviousHref,
|
||||
} from '@/lib/wizardActionChain'
|
||||
import {
|
||||
applyVoteShortcut,
|
||||
|
|
@ -138,7 +138,12 @@ export const WizardExpectedVotesStep = ({
|
|||
flowTitle={wizardFlowTitleForSlug(actionSlug)}
|
||||
stepTitle={wizardNextStepTitle(actionSlug)}
|
||||
isEntryStep={false}
|
||||
previousHref={wizardActionHref(actionSlug, undefined, { returnPath })}
|
||||
previousHref={wizardChainPreviousHref(
|
||||
entryAction,
|
||||
'update-votes',
|
||||
municipalitySlug,
|
||||
returnPath,
|
||||
)}
|
||||
dismissHref={wizardChainEndHref(returnPath)}
|
||||
municipalityLabel={municipalityName}
|
||||
skip={skip}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,26 @@ export const nextWizardChainStep = (
|
|||
completedAction: WizardChainActionId,
|
||||
): WizardChainActionId | undefined => wizardChainAfter(entryAction, completedAction)[0]
|
||||
|
||||
/** Principal plus remaining queue — the ordered session (B98). */
|
||||
export const wizardChainSessionSteps = (
|
||||
entryAction: WizardChainActionId,
|
||||
): readonly WizardChainActionId[] => [entryAction, ...wizardChainAfter(entryAction)]
|
||||
|
||||
export type WizardChainPreviousTarget = WizardChainActionId | 'municipality-search'
|
||||
|
||||
/** Step immediately before `currentAction` in a B98 session, or municipality search at the principal. */
|
||||
export const previousWizardChainStep = (
|
||||
entryAction: WizardChainActionId,
|
||||
currentAction: WizardChainActionId,
|
||||
): WizardChainPreviousTarget => {
|
||||
const steps = wizardChainSessionSteps(entryAction)
|
||||
const index = steps.indexOf(currentAction)
|
||||
if (index <= 0) {
|
||||
return 'municipality-search'
|
||||
}
|
||||
return steps[index - 1]
|
||||
}
|
||||
|
||||
const wizardHrefForChainStep = (
|
||||
action: WizardChainActionId,
|
||||
municipalitySlug: string,
|
||||
|
|
@ -109,3 +129,24 @@ export const resolveWizardChainEntry = (
|
|||
entryAction: CampaignWizardActionId | undefined,
|
||||
currentAction: WizardChainActionId,
|
||||
): WizardChainActionId => (isWizardChainActionId(entryAction) ? entryAction : currentAction)
|
||||
|
||||
/**
|
||||
* Href for the wizard header Voltar on a root step of a chainable flow (B135).
|
||||
* Sub-steps (trend note, signal body) keep intra-flow previous links.
|
||||
*/
|
||||
export const wizardChainPreviousHref = (
|
||||
entryAction: CampaignWizardActionId | undefined,
|
||||
currentAction: WizardChainActionId,
|
||||
municipalitySlug: string,
|
||||
returnPath?: string,
|
||||
): string => {
|
||||
const sessionEntry = resolveWizardChainEntry(entryAction, currentAction)
|
||||
const previous = previousWizardChainStep(sessionEntry, currentAction)
|
||||
|
||||
if (previous === 'municipality-search') {
|
||||
const entrySlug = CAMPAIGN_WIZARD_ACTION_SLUGS[sessionEntry]
|
||||
return wizardActionHref(entrySlug, undefined, { entryAction: sessionEntry, returnPath })
|
||||
}
|
||||
|
||||
return wizardHrefForChainStep(previous, municipalitySlug, sessionEntry, returnPath)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ import { CAMPAIGN_HOME } from '@/lib/campaignPaths'
|
|||
import {
|
||||
isWizardChainActionId,
|
||||
nextWizardChainStep,
|
||||
previousWizardChainStep,
|
||||
resolveWizardChainEntry,
|
||||
wizardChainAfter,
|
||||
wizardChainContinueHref,
|
||||
wizardChainPreviousHref,
|
||||
wizardChainSessionSteps,
|
||||
} from '@/lib/wizardActionChain'
|
||||
|
||||
describe('wizardActionChain', () => {
|
||||
|
|
@ -87,4 +90,39 @@ describe('wizardActionChain', () => {
|
|||
expect(resolveWizardChainEntry('register-signal', 'update-votes')).toBe('register-signal')
|
||||
expect(resolveWizardChainEntry('register-demand', 'change-trend')).toBe('change-trend')
|
||||
})
|
||||
|
||||
it('lists session steps as principal then queue', () => {
|
||||
expect(wizardChainSessionSteps('update-votes')).toEqual([
|
||||
'update-votes',
|
||||
'change-trend',
|
||||
'register-signal',
|
||||
'update-leadership',
|
||||
])
|
||||
})
|
||||
|
||||
it('resolves the previous step in a session', () => {
|
||||
expect(previousWizardChainStep('update-votes', 'update-votes')).toBe('municipality-search')
|
||||
expect(previousWizardChainStep('update-votes', 'change-trend')).toBe('update-votes')
|
||||
expect(previousWizardChainStep('update-votes', 'register-signal')).toBe('change-trend')
|
||||
expect(previousWizardChainStep('register-signal', 'update-votes')).toBe('change-trend')
|
||||
})
|
||||
|
||||
it('builds previous hrefs for principal and chained steps', () => {
|
||||
expect(wizardChainPreviousHref(undefined, 'update-votes', 'cairu')).toBe(
|
||||
`${CAMPAIGN_ACTIONS_HOME}/atualizar-votos?entry=update-votes`,
|
||||
)
|
||||
expect(wizardChainPreviousHref('update-votes', 'change-trend', 'cairu')).toBe(
|
||||
`${CAMPAIGN_ACTIONS_HOME}/atualizar-votos?municipio=cairu&entry=update-votes`,
|
||||
)
|
||||
expect(wizardChainPreviousHref('update-votes', 'register-signal', 'cairu')).toBe(
|
||||
`${CAMPAIGN_ACTIONS_HOME}/mudar-tendencia?municipio=cairu&entry=update-votes`,
|
||||
)
|
||||
expect(wizardChainPreviousHref('update-votes', 'update-leadership', 'cairu')).toBe(
|
||||
`${CAMPAIGN_ACTIONS_HOME}/registrar-sinal?municipio=cairu&entry=update-votes`,
|
||||
)
|
||||
const origin = '/campanha/municipios/cairu'
|
||||
expect(wizardChainPreviousHref('update-votes', 'change-trend', 'cairu', origin)).toBe(
|
||||
`${CAMPAIGN_ACTIONS_HOME}/atualizar-votos?municipio=cairu&entry=update-votes&from=${encodeURIComponent(origin)}`,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue