exampleReplaysList.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import {Fragment, useMemo} from 'react';
  2. import {Location} from 'history';
  3. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import {t} from 'sentry/locale';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import getRouteStringFromRoutes from 'sentry/utils/getRouteStringFromRoutes';
  8. import useReplayList from 'sentry/utils/replays/hooks/useReplayList';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import {useRoutes} from 'sentry/utils/useRoutes';
  11. import {StatusContainer} from 'sentry/views/profiling/landing/styles';
  12. import {ReplayCell} from 'sentry/views/replays/replayTable/tableCell';
  13. export default function ExampleReplaysList({
  14. location,
  15. clickType,
  16. selectorQuery,
  17. projectId,
  18. }: {
  19. clickType: 'count_dead_clicks' | 'count_rage_clicks';
  20. location: Location;
  21. projectId: number;
  22. selectorQuery: string;
  23. }) {
  24. const organization = useOrganization();
  25. const {project, environment, start, statsPeriod, utc, end} = location.query;
  26. const emptyLocation: Location = useMemo(() => {
  27. return {
  28. pathname: '',
  29. search: '',
  30. hash: '',
  31. state: '',
  32. action: 'PUSH' as const,
  33. key: '',
  34. query: {project, environment, start, statsPeriod, utc, end},
  35. };
  36. }, [project, environment, start, statsPeriod, utc, end]);
  37. const eventView = useMemo(
  38. () =>
  39. EventView.fromNewQueryWithLocation(
  40. {
  41. id: '',
  42. name: '',
  43. version: 2,
  44. fields: [
  45. 'activity',
  46. 'duration',
  47. 'id',
  48. 'project_id',
  49. 'user',
  50. 'finished_at',
  51. 'is_archived',
  52. 'started_at',
  53. 'urls',
  54. ],
  55. projects: [projectId],
  56. query: selectorQuery,
  57. orderby: `-${clickType}`,
  58. },
  59. emptyLocation
  60. ),
  61. [emptyLocation, selectorQuery, clickType, projectId]
  62. );
  63. const {replays, isFetching, fetchError} = useReplayList({
  64. eventView,
  65. location: emptyLocation,
  66. organization,
  67. perPage: 3,
  68. });
  69. const routes = useRoutes();
  70. const referrer = getRouteStringFromRoutes(routes);
  71. return (
  72. <Fragment>
  73. {fetchError || (!isFetching && !replays?.length) ? (
  74. <EmptyStateWarning withIcon={false} small>
  75. {t('No replays found')}
  76. </EmptyStateWarning>
  77. ) : isFetching ? (
  78. <StatusContainer>
  79. <LoadingIndicator />
  80. </StatusContainer>
  81. ) : (
  82. replays?.map(r => {
  83. return (
  84. <ReplayCell
  85. key={r.id}
  86. replay={r}
  87. eventView={eventView}
  88. organization={organization}
  89. referrer={referrer}
  90. referrer_table="selector-widget"
  91. isWidget
  92. />
  93. );
  94. })
  95. )}
  96. </Fragment>
  97. );
  98. }