vitalDetailPanel.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  7. import {PERFORMANCE_SCORE_COLORS} from 'sentry/views/insights/browser/webVitals/utils/performanceScoreColors';
  8. import DetailPanel from 'sentry/views/insights/common/components/detailPanel';
  9. import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
  10. import {
  11. PerformanceScore,
  12. type VitalItem,
  13. type VitalStatus,
  14. } from 'sentry/views/insights/mobile/screens/utils';
  15. export function VitalDetailPanel({
  16. vital,
  17. status,
  18. onClose,
  19. }: {
  20. onClose: () => void;
  21. status: VitalStatus | undefined;
  22. vital: VitalItem | undefined;
  23. }) {
  24. const {selectedPlatform} = useCrossPlatformProject();
  25. const platformDocsLink = vital?.platformDocLinks[selectedPlatform];
  26. const sdkDocsLink = vital?.sdkDocLinks[selectedPlatform];
  27. return (
  28. <PageAlertProvider>
  29. <DetailPanel detailKey={vital?.field} onClose={onClose}>
  30. {vital && (
  31. <React.Fragment>
  32. <VitalDetailTitle>{vital.title}</VitalDetailTitle>
  33. {status && (
  34. <h2>
  35. {status.formattedValue ?? '-'}{' '}
  36. {status.score !== PerformanceScore.NONE && (
  37. <Badge status={status.score}>{status.description}</Badge>
  38. )}
  39. </h2>
  40. )}
  41. <p>{vital.docs}</p>
  42. {vital.setup && <p>{vital.setup}</p>}
  43. {(platformDocsLink || sdkDocsLink) && (
  44. <React.Fragment>
  45. <SubHeading>{t('Learn more')}</SubHeading>
  46. <ul>
  47. {sdkDocsLink && (
  48. <li>
  49. <ExternalLink href={sdkDocsLink}>
  50. {t('Sentry SDK documentation')}
  51. </ExternalLink>
  52. </li>
  53. )}
  54. {platformDocsLink && (
  55. <li>
  56. <ExternalLink href={platformDocsLink}>
  57. {t('Platform documentation')}
  58. </ExternalLink>
  59. </li>
  60. )}
  61. </ul>
  62. </React.Fragment>
  63. )}
  64. </React.Fragment>
  65. )}
  66. <PageAlert />
  67. </DetailPanel>
  68. </PageAlertProvider>
  69. );
  70. }
  71. const VitalDetailTitle = styled('h4')`
  72. margin-bottom: ${space(1)};
  73. margin-top: 40px;
  74. `;
  75. const Badge = styled('div')<{status: string}>`
  76. white-space: nowrap;
  77. border-radius: 12px;
  78. color: ${p => p.theme[PERFORMANCE_SCORE_COLORS[p.status].normal]};
  79. background-color: ${p => p.theme[PERFORMANCE_SCORE_COLORS[p.status].light]};
  80. border: solid 1px ${p => p.theme[PERFORMANCE_SCORE_COLORS[p.status].light]};
  81. font-size: ${p => p.theme.fontSizeSmall};
  82. padding: 0 ${space(1)};
  83. display: inline-block;
  84. height: 17px;
  85. vertical-align: middle;
  86. `;
  87. const SubHeading = styled('div')`
  88. font-weight: ${p => p.theme.fontWeightBold};
  89. margin-bottom: ${space(1)};
  90. `;