fix(admin-ui): backlog sweep — 7 review items

This commit is contained in:
Александр Зимин
2026-05-10 19:21:33 +00:00
parent c7f6559bed
commit 48dd8a487a
6 changed files with 156 additions and 16 deletions
+10 -1
View File
@@ -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 ===