Browse Source

ref(new-widget-builder-experience): Revert MetricsSearchbar logic (#33303)

Priscila Oliveira 2 years ago
parent
commit
22fb0956a4

+ 2 - 10
static/app/views/dashboardsV2/dashboard.tsx

@@ -146,11 +146,7 @@ class Dashboard extends Component<Props, State> {
       window.addEventListener('resize', this.debouncedHandleResize);
     }
 
-    if (
-      organization.features.includes('dashboards-metrics') &&
-      !organization.features.includes('new-widget-builder-experience') &&
-      organization.features.includes('new-widget-builder-experience-modal-access')
-    ) {
+    if (organization.features.includes('dashboards-metrics')) {
       fetchMetricsFields(api, organization.slug, selection.projects);
       fetchMetricsTags(api, organization.slug, selection.projects);
     }
@@ -181,11 +177,7 @@ class Dashboard extends Component<Props, State> {
     if (!isEqual(prevProps.selection.projects, selection.projects)) {
       this.fetchMemberList();
 
-      if (
-        organization.features.includes('dashboards-metrics') &&
-        !organization.features.includes('new-widget-builder-experience') &&
-        organization.features.includes('new-widget-builder-experience-modal-access')
-      ) {
+      if (organization.features.includes('dashboards-metrics')) {
         fetchMetricsFields(api, organization.slug, selection.projects);
         fetchMetricsTags(api, organization.slug, selection.projects);
       }

+ 0 - 2
static/app/views/dashboardsV2/widgetBuilder/buildSteps/columnsStep/releaseColumnFields.tsx

@@ -7,7 +7,6 @@ import {
 } from 'sentry/utils/discover/fields';
 import {useMetricMetas} from 'sentry/utils/useMetricMetas';
 import {useMetricTags} from 'sentry/utils/useMetricTags';
-import useProjects from 'sentry/utils/useProjects';
 import {DisplayType, WidgetType} from 'sentry/views/dashboardsV2/types';
 import {generateMetricsWidgetFieldOptions} from 'sentry/views/dashboardsV2/widgetBuilder/metricWidget/fields';
 import {FieldValueOption} from 'sentry/views/eventsV2/table/queryField';
@@ -34,7 +33,6 @@ export function ReleaseColumnFields({
 }: Props) {
   const {metricTags} = useMetricTags();
   const {metricMetas} = useMetricMetas();
-  const {} = useProjects();
   // Any function/field choice for Big Number widgets is legal since the
   // data source is from an endpoint that is not timeseries-based.
   // The function/field choice for World Map widget will need to be numeric-like.

+ 27 - 4
static/app/views/performance/metricsSearchBar.tsx

@@ -1,11 +1,13 @@
+import {useEffect, useState} from 'react';
 import {ClassNames} from '@emotion/react';
 import memoize from 'lodash/memoize';
 
+import {addErrorMessage} from 'sentry/actionCreators/indicator';
 import SmartSearchBar from 'sentry/components/smartSearchBar';
 import {NEGATION_OPERATOR, SEARCH_WILDCARD} from 'sentry/constants';
-import {MetricsTagValue, Organization, Tag} from 'sentry/types';
+import {t} from 'sentry/locale';
+import {MetricsTag, MetricsTagValue, Organization, Tag} from 'sentry/types';
 import useApi from 'sentry/utils/useApi';
-import {useMetricTags} from 'sentry/utils/useMetricTags';
 
 const SEARCH_SPECIAL_CHARS_REGEXP = new RegExp(
   `^${NEGATION_OPERATOR}|\\${SEARCH_WILDCARD}`,
@@ -32,7 +34,28 @@ function MetricsSearchBar({
   ...props
 }: Props) {
   const api = useApi();
-  const {metricTags} = useMetricTags();
+  const [tags, setTags] = useState<MetricsTag[]>([]);
+
+  useEffect(() => {
+    fetchTags();
+  }, [projectIds]);
+
+  async function fetchTags() {
+    try {
+      const response = await api.requestPromise(
+        `/organizations/${orgSlug}/metrics/tags/`,
+        {
+          query: {
+            project: !projectIds.length ? undefined : projectIds,
+          },
+        }
+      );
+
+      setTags(response);
+    } catch {
+      addErrorMessage(t('Unable to fetch search bar tags'));
+    }
+  }
 
   /**
    * Prepare query string (e.g. strip special characters like negation operator)
@@ -56,7 +79,7 @@ function MetricsSearchBar({
     );
   }
 
-  const supportedTags = Object.values(metricTags).reduce((acc, {key}) => {
+  const supportedTags = Object.values(tags).reduce((acc, {key}) => {
     acc[key] = {key, name: key};
     return acc;
   }, {});