import * as React from 'react'; import pick from 'lodash/pick'; import {MetaType} from 'app/utils/discover/eventView'; import {WebVital} from 'app/utils/discover/fields'; import GenericDiscoverQuery, { DiscoverQueryPropsWithContext, GenericChildrenProps, } from 'app/utils/discover/genericDiscoverQuery'; import {PERFORMANCE_URL_PARAM} from 'app/utils/performance/constants'; import withApi from 'app/utils/withApi'; export type TableDataRow = { id: string; [key: string]: React.ReactText; }; export type TableData = { data: Array; meta?: MetaType; }; export type VitalData = { poor: number; meh: number; good: number; total: number; p75: number | null; }; export type VitalsData = Record; type VitalsProps = { vitals: WebVital[]; }; type RequestProps = DiscoverQueryPropsWithContext & VitalsProps; type ChildrenProps = Omit, 'tableData'> & { vitalsData: VitalsData | null; }; type Props = RequestProps & { children: (props: ChildrenProps) => React.ReactNode; }; function getRequestPayload(props: RequestProps) { const {eventView, vitals} = props; const apiPayload = eventView?.getEventsAPIPayload(props.location); return { vital: vitals, ...pick(apiPayload, ['query', ...Object.values(PERFORMANCE_URL_PARAM)]), }; } function VitalsCardsDiscoverQuery(props: Props) { return ( getRequestPayload={getRequestPayload} route="events-vitals" {...props} > {({tableData, ...rest}) => { return props.children({vitalsData: tableData, ...rest}); }} ); } export default withApi(VitalsCardsDiscoverQuery);