accessibilityRefetchBanner.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/container/flex';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import Well from 'sentry/components/well';
  7. import {t, tct} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import formatReplayDuration from 'sentry/utils/duration/formatReplayDuration';
  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 = formatReplayDuration(currentTime, 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 size="xs" priority="primary" onClick={handleClickRefetch}>
  51. {isPlaying
  52. ? tct('Pause and run validation for [now]', {now})
  53. : tct('Run validation for [now]', {now})}
  54. </Button>
  55. </Flex>
  56. </StyledWell>
  57. );
  58. }
  59. const StyledWell = styled(Well)`
  60. margin-bottom: 0;
  61. border-radius: ${p => p.theme.borderRadiusTop};
  62. `;
  63. const StyledTimestampButton = styled(TimestampButton)`
  64. align-self: center;
  65. align-items: center;
  66. `;