mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-21 02:53:06 +00:00
fix: restore searchOnlyListOmnibox exports from main (CI merge)
This commit is contained in:
parent
519721cbfd
commit
0d124b47cb
2 changed files with 51 additions and 1 deletions
|
|
@ -2,7 +2,11 @@
|
||||||
* Degenerate omnibox for lists that only expose free-text search (B128:
|
* Degenerate omnibox for lists that only expose free-text search (B128:
|
||||||
* organizações). Pure / client-safe.
|
* organizações). Pure / client-safe.
|
||||||
*/
|
*/
|
||||||
import { type CampaignListOmniboxChip } from '@/lib/campaignListOmnibox'
|
import {
|
||||||
|
filterOmniboxSuggestionSeeds,
|
||||||
|
type CampaignListOmniboxChip,
|
||||||
|
type CampaignListOmniboxSuggestion,
|
||||||
|
} from '@/lib/campaignListOmnibox'
|
||||||
|
|
||||||
export type SearchOnlyListState = {
|
export type SearchOnlyListState = {
|
||||||
q?: string
|
q?: string
|
||||||
|
|
@ -19,6 +23,9 @@ export const buildSearchOnlyOmniboxChips = (
|
||||||
state: SearchOnlyListState,
|
state: SearchOnlyListState,
|
||||||
): CampaignListOmniboxChip[] => (state.q ? [{ id: 'q', label: chipLabel('Busca', state.q) }] : [])
|
): CampaignListOmniboxChip[] => (state.q ? [{ id: 'q', label: chipLabel('Busca', state.q) }] : [])
|
||||||
|
|
||||||
|
export const buildSearchOnlyOmniboxSuggestions = (query: string): CampaignListOmniboxSuggestion[] =>
|
||||||
|
filterOmniboxSuggestionSeeds([], query)
|
||||||
|
|
||||||
export const applySearchOnlyOmniboxSuggestion = <T extends SearchOnlyListState>({
|
export const applySearchOnlyOmniboxSuggestion = <T extends SearchOnlyListState>({
|
||||||
state,
|
state,
|
||||||
suggestionId,
|
suggestionId,
|
||||||
|
|
@ -34,3 +41,28 @@ export const applySearchOnlyOmniboxSuggestion = <T extends SearchOnlyListState>(
|
||||||
}
|
}
|
||||||
return { kind: 'url', state }
|
return { kind: 'url', state }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const removeSearchOnlyOmniboxChip = <T extends SearchOnlyListState>({
|
||||||
|
state,
|
||||||
|
chipId,
|
||||||
|
withPageReset,
|
||||||
|
}: {
|
||||||
|
state: T
|
||||||
|
chipId: string
|
||||||
|
withPageReset: (next: T) => T
|
||||||
|
}): SearchOnlyOmniboxAction<T> => {
|
||||||
|
if (chipId === 'q') {
|
||||||
|
return { kind: 'url', state: withPageReset({ ...state, q: undefined }) }
|
||||||
|
}
|
||||||
|
return { kind: 'url', state }
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearSearchOnlyOmnibox = <T extends SearchOnlyListState>({
|
||||||
|
cleared,
|
||||||
|
}: {
|
||||||
|
state: T
|
||||||
|
cleared: T
|
||||||
|
}): SearchOnlyOmniboxAction<T> => ({
|
||||||
|
kind: 'clear',
|
||||||
|
state: cleared,
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ import { describe, expect, it } from 'vitest'
|
||||||
import {
|
import {
|
||||||
applySearchOnlyOmniboxSuggestion,
|
applySearchOnlyOmniboxSuggestion,
|
||||||
buildSearchOnlyOmniboxChips,
|
buildSearchOnlyOmniboxChips,
|
||||||
|
buildSearchOnlyOmniboxSuggestions,
|
||||||
|
clearSearchOnlyOmnibox,
|
||||||
|
removeSearchOnlyOmniboxChip,
|
||||||
} from '@/lib/searchOnlyListOmnibox'
|
} from '@/lib/searchOnlyListOmnibox'
|
||||||
import {
|
import {
|
||||||
applyActivityOmniboxSuggestion,
|
applyActivityOmniboxSuggestion,
|
||||||
|
|
@ -309,6 +312,21 @@ describe('list omnibox adapters (B128)', () => {
|
||||||
withPageReset: (next) => ({ ...next, page: 1 }),
|
withPageReset: (next) => ({ ...next, page: 1 }),
|
||||||
})
|
})
|
||||||
expect(applied).toEqual({ kind: 'url', state: { page: 1, q: 'ana' } })
|
expect(applied).toEqual({ kind: 'url', state: { page: 1, q: 'ana' } })
|
||||||
|
|
||||||
|
expect(buildSearchOnlyOmniboxSuggestions('x')[0]?.id).toBe('q:x')
|
||||||
|
|
||||||
|
const removed = removeSearchOnlyOmniboxChip({
|
||||||
|
state: { q: 'sindicato', page: 2 },
|
||||||
|
chipId: 'q',
|
||||||
|
withPageReset: (next) => ({ ...next, page: 1 }),
|
||||||
|
})
|
||||||
|
expect(removed).toEqual({ kind: 'url', state: { page: 1, q: undefined } })
|
||||||
|
|
||||||
|
const cleared = clearSearchOnlyOmnibox({
|
||||||
|
state: { q: 'sindicato' },
|
||||||
|
cleared: {},
|
||||||
|
})
|
||||||
|
expect(cleared).toEqual({ kind: 'clear', state: {} })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('advisor toggles municipality portfolio filter and suggests by name', () => {
|
it('advisor toggles municipality portfolio filter and suggests by name', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue