|
@@ -3,8 +3,12 @@ import * as Sentry from '@sentry/react';
|
|
|
|
|
|
import {saveRecentSearch} from 'sentry/actionCreators/savedSearches';
|
|
|
import type {Client} from 'sentry/api';
|
|
|
-import {tokenIsInvalid} from 'sentry/components/searchQueryBuilder/utils';
|
|
|
+import {
|
|
|
+ recentSearchTypeToLabel,
|
|
|
+ tokenIsInvalid,
|
|
|
+} from 'sentry/components/searchQueryBuilder/utils';
|
|
|
import {type ParseResult, Token} from 'sentry/components/searchSyntax/parser';
|
|
|
+import type {SavedSearchType} from 'sentry/types';
|
|
|
import type {Organization} from 'sentry/types/organization';
|
|
|
import {trackAnalytics} from 'sentry/utils/analytics';
|
|
|
import useApi from 'sentry/utils/useApi';
|
|
@@ -12,13 +16,13 @@ import useOrganization from 'sentry/utils/useOrganization';
|
|
|
|
|
|
type UseHandleSearchProps = {
|
|
|
parsedQuery: ParseResult | null;
|
|
|
- savedSearchType: any;
|
|
|
+ recentSearches: SavedSearchType | undefined;
|
|
|
searchSource: string;
|
|
|
onSearch?: (query: string) => void;
|
|
|
};
|
|
|
|
|
|
async function saveAsRecentSearch({
|
|
|
- savedSearchType,
|
|
|
+ recentSearches,
|
|
|
query,
|
|
|
api,
|
|
|
organization,
|
|
@@ -26,16 +30,16 @@ async function saveAsRecentSearch({
|
|
|
api: Client;
|
|
|
organization: Organization;
|
|
|
query: string;
|
|
|
- savedSearchType: any;
|
|
|
+ recentSearches: SavedSearchType | undefined;
|
|
|
}) {
|
|
|
- // Only save recent search query if we have a savedSearchType (also 0 is a valid value)
|
|
|
+ // Only save recent search query if there is a type provided.
|
|
|
// Do not save empty string queries (i.e. if they clear search)
|
|
|
- if (typeof savedSearchType === 'undefined' || !query) {
|
|
|
+ if (typeof recentSearches === 'undefined' || !query) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- await saveRecentSearch(api, organization.slug, savedSearchType, query);
|
|
|
+ await saveRecentSearch(api, organization.slug, recentSearches, query);
|
|
|
} catch (err) {
|
|
|
// Silently capture errors if it fails to save
|
|
|
Sentry.captureException(err);
|
|
@@ -84,7 +88,7 @@ function trackIndividualSearchFilters({
|
|
|
|
|
|
export function useHandleSearch({
|
|
|
parsedQuery,
|
|
|
- savedSearchType,
|
|
|
+ recentSearches,
|
|
|
searchSource,
|
|
|
onSearch,
|
|
|
}: UseHandleSearchProps) {
|
|
@@ -95,7 +99,7 @@ export function useHandleSearch({
|
|
|
(query: string) => {
|
|
|
onSearch?.(query);
|
|
|
|
|
|
- const searchType = savedSearchType === 0 ? 'issues' : 'events';
|
|
|
+ const searchType = recentSearchTypeToLabel(recentSearches);
|
|
|
|
|
|
if (parsedQuery?.some(token => tokenIsInvalid(token))) {
|
|
|
trackAnalytics('search.search_with_invalid', {
|
|
@@ -124,8 +128,8 @@ export function useHandleSearch({
|
|
|
organization,
|
|
|
});
|
|
|
|
|
|
- saveAsRecentSearch({api, organization, query, savedSearchType});
|
|
|
+ saveAsRecentSearch({api, organization, query, recentSearches});
|
|
|
},
|
|
|
- [api, onSearch, organization, parsedQuery, savedSearchType, searchSource]
|
|
|
+ [api, onSearch, organization, parsedQuery, recentSearches, searchSource]
|
|
|
);
|
|
|
}
|