Browse Source

ref(ts): Consistently use TagCollection (#38313)

Evan Purkhiser 2 years ago
parent
commit
8c7ed3391a

+ 2 - 2
static/app/components/events/searchBar.tsx

@@ -7,7 +7,7 @@ import omit from 'lodash/omit';
 import {fetchTagValues} from 'sentry/actionCreators/tags';
 import SmartSearchBar from 'sentry/components/smartSearchBar';
 import {NEGATION_OPERATOR, SEARCH_WILDCARD} from 'sentry/constants';
-import {Organization, SavedSearchType, Tag, TagCollection} from 'sentry/types';
+import {Organization, SavedSearchType, TagCollection} from 'sentry/types';
 import {defined} from 'sentry/utils';
 import {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
 import {
@@ -170,7 +170,7 @@ function SearchBar(props: SearchBarProps) {
 
     const orgHasPerformanceView = organization.features.includes('performance-view');
 
-    const combinedTags: Record<string, Tag> = orgHasPerformanceView
+    const combinedTags: TagCollection = orgHasPerformanceView
       ? Object.assign({}, measurementsWithKind, spanTags, fieldTags, functionTags)
       : omit(fieldTags, TRACING_FIELDS);
 

+ 2 - 2
static/app/components/smartSearchBar/index.tsx

@@ -37,7 +37,7 @@ import {IconClose, IconEllipsis, IconSearch} from 'sentry/icons';
 import {t} from 'sentry/locale';
 import MemberListStore from 'sentry/stores/memberListStore';
 import space from 'sentry/styles/space';
-import {Organization, SavedSearchType, Tag, User} from 'sentry/types';
+import {Organization, SavedSearchType, Tag, TagCollection, User} from 'sentry/types';
 import {defined} from 'sentry/utils';
 import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {callIfFunction} from 'sentry/utils/callIfFunction';
@@ -251,7 +251,7 @@ type Props = WithRouterProps & {
   /**
    * Map of tags
    */
-  supportedTags?: {[key: string]: Tag};
+  supportedTags?: TagCollection;
   /**
    * Wrap the input with a form. Useful if search bar is used within a parent
    * form

+ 2 - 7
static/app/components/smartSearchBar/utils.tsx

@@ -26,7 +26,7 @@ import {
   Shortcut,
   ShortcutType,
 } from './types';
-import {Tag} from 'sentry/types';
+import {TagCollection} from 'sentry/types';
 import {FieldKind, FieldValueType, getFieldDefinition} from 'sentry/utils/fields';
 
 export function addSpace(query = '') {
@@ -384,12 +384,7 @@ const getItemTitle = (key: string, kind: FieldKind) => {
  * For example, "device.arch" and "device.name" will be grouped together as children of "device", a non-interactive parent.
  * The parent will become interactive if there exists a key "device".
  */
-export const getTagItemsFromKeys = (
-  tagKeys: string[],
-  supportedTags: {
-    [key: string]: Tag;
-  }
-) => {
+export const getTagItemsFromKeys = (tagKeys: string[], supportedTags: TagCollection) => {
   return [...tagKeys].reduce((groups, key) => {
     const keyWithColon = `${key}:`;
     const sections = key.split('.');

+ 4 - 6
static/app/utils/profiling/hooks/useProfileFilters.tsx

@@ -2,22 +2,20 @@ import {useEffect, useState} from 'react';
 
 import {Client} from 'sentry/api';
 import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
-import {Organization, PageFilters, Tag} from 'sentry/types';
+import {Organization, PageFilters, Tag, TagCollection} from 'sentry/types';
 import useApi from 'sentry/utils/useApi';
 import useOrganization from 'sentry/utils/useOrganization';
 
-type ProfileFilters = Record<string, Tag>;
-
 interface ProfileFiltersOptions {
   query: string;
   selection?: PageFilters;
 }
 
-function useProfileFilters({query, selection}: ProfileFiltersOptions): ProfileFilters {
+function useProfileFilters({query, selection}: ProfileFiltersOptions): TagCollection {
   const api = useApi();
   const organization = useOrganization();
 
-  const [profileFilters, setProfileFilters] = useState<ProfileFilters>({});
+  const [profileFilters, setProfileFilters] = useState<TagCollection>({});
 
   useEffect(() => {
     if (!selection) {
@@ -26,7 +24,7 @@ function useProfileFilters({query, selection}: ProfileFiltersOptions): ProfileFi
 
     fetchProfileFilters(api, organization, query, selection).then(response => {
       const withPredefinedFilters = response.reduce(
-        (filters: ProfileFilters, tag: Tag) => {
+        (filters: TagCollection, tag: Tag) => {
           filters[tag.key] = {
             ...tag,
             // predefined allows us to specify a list of possible values

+ 2 - 4
static/app/views/issueList/filters.tsx

@@ -5,13 +5,11 @@ import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
 import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
 import ProjectPageFilter from 'sentry/components/projectPageFilter';
 import space from 'sentry/styles/space';
-import {Organization, SavedSearch} from 'sentry/types';
+import {Organization, SavedSearch, TagCollection} from 'sentry/types';
 
 import IssueListSearchBar from './searchBar';
 import {TagValueLoader} from './types';
 
-type IssueListSearchBarProps = React.ComponentProps<typeof IssueListSearchBar>;
-
 type Props = {
   isSearchDisabled: boolean;
   onSearch: (query: string) => void;
@@ -21,7 +19,7 @@ type Props = {
   savedSearch: SavedSearch;
   sort: string;
   tagValueLoader: TagValueLoader;
-  tags: NonNullable<IssueListSearchBarProps['supportedTags']>;
+  tags: TagCollection;
 };
 
 function IssueListFilters({

+ 3 - 3
static/app/views/issueList/searchBar.tsx

@@ -6,12 +6,12 @@ import {
   makeSaveSearchAction,
   makeSearchBuilderAction,
 } from 'sentry/components/smartSearchBar/actions';
-import {SavedSearch, SavedSearchType, Tag} from 'sentry/types';
+import {SavedSearch, SavedSearchType, Tag, TagCollection} from 'sentry/types';
 import {FieldKind, getFieldDefinition} from 'sentry/utils/fields';
 
 import {TagValueLoader} from './types';
 
-const getSupportedTags = (supportedTags: {[key: string]: Tag}) =>
+const getSupportedTags = (supportedTags: TagCollection) =>
   Object.fromEntries(
     Object.keys(supportedTags).map(key => [
       key,
@@ -27,7 +27,7 @@ const getSupportedTags = (supportedTags: {[key: string]: Tag}) =>
 interface Props extends React.ComponentProps<typeof SmartSearchBar> {
   onSidebarToggle: (e: React.MouseEvent) => void;
   sort: string;
-  supportedTags: {[key: string]: Tag};
+  supportedTags: TagCollection;
   tagValueLoader: TagValueLoader;
   savedSearch?: SavedSearch;
 }