← All changes
|
js/components/ManageMenu/CommunityCloud/WithCloudSearchContext.tsx
+13
-2
3.10.2
→
4.0.0-beta.2
View file →
| @@ -34,12 +34,22 @@ | ||
| 34 | 34 | status: 'status', |
| 35 | 35 | category: 'category' |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | +const SEARCH_METHODS = ['term', 'codevault', 'ai'] as const | |
| 39 | + | |
| 40 | +export type CloudSearchMethod = typeof SEARCH_METHODS[number] | |
| 41 | + | |
| 42 | +const isSearchMethod = (value: unknown): value is CloudSearchMethod => | |
| 43 | + SEARCH_METHODS.some(method => method === value) | |
| 44 | + | |
| 45 | +export const parseSearchMethod = (value: unknown): CloudSearchMethod => | |
| 46 | + isSearchMethod(value) ? value : 'term' | |
| 47 | + | |
| 38 | 48 | export interface CloudSearchParams { |
| 39 | 49 | page: number |
| 40 | 50 | query: string |
| 41 | - method: 'term' | 'codevault' | |
| 51 | + method: CloudSearchMethod | |
| 42 | 52 | type: string |
| 43 | 53 | status: number |
| 44 | 54 | category: string |
| 45 | 55 | } |
| @@ -69,9 +79,9 @@ | ||
| 69 | 79 | page: isNaN(page) ? 1 : page, |
| 70 | 80 | type, |
| 71 | 81 | query, |
| 72 | 82 | status: Number(status), |
| 73 | - method: 'codevault' === method ? 'codevault' : 'term', | |
| 83 | + method: parseSearchMethod(method), | |
| 74 | 84 | category |
| 75 | 85 | } |
| 76 | 86 | } |
| 77 | 87 | |
| @@ -92,8 +102,9 @@ | ||
| 92 | 102 | ) => |
| 93 | 103 | buildUrl(baseUrl, { |
| 94 | 104 | query, |
| 95 | 105 | searchByCodevault: 'codevault' === method ? true : undefined, |
| 106 | + searchMethod: 'ai' === method ? 'ai' : undefined, | |
| 96 | 107 | per_page: SNIPPETS_PER_PAGE, |
| 97 | 108 | type: type || undefined, |
| 98 | 109 | category: category || undefined, |
| 99 | 110 | status: status || undefined, |