index.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {useContext} from 'react';
  2. import {useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import type {Location} from 'history';
  5. import Placeholder from 'sentry/components/placeholder';
  6. import {space} from 'sentry/styles/space';
  7. import type {Organization} from 'sentry/types';
  8. import type {Event} from 'sentry/types/event';
  9. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  10. import useMedia from 'sentry/utils/useMedia';
  11. import IssueQuickTrace from './issueQuickTrace';
  12. type Props = {
  13. event: Event;
  14. location: Location;
  15. organization: Organization;
  16. };
  17. function QuickTrace({event, organization, location}: Props) {
  18. const theme = useTheme();
  19. const hasPerformanceView = organization.features.includes('performance-view');
  20. const hasTraceContext = Boolean(event.contexts?.trace?.trace_id);
  21. const quickTrace = useContext(QuickTraceContext);
  22. const isSmallViewport = useMedia(`(max-width: ${theme.breakpoints.small})`);
  23. if (isSmallViewport || !hasPerformanceView || !hasTraceContext) {
  24. return null;
  25. }
  26. if (quickTrace?.isLoading) {
  27. return <TracePlaceholder height="20px" />;
  28. }
  29. return (
  30. <IssueQuickTrace
  31. organization={organization}
  32. event={event}
  33. location={location}
  34. quickTrace={quickTrace}
  35. />
  36. );
  37. }
  38. const TracePlaceholder = styled(Placeholder)`
  39. width: auto;
  40. max-width: 300px;
  41. margin-top: ${space(0.75)};
  42. `;
  43. export default QuickTrace;