feedbackScreenshot.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import ImageVisualization from 'sentry/components/events/eventTagsAndScreenshot/screenshot/imageVisualization';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import Panel from 'sentry/components/panels/panel';
  6. import type {EventAttachment, Organization, Project} from 'sentry/types';
  7. type Props = {
  8. organization: Organization;
  9. projectSlug: Project['slug'];
  10. screenshot: EventAttachment;
  11. className?: string;
  12. onClick?: () => void;
  13. };
  14. export default function FeedbackScreenshot({
  15. className,
  16. organization,
  17. projectSlug,
  18. screenshot,
  19. onClick,
  20. }: Props) {
  21. const [isLoading, setIsLoading] = useState(true);
  22. const img = (
  23. <StyledImageVisualization
  24. attachment={screenshot}
  25. orgId={organization.slug}
  26. projectSlug={projectSlug}
  27. eventId={screenshot.event_id}
  28. onLoad={() => setIsLoading(false)}
  29. onError={() => setIsLoading(false)}
  30. />
  31. );
  32. return (
  33. <StyledPanel className={className}>
  34. {isLoading && (
  35. <StyledLoadingIndicator>
  36. <LoadingIndicator mini />
  37. </StyledLoadingIndicator>
  38. )}
  39. {onClick ? <StyledImageButton onClick={onClick}>{img}</StyledImageButton> : img}
  40. </StyledPanel>
  41. );
  42. }
  43. const StyledPanel = styled(Panel)`
  44. display: flex;
  45. flex-direction: column;
  46. justify-content: center;
  47. align-items: center;
  48. margin-bottom: 0;
  49. border: 0;
  50. border-radius: ${p => p.theme.borderRadius};
  51. `;
  52. const StyledLoadingIndicator = styled('div')`
  53. display: flex;
  54. align-items: center;
  55. justify-content: center;
  56. height: 100%;
  57. background: ${p => p.theme.purple100};
  58. `;
  59. const StyledImageButton = styled('button')`
  60. cursor: zoom-in;
  61. background: none;
  62. padding: 0;
  63. border: 0;
  64. overflow: auto;
  65. `;
  66. const StyledImageVisualization = styled(ImageVisualization)`
  67. z-index: 1;
  68. border: 0;
  69. border-radius: ${p => p.theme.borderRadius};
  70. overflow: hidden;
  71. img {
  72. width: auto;
  73. height: auto;
  74. }
  75. `;