12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import {Client} from 'sentry/api';
- import {MAX_AUTOCOMPLETE_RECENT_SEARCHES} from 'sentry/constants';
- import {RecentSearch, SavedSearch, SavedSearchType} from 'sentry/types';
- import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse';
- import RequestError from 'sentry/utils/requestError/requestError';
- const getRecentSearchUrl = (orgSlug: string): string =>
- `/organizations/${orgSlug}/recent-searches/`;
- export function saveRecentSearch(
- api: Client,
- orgSlug: string,
- type: SavedSearchType,
- query: string
- ): Promise<SavedSearch> {
- const url = getRecentSearchUrl(orgSlug);
- const promise = api.requestPromise(url, {
- method: 'POST',
- data: {
- query,
- type,
- },
- });
- promise.catch((err: RequestError) =>
- handleXhrErrorResponse('Unable to save a recent search', err)
- );
- return promise;
- }
- export function fetchRecentSearches(
- api: Client,
- orgSlug: string,
- type: SavedSearchType,
- query?: string
- ): Promise<RecentSearch[]> {
- const url = getRecentSearchUrl(orgSlug);
-
-
-
-
-
- if (query && query.length > 5000) {
- query = query.substring(0, 5000);
- }
- const promise = api.requestPromise(url, {
- query: {
- query,
- type,
- limit: MAX_AUTOCOMPLETE_RECENT_SEARCHES,
- },
- });
- promise.catch((resp: RequestError) => {
- if (resp.status !== 401 && resp.status !== 403) {
- handleXhrErrorResponse('Unable to fetch recent searches', resp);
- }
- });
- return promise;
- }
|