mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-28 07:33:05 +00:00
fix(campanha): B120 simplify — option pick must not commit typeahead as q
Keep only committed URL q on filter picks, exhaust multi-param mapping, and document the municípios secondary-nav contract in unit tests. Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
parent
ad23e9f4c7
commit
f97618524b
5 changed files with 69 additions and 30 deletions
|
|
@ -4,6 +4,8 @@ Conteúdo movido do `AGENTS.md` em 2026-07-30 (fatiamento do paradigma de agente
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
**Recently resolved (2026-08-02):** **B120** (Issue #207) — municípios mobile: combobox multi-filtro (chips + typeahead) no lugar da pilha NativeSelect; overview KPI + aviso de sort só em `md+`; cards densificados (cobertura/nível + controles compactos). URL B18 intacta. Plano: [`municipios-mobile-filtro-combobox-densificar.md`](docs/plans/municipios-mobile-filtro-combobox-densificar.md).
|
||||||
|
|
||||||
**Recently resolved (2026-08-02):** **OH10** (Issue #171) — writes municipality staff CAS (`baseUpdatedAt`) + outbox irmão (`opsMunicipalityOutbox`) para municipalityUpdate, declareVotes, tendência, engagement e advisors; flag OFF mantém caminhos actuais. Plano: [`oh10-municipality-writes-cas.md`](docs/plans/oh10-municipality-writes-cas.md).
|
**Recently resolved (2026-08-02):** **OH10** (Issue #171) — writes municipality staff CAS (`baseUpdatedAt`) + outbox irmão (`opsMunicipalityOutbox`) para municipalityUpdate, declareVotes, tendência, engagement e advisors; flag OFF mantém caminhos actuais. Plano: [`oh10-municipality-writes-cas.md`](docs/plans/oh10-municipality-writes-cas.md).
|
||||||
|
|
||||||
**Recently resolved (2026-08-02):** **OH9** (Issue #172) — detalhe de município dual-path: `MunicipalityDetailHeaderView` partilhado; `OfflineBoundary` (SSR=RSC; offline+`OPS_HYBRID`→Local); `MunicipalityDetailLocal` lê mirror (município + pledges×leaderships); regiões online-only com “Disponível quando estiveres online.”; e2e `campaignOpsOffline` (skip sem flag). Plano: [`oh9-municipio-detalhe-dualpath.md`](docs/plans/oh9-municipio-detalhe-dualpath.md).
|
**Recently resolved (2026-08-02):** **OH9** (Issue #172) — detalhe de município dual-path: `MunicipalityDetailHeaderView` partilhado; `OfflineBoundary` (SSR=RSC; offline+`OPS_HYBRID`→Local); `MunicipalityDetailLocal` lê mirror (município + pledges×leaderships); regiões online-only com “Disponível quando estiveres online.”; e2e `campaignOpsOffline` (skip sem flag). Plano: [`oh9-municipio-detalhe-dualpath.md`](docs/plans/oh9-municipio-detalhe-dualpath.md).
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ export const MunicipalityFilters = ({
|
||||||
onSearchChange={onSearchChange}
|
onSearchChange={onSearchChange}
|
||||||
clearSearchBox={() => setSearch('')}
|
clearSearchBox={() => setSearch('')}
|
||||||
onNavigate={navigateWithSearch}
|
onNavigate={navigateWithSearch}
|
||||||
|
onNavigateClearingSearch={clearSearchAndNavigate}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import {
|
||||||
import { InputGroupAddon } from '@/components/ui/input-group'
|
import { InputGroupAddon } from '@/components/ui/input-group'
|
||||||
import { DEFAULT_VOTE_ESTIMATE_SCENARIO } from '@/lib/voteEstimate'
|
import { DEFAULT_VOTE_ESTIMATE_SCENARIO } from '@/lib/voteEstimate'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { matchesAtWordStart } from '@/lib/wordStartFilter'
|
import { matchesAtWordStart, normalizeSearchPhrase } from '@/lib/wordStartFilter'
|
||||||
import type { MunicipalityFilterOption } from '@/utilities/municipality/municipalityListFilters'
|
import type { MunicipalityFilterOption } from '@/utilities/municipality/municipalityListFilters'
|
||||||
import type { MunicipalityListState } from '@/utilities/municipality/municipalityListUrl'
|
import type { MunicipalityListState } from '@/utilities/municipality/municipalityListUrl'
|
||||||
import {
|
import {
|
||||||
|
|
@ -37,6 +37,8 @@ type MunicipalityMobileFilterComboboxProps = {
|
||||||
/** Clear the box without arming the search debounce / URL write. */
|
/** Clear the box without arming the search debounce / URL write. */
|
||||||
clearSearchBox: () => void
|
clearSearchBox: () => void
|
||||||
onNavigate: (next: MunicipalityListState) => void
|
onNavigate: (next: MunicipalityListState) => void
|
||||||
|
/** Drop draft search and navigate (option pick — typeahead text must not become `q`). */
|
||||||
|
onNavigateClearingSearch: (next: MunicipalityListState) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,6 +55,7 @@ export const MunicipalityMobileFilterCombobox = ({
|
||||||
onSearchChange,
|
onSearchChange,
|
||||||
clearSearchBox,
|
clearSearchBox,
|
||||||
onNavigate,
|
onNavigate,
|
||||||
|
onNavigateClearingSearch,
|
||||||
}: MunicipalityMobileFilterComboboxProps) => {
|
}: MunicipalityMobileFilterComboboxProps) => {
|
||||||
const scenarioContext = useMunicipalityEstimateScenarioOptional()
|
const scenarioContext = useMunicipalityEstimateScenarioOptional()
|
||||||
const scenario = scenarioContext?.scenario ?? DEFAULT_VOTE_ESTIMATE_SCENARIO
|
const scenario = scenarioContext?.scenario ?? DEFAULT_VOTE_ESTIMATE_SCENARIO
|
||||||
|
|
@ -66,18 +69,24 @@ export const MunicipalityMobileFilterCombobox = ({
|
||||||
scenario,
|
scenario,
|
||||||
})
|
})
|
||||||
const chips = buildMunicipalityMobileFilterChips(state, options)
|
const chips = buildMunicipalityMobileFilterChips(state, options)
|
||||||
|
// One scan per keystroke: when the draft matches no option label it is a name
|
||||||
|
// search — keep the full catalog so a filter can still be picked.
|
||||||
|
const normalizedDraft = normalizeSearchPhrase(search)
|
||||||
|
const draftMatchesOption = normalizedDraft
|
||||||
|
? options.some((option) => matchesAtWordStart(option.label, search))
|
||||||
|
: false
|
||||||
|
|
||||||
const applyOption = (option: MunicipalityMobileFilterOption) => {
|
const applyOption = (option: MunicipalityMobileFilterOption) => {
|
||||||
const next = applyMunicipalityMobileFilterOption(state, option)
|
const next = applyMunicipalityMobileFilterOption(state, option)
|
||||||
if (next === 'scenario') {
|
if (next === 'scenario') {
|
||||||
setScenario?.(option.kind === 'scenario' ? option.scenario : scenario)
|
if (option.kind === 'scenario') setScenario?.(option.scenario)
|
||||||
clearSearchBox()
|
clearSearchBox()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Carry whatever is in the box as `q` (same contract as the old sort select),
|
// Keep only the committed URL `q` — the box text may be a typeahead prefix
|
||||||
// then empty the typeahead for the next keyword.
|
// ("Prior", "Tendência"), not a município name. Drop the draft with Limpar's
|
||||||
onNavigate(next)
|
// clear path so the debounce cannot re-commit it after the pick.
|
||||||
clearSearchBox()
|
onNavigateClearingSearch({ ...next, q: state.q })
|
||||||
}
|
}
|
||||||
|
|
||||||
const dismissChip = (chipId: string) => {
|
const dismissChip = (chipId: string) => {
|
||||||
|
|
@ -120,13 +129,8 @@ export const MunicipalityMobileFilterCombobox = ({
|
||||||
if (option) applyOption(option)
|
if (option) applyOption(option)
|
||||||
}}
|
}}
|
||||||
filter={(option, query) => {
|
filter={(option, query) => {
|
||||||
if (!query) return true
|
if (!query || !draftMatchesOption) return true
|
||||||
// When the box is a name search (no option label matches), keep the
|
return matchesAtWordStart(option.label, query)
|
||||||
// full catalog so a filter can still be picked while `q` is pending.
|
|
||||||
const anyMatch = options.some((candidate) =>
|
|
||||||
matchesAtWordStart(candidate.label, query),
|
|
||||||
)
|
|
||||||
return anyMatch ? matchesAtWordStart(option.label, query) : true
|
|
||||||
}}
|
}}
|
||||||
isItemEqualToValue={(left, right) => left?.id === right?.id}
|
isItemEqualToValue={(left, right) => left?.id === right?.id}
|
||||||
itemToStringLabel={(option) => option.label}
|
itemToStringLabel={(option) => option.label}
|
||||||
|
|
|
||||||
|
|
@ -110,16 +110,27 @@ export const buildMunicipalityMobileFilterOptions = ({
|
||||||
if (definition.param === 'advisor') filterOptions = advisorFilterOptions
|
if (definition.param === 'advisor') filterOptions = advisorFilterOptions
|
||||||
if (filterOptions.length === 0) continue
|
if (filterOptions.length === 0) continue
|
||||||
|
|
||||||
const param: MunicipalityMultiFilterParam =
|
const param = ((): MunicipalityMultiFilterParam => {
|
||||||
definition.param === 'region'
|
switch (definition.param) {
|
||||||
? 'region'
|
case 'region':
|
||||||
: definition.param === 'advisor'
|
return 'region'
|
||||||
? 'advisor'
|
case 'advisor':
|
||||||
: definition.param === 'trend'
|
return 'advisor'
|
||||||
? 'trend'
|
case 'trend':
|
||||||
: definition.param === 'class'
|
return 'trend'
|
||||||
? 'class'
|
case 'class':
|
||||||
: 'level'
|
return 'class'
|
||||||
|
case 'level':
|
||||||
|
return 'level'
|
||||||
|
case 'name':
|
||||||
|
case 'coverage':
|
||||||
|
throw new Error(`Unexpected multi filter param: ${definition.param}`)
|
||||||
|
default: {
|
||||||
|
const _exhaustive: never = definition.param
|
||||||
|
return _exhaustive
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
const selected = new Set(getMunicipalityMultiFilterValues(state, param))
|
const selected = new Set(getMunicipalityMultiFilterValues(state, param))
|
||||||
for (const option of filterOptions) {
|
for (const option of filterOptions) {
|
||||||
|
|
@ -213,12 +224,25 @@ export const dismissMunicipalityMobileFilterChip = (
|
||||||
state: MunicipalityListState,
|
state: MunicipalityListState,
|
||||||
option: MunicipalityMobileFilterOption,
|
option: MunicipalityMobileFilterOption,
|
||||||
): MunicipalityListState | 'scenario-default' => {
|
): MunicipalityListState | 'scenario-default' => {
|
||||||
if (option.kind === 'sort') {
|
switch (option.kind) {
|
||||||
return { ...state, page: 1, sort: undefined, dir: undefined }
|
case 'sort':
|
||||||
|
return { ...state, page: 1, sort: undefined, dir: undefined }
|
||||||
|
case 'scenario':
|
||||||
|
return 'scenario-default'
|
||||||
|
case 'priority':
|
||||||
|
case 'multi':
|
||||||
|
case 'coverage': {
|
||||||
|
const next = applyMunicipalityMobileFilterOption(state, option)
|
||||||
|
if (next === 'scenario') {
|
||||||
|
throw new Error(`Unexpected scenario result for ${option.kind}`)
|
||||||
|
}
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
const _exhaustive: never = option
|
||||||
|
return _exhaustive
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (option.kind === 'scenario') return 'scenario-default'
|
|
||||||
const next = applyMunicipalityMobileFilterOption(state, option)
|
|
||||||
return next === 'scenario' ? state : next
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ const filterCases: FilterCase[] = [
|
||||||
hrefWithQuery: '/campanha/municipios?q=silva',
|
hrefWithQuery: '/campanha/municipios?q=silva',
|
||||||
bareHref: '/campanha/municipios',
|
bareHref: '/campanha/municipios',
|
||||||
sortValue: 'name|asc',
|
sortValue: 'name|asc',
|
||||||
hrefWithQueryAndSecondary: '/campanha/municipios?q=silva&priority=alta',
|
hrefWithQueryAndSecondary: '/campanha/municipios?priority=alta',
|
||||||
hrefWithSecondary: '/campanha/municipios?priority=alta',
|
hrefWithSecondary: '/campanha/municipios?priority=alta',
|
||||||
navigateSecondary: navigateViaMunicipalityPriorityOption,
|
navigateSecondary: navigateViaMunicipalityPriorityOption,
|
||||||
element: (currentQuery) =>
|
element: (currentQuery) =>
|
||||||
|
|
@ -266,7 +266,7 @@ describe('campaign list filter navigation', () => {
|
||||||
it.each(filterCases)(
|
it.each(filterCases)(
|
||||||
'$name: carries the uncommitted search when another control navigates',
|
'$name: carries the uncommitted search when another control navigates',
|
||||||
(filterCase) => {
|
(filterCase) => {
|
||||||
const { searchLabel, navigateSecondary, hrefWithQueryAndSecondary } = filterCase
|
const { searchLabel, navigateSecondary, hrefWithQueryAndSecondary, name } = filterCase
|
||||||
mountCase(filterCase)
|
mountCase(filterCase)
|
||||||
|
|
||||||
typeSearch(searchLabel, 'silva')
|
typeSearch(searchLabel, 'silva')
|
||||||
|
|
@ -277,6 +277,14 @@ describe('campaign list filter navigation', () => {
|
||||||
scroll: false,
|
scroll: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Municípios B120: a combobox pick must NOT commit the typeahead draft as
|
||||||
|
// `q` (prefix text ≠ município name). Other shells still carry the draft.
|
||||||
|
if (name !== 'municípios') {
|
||||||
|
expect(hrefWithQueryAndSecondary).toContain('q=silva')
|
||||||
|
} else {
|
||||||
|
expect(hrefWithQueryAndSecondary).not.toContain('q=')
|
||||||
|
}
|
||||||
|
|
||||||
// The secondary control consumed the pending search; the timer must not
|
// The secondary control consumed the pending search; the timer must not
|
||||||
// fire a second navigation.
|
// fire a second navigation.
|
||||||
advance(SEARCH_DEBOUNCE_MS)
|
advance(SEARCH_DEBOUNCE_MS)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue