samplingSDKUpgradesAlert.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {useEffect} from 'react';
  2. import styled from '@emotion/styled';
  3. import {openModal} from 'sentry/actionCreators/modal';
  4. import Alert from 'sentry/components/alert';
  5. import Button from 'sentry/components/button';
  6. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {Organization} from 'sentry/types';
  10. import {RecommendedSdkUpgrade} from 'sentry/types/sampling';
  11. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  12. import {
  13. RecommendedStepsModal,
  14. RecommendedStepsModalProps,
  15. } from './modals/recommendedStepsModal';
  16. type Props = Pick<RecommendedStepsModalProps, 'projectId' | 'onReadDocs'> & {
  17. organization: Organization;
  18. recommendedSdkUpgrades: RecommendedSdkUpgrade[];
  19. };
  20. export function SamplingSDKUpgradesAlert({
  21. organization,
  22. projectId,
  23. recommendedSdkUpgrades,
  24. onReadDocs,
  25. }: Props) {
  26. useEffect(() => {
  27. if (recommendedSdkUpgrades.length > 0) {
  28. trackAdvancedAnalyticsEvent('sampling.sdk.updgrades.alert', {
  29. organization,
  30. project_id: projectId,
  31. });
  32. }
  33. }, [recommendedSdkUpgrades.length, organization, projectId]);
  34. function handleOpenRecommendedSteps() {
  35. openModal(modalProps => (
  36. <RecommendedStepsModal
  37. {...modalProps}
  38. onReadDocs={onReadDocs}
  39. organization={organization}
  40. projectId={projectId}
  41. recommendedSdkUpgrades={recommendedSdkUpgrades}
  42. />
  43. ));
  44. }
  45. if (recommendedSdkUpgrades.length === 0) {
  46. return null;
  47. }
  48. return (
  49. <Alert
  50. data-test-id="recommended-sdk-upgrades-alert"
  51. type="info"
  52. showIcon
  53. trailingItems={
  54. <Button onClick={handleOpenRecommendedSteps} priority="link" borderless>
  55. {t('Learn More')}
  56. </Button>
  57. }
  58. >
  59. {t(
  60. 'To activate sampling rules, it’s a requirement to update the following project SDK(s):'
  61. )}
  62. <Projects>
  63. {recommendedSdkUpgrades.map(recommendedSdkUpgrade => (
  64. <ProjectBadge
  65. key={recommendedSdkUpgrade.project.id}
  66. project={recommendedSdkUpgrade.project}
  67. avatarSize={16}
  68. />
  69. ))}
  70. </Projects>
  71. </Alert>
  72. );
  73. }
  74. const Projects = styled('div')`
  75. display: flex;
  76. flex-wrap: wrap;
  77. gap: ${space(1.5)};
  78. justify-content: flex-start;
  79. margin-top: ${space(1)};
  80. `;