traceLiteQuery.tsx 2.1 KB

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