fix(admin-ui): backlog sweep — 7 review items
This commit is contained in:
@@ -371,11 +371,20 @@ export const useCascadePreview = (dict: string, businessKey: string | undefined)
|
||||
/**
|
||||
* Free-form ILIKE search across all dictionaries (active records only).
|
||||
* Min query length = 3 (backend требует для использования trigram index).
|
||||
*
|
||||
* Min-length guard: throw в queryFn — защищает от prefetch (router loader)
|
||||
* вызовов с q="ab" → backend 400. queryFn enforces invariant; useQuery
|
||||
* `enabled` gating опциональный для UI shortcut, но не source of truth.
|
||||
*/
|
||||
export const SEARCH_MIN_LEN = 3
|
||||
|
||||
export const searchQuery = (q: string, size = 100, perDict = 10) =>
|
||||
queryOptions({
|
||||
queryKey: ['search', q, size, perDict] as const,
|
||||
queryFn: async (): Promise<SearchResponse> => {
|
||||
if (q.length < SEARCH_MIN_LEN) {
|
||||
throw new Error(`search query too short (min ${SEARCH_MIN_LEN} chars)`)
|
||||
}
|
||||
const { data } = await apiClient.get<SearchResponse>('/search', {
|
||||
params: { q, size, perDict },
|
||||
})
|
||||
@@ -387,7 +396,7 @@ export const searchQuery = (q: string, size = 100, perDict = 10) =>
|
||||
export const useSearch = (q: string | undefined, size = 100, perDict = 10) =>
|
||||
useQuery({
|
||||
...searchQuery(q ?? '', size, perDict),
|
||||
enabled: Boolean(q && q.length >= 3),
|
||||
enabled: Boolean(q && q.length >= SEARCH_MIN_LEN),
|
||||
})
|
||||
|
||||
// === Approval Workflow v2 ===
|
||||
|
||||
Reference in New Issue
Block a user