accessibilityRefetchBanner.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {useCallback, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import {Flex} from 'sentry/components/profiling/flex';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import {showPlayerTime} from 'sentry/components/replays/utils';
  7. import Well from 'sentry/components/well';
  8. import {t, tct} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import TimestampButton from 'sentry/views/replays/detail/timestampButton';
  11. interface Props {
  12. initialOffsetMs: number;
  13. refetch: () => void;
  14. }
  15. export default function AccessibilityRefetchBanner({initialOffsetMs, refetch}: Props) {
  16. const {currentTime, replay, setCurrentTime, isPlaying, togglePlayPause} =
  17. useReplayContext();
  18. const startTimestampMs = replay?.getReplay()?.started_at?.getTime() ?? 0;
  19. const [lastOffsetMs, setLastOffsetMs] = useState(initialOffsetMs);
  20. const handleClickRefetch = useCallback(() => {
  21. togglePlayPause(false);
  22. setLastOffsetMs(currentTime);
  23. refetch();
  24. }, [currentTime, refetch, togglePlayPause]);
  25. const handleClickTimestamp = useCallback(() => {
  26. setCurrentTime(lastOffsetMs);
  27. }, [setCurrentTime, lastOffsetMs]);
  28. const now = showPlayerTime(startTimestampMs + currentTime, startTimestampMs, false);
  29. return (
  30. <StyledWell>
  31. <Flex
  32. gap={space(1)}
  33. justify="space-between"
  34. align="center"
  35. wrap="nowrap"
  36. style={{overflow: 'auto'}}
  37. >
  38. <Flex gap={space(1)} wrap="nowrap" style={{whiteSpace: 'nowrap'}}>
  39. {tct('Results as of [lastRuntime]', {
  40. lastRuntime: (
  41. <StyledTimestampButton
  42. aria-label={t('See in replay')}
  43. onClick={handleClickTimestamp}
  44. startTimestampMs={startTimestampMs}
  45. timestampMs={startTimestampMs + lastOffsetMs}
  46. />
  47. ),
  48. })}
  49. </Flex>
  50. <Button
  51. size="xs"
  52. priority="primary"
  53. onClick={handleClickRefetch}
  54. disabled={currentTime === lastOffsetMs}
  55. >
  56. {isPlaying
  57. ? tct('Pause and run validation for [now]', {now})
  58. : tct('Run validation for [now]', {now})}
  59. </Button>
  60. </Flex>
  61. </StyledWell>
  62. );
  63. }
  64. const StyledWell = styled(Well)`
  65. margin-bottom: 0;
  66. border-radius: ${p => p.theme.borderRadiusTop};
  67. `;
  68. const StyledTimestampButton = styled(TimestampButton)`
  69. align-self: center;
  70. align-items: center;
  71. `;