mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +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):** **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}
|
||||
clearSearchBox={() => setSearch('')}
|
||||
onNavigate={navigateWithSearch}
|
||||
onNavigateClearingSearch={clearSearchAndNavigate}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
import { InputGroupAddon } from '@/components/ui/input-group'
|
||||
import { DEFAULT_VOTE_ESTIMATE_SCENARIO } from '@/lib/voteEstimate'
|
||||
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 { MunicipalityListState } from '@/utilities/municipality/municipalityListUrl'
|
||||
import {
|
||||
|
|
@ -37,6 +37,8 @@ type MunicipalityMobileFilterComboboxProps = {
|
|||
/** Clear the box without arming the search debounce / URL write. */
|
||||
clearSearchBox: () => 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,
|
||||
clearSearchBox,
|
||||
onNavigate,
|
||||
onNavigateClearingSearch,
|
||||
}: MunicipalityMobileFilterComboboxProps) => {
|
||||
const scenarioContext = useMunicipalityEstimateScenarioOptional()
|
||||
const scenario = scenarioContext?.scenario ?? DEFAULT_VOTE_ESTIMATE_SCENARIO
|
||||
|
|
@ -66,18 +69,24 @@ export const MunicipalityMobileFilterCombobox = ({
|
|||
scenario,
|
||||
})
|
||||
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 next = applyMunicipalityMobileFilterOption(state, option)
|
||||
if (next === 'scenario') {
|
||||
setScenario?.(option.kind === 'scenario' ? option.scenario : scenario)
|
||||
if (option.kind === 'scenario') setScenario?.(option.scenario)
|
||||
clearSearchBox()
|
||||
return
|
||||
}
|
||||
// Carry whatever is in the box as `q` (same contract as the old sort select),
|
||||
// then empty the typeahead for the next keyword.
|
||||
onNavigate(next)
|
||||
clearSearchBox()
|
||||
// Keep only the committed URL `q` — the box text may be a typeahead prefix
|
||||
// ("Prior", "Tendência"), not a município name. Drop the draft with Limpar's
|
||||
// clear path so the debounce cannot re-commit it after the pick.
|
||||
onNavigateClearingSearch({ ...next, q: state.q })
|
||||
}
|
||||
|
||||
const dismissChip = (chipId: string) => {
|
||||
|
|
@ -120,13 +129,8 @@ export const MunicipalityMobileFilterCombobox = ({
|
|||
if (option) applyOption(option)
|
||||
}}
|
||||
filter={(option, query) => {
|
||||
if (!query) return true
|
||||
// When the box is a name search (no option label matches), keep the
|
||||
// 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
|
||||
if (!query || !draftMatchesOption) return true
|
||||
return matchesAtWordStart(option.label, query)
|
||||
}}
|
||||
isItemEqualToValue={(left, right) => left?.id === right?.id}
|
||||
itemToStringLabel={(option) => option.label}
|
||||
|
|
|
|||
|
|
@ -110,16 +110,27 @@ export const buildMunicipalityMobileFilterOptions = ({
|
|||
if (definition.param === 'advisor') filterOptions = advisorFilterOptions
|
||||
if (filterOptions.length === 0) continue
|
||||
|
||||
const param: MunicipalityMultiFilterParam =
|
||||
definition.param === 'region'
|
||||
? 'region'
|
||||
: definition.param === 'advisor'
|
||||
? 'advisor'
|
||||
: definition.param === 'trend'
|
||||
? 'trend'
|
||||
: definition.param === 'class'
|
||||
? 'class'
|
||||
: 'level'
|
||||
const param = ((): MunicipalityMultiFilterParam => {
|
||||
switch (definition.param) {
|
||||
case 'region':
|
||||
return 'region'
|
||||
case 'advisor':
|
||||
return 'advisor'
|
||||
case 'trend':
|
||||
return 'trend'
|
||||
case 'class':
|
||||
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))
|
||||
for (const option of filterOptions) {
|
||||
|
|
@ -213,12 +224,25 @@ export const dismissMunicipalityMobileFilterChip = (
|
|||
state: MunicipalityListState,
|
||||
option: MunicipalityMobileFilterOption,
|
||||
): MunicipalityListState | 'scenario-default' => {
|
||||
if (option.kind === 'sort') {
|
||||
return { ...state, page: 1, sort: undefined, dir: undefined }
|
||||
switch (option.kind) {
|
||||
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',
|
||||
bareHref: '/campanha/municipios',
|
||||
sortValue: 'name|asc',
|
||||
hrefWithQueryAndSecondary: '/campanha/municipios?q=silva&priority=alta',
|
||||
hrefWithQueryAndSecondary: '/campanha/municipios?priority=alta',
|
||||
hrefWithSecondary: '/campanha/municipios?priority=alta',
|
||||
navigateSecondary: navigateViaMunicipalityPriorityOption,
|
||||
element: (currentQuery) =>
|
||||
|
|
@ -266,7 +266,7 @@ describe('campaign list filter navigation', () => {
|
|||
it.each(filterCases)(
|
||||
'$name: carries the uncommitted search when another control navigates',
|
||||
(filterCase) => {
|
||||
const { searchLabel, navigateSecondary, hrefWithQueryAndSecondary } = filterCase
|
||||
const { searchLabel, navigateSecondary, hrefWithQueryAndSecondary, name } = filterCase
|
||||
mountCase(filterCase)
|
||||
|
||||
typeSearch(searchLabel, 'silva')
|
||||
|
|
@ -277,6 +277,14 @@ describe('campaign list filter navigation', () => {
|
|||
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
|
||||
// fire a second navigation.
|
||||
advance(SEARCH_DEBOUNCE_MS)
|
||||
|
|
|
|||
Loading…
Reference in a new issue