import {EventsMetaType, MetaType} from 'sentry/utils/discover/eventView'; import {TransactionThresholdMetric} from 'sentry/views/performance/transactionSummary/transactionThresholdModal'; import GenericDiscoverQuery, { DiscoverQueryProps, GenericChildrenProps, useGenericDiscoverQuery, } from './genericDiscoverQuery'; /** * An individual row in a DiscoverQuery result */ export type TableDataRow = { [key: string]: React.ReactText; id: string; }; /** * A DiscoverQuery result including rows and metadata. */ export type TableData = { data: Array; meta?: MetaType; }; /** * A DiscoverQuery result including rows and metadata from the events endpoint. */ export type EventsTableData = { data: Array; meta?: EventsMetaType; }; export type TableDataWithTitle = TableData & {title: string}; export type DiscoverQueryPropsWithThresholds = DiscoverQueryProps & { transactionName?: string; transactionThreshold?: number; transactionThresholdMetric?: TransactionThresholdMetric; }; export type DiscoverQueryComponentProps = DiscoverQueryPropsWithThresholds & { children: (props: GenericChildrenProps) => React.ReactNode; }; function shouldRefetchData( prevProps: DiscoverQueryPropsWithThresholds, nextProps: DiscoverQueryPropsWithThresholds ) { return ( prevProps.transactionName !== nextProps.transactionName || prevProps.transactionThreshold !== nextProps.transactionThreshold || prevProps.transactionThresholdMetric !== nextProps.transactionThresholdMetric ); } function DiscoverQuery(props: DiscoverQueryComponentProps) { const afterFetch = (data, _) => { const {fields, ...otherMeta} = data.meta ?? {}; return { ...data, meta: {...fields, ...otherMeta}, }; }; return ( route="events" shouldRefetchData={shouldRefetchData} afterFetch={afterFetch} {...props} /> ); } export function useDiscoverQuery(props: Omit) { const afterFetch = (data, _) => { const {fields, ...otherMeta} = data.meta ?? {}; return { ...data, meta: {...fields, ...otherMeta}, }; }; const res = useGenericDiscoverQuery({ route: 'events', shouldRefetchData, afterFetch, ...props, }); const pageLinks = res.response?.getResponseHeader('Link') ?? undefined; return {...res, pageLinks}; } export default DiscoverQuery;