traceLiteQuery.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {Fragment} from 'react';
  2. import GenericDiscoverQuery, {
  3. DiscoverQueryProps,
  4. } from 'sentry/utils/discover/genericDiscoverQuery';
  5. import {
  6. BaseTraceChildrenProps,
  7. PartialQuickTrace,
  8. TraceLite,
  9. TraceRequestProps,
  10. } from 'sentry/utils/performance/quickTrace/types';
  11. import {
  12. getTraceRequestPayload,
  13. makeEventView,
  14. } from 'sentry/utils/performance/quickTrace/utils';
  15. type AdditionalQueryProps = {
  16. eventId: string;
  17. };
  18. type TraceLiteQueryChildrenProps = BaseTraceChildrenProps &
  19. Omit<PartialQuickTrace, 'trace'> & {
  20. trace: TraceLite | null;
  21. };
  22. type QueryProps = Omit<TraceRequestProps, 'eventView'> &
  23. AdditionalQueryProps & {
  24. children: (props: TraceLiteQueryChildrenProps) => React.ReactNode;
  25. };
  26. function getTraceLiteRequestPayload({
  27. eventId,
  28. ...props
  29. }: DiscoverQueryProps & AdditionalQueryProps) {
  30. const additionalApiPayload = getTraceRequestPayload(props);
  31. return Object.assign({event_id: eventId}, additionalApiPayload);
  32. }
  33. function EmptyTrace({children}: Pick<QueryProps, 'children'>) {
  34. return (
  35. <Fragment>
  36. {children({
  37. isLoading: false,
  38. error: null,
  39. trace: null,
  40. type: 'partial',
  41. })}
  42. </Fragment>
  43. );
  44. }
  45. function TraceLiteQuery({
  46. traceId,
  47. start,
  48. end,
  49. statsPeriod,
  50. children,
  51. ...props
  52. }: QueryProps) {
  53. if (!traceId) {
  54. return <EmptyTrace>{children}</EmptyTrace>;
  55. }
  56. const eventView = makeEventView({start, end, statsPeriod});
  57. return (
  58. <GenericDiscoverQuery<TraceLite, AdditionalQueryProps>
  59. route={`events-trace-light/${traceId}`}
  60. getRequestPayload={getTraceLiteRequestPayload}
  61. eventView={eventView}
  62. {...props}
  63. >
  64. {({tableData, ...rest}) =>
  65. children({
  66. // This is using '||` instead of '??` here because
  67. // the client returns a empty string when the response
  68. // is 204. And we want the empty string, undefined and
  69. // null to be converted to null.
  70. trace: tableData || null,
  71. type: 'partial',
  72. ...rest,
  73. })
  74. }
  75. </GenericDiscoverQuery>
  76. );
  77. }
  78. export default TraceLiteQuery;