import styled from '@emotion/styled'; import Alert from 'sentry/components/alert'; import ExternalLink from 'sentry/components/links/externalLink'; import {parseSearch} from 'sentry/components/searchSyntax/parser'; import {tct} from 'sentry/locale'; import {space} from 'sentry/styles/space'; import {parseFunction} from 'sentry/utils/discover/fields'; import { MEPConsumer, MEPState, } from 'sentry/utils/performance/contexts/metricsEnhancedSetting'; import useOrganization from 'sentry/utils/useOrganization'; import {DashboardsMEPConsumer} from './widgetCard/dashboardsMEPContext'; import {type Widget, WidgetType} from './types'; type SearchFilterKey = {key?: {value: string}}; interface IndexedEventsSelectionAlertProps { widget: Widget; } const ERROR_FIELDS = [ 'error.handled', 'error.unhandled', 'error.mechanism', 'error.type', 'error.value', ]; export function IndexedEventsSelectionAlert({widget}: IndexedEventsSelectionAlertProps) { const organization = useOrganization(); if (organization.features.includes('performance-mep-bannerless-ui')) { return null; } const widgetContainsErrorFields = widget.queries.some( ({columns, aggregates, conditions}) => ERROR_FIELDS.some( errorField => columns.includes(errorField) || aggregates.some(aggregate => parseFunction(aggregate)?.arguments.includes(errorField) ) || parseSearch(conditions)?.some( filter => (filter as SearchFilterKey).key?.value === errorField ) ) ); return ( {metricSettingContext => { return ( {({isMetricsData}) => { if ( isMetricsData === false && widget.widgetType === WidgetType.DISCOVER && metricSettingContext && metricSettingContext.metricSettingState !== MEPState.TRANSACTIONS_ONLY ) { if (!widgetContainsErrorFields) { return ( {tct( "Your selection is only applicable to [indexedData: indexed event data]. We've automatically adjusted your results.", { indexedData: ( ), } )} ); } } return null; }} ); }} ); } const StoredDataAlert = styled(Alert)` margin-top: ${space(1)}; margin-bottom: 0; `;