accessibilityRefetchBanner.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 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. `;