specifyClientRateModal.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  4. import Button from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import {t, tct} from 'sentry/locale';
  7. import {Organization, Project} from 'sentry/types';
  8. import {defined} from 'sentry/utils';
  9. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  10. import {SamplingProjectIncompatibleAlert} from '../samplingProjectIncompatibleAlert';
  11. import {isValidSampleRate, SERVER_SIDE_SAMPLING_DOC_LINK} from '../utils';
  12. import {useRecommendedSdkUpgrades} from '../utils/useRecommendedSdkUpgrades';
  13. import {FooterActions, Stepper, StyledNumberField} from './uniformRateModal';
  14. type SpecifyClientRateModalProps = ModalRenderProps & {
  15. onChange: (value: number | undefined) => void;
  16. onGoNext: () => void;
  17. onReadDocs: () => void;
  18. organization: Organization;
  19. projectId: Project['id'];
  20. value: number | undefined;
  21. };
  22. export function SpecifyClientRateModal({
  23. Header,
  24. Body,
  25. Footer,
  26. closeModal,
  27. onReadDocs,
  28. onGoNext,
  29. organization,
  30. projectId,
  31. value,
  32. onChange,
  33. }: SpecifyClientRateModalProps) {
  34. const {isProjectIncompatible} = useRecommendedSdkUpgrades({
  35. orgSlug: organization.slug,
  36. projectId,
  37. });
  38. function handleReadDocs() {
  39. trackAdvancedAnalyticsEvent('sampling.settings.modal.specify.client.rate_read_docs', {
  40. organization,
  41. project_id: projectId,
  42. });
  43. onReadDocs();
  44. }
  45. function handleGoNext() {
  46. trackAdvancedAnalyticsEvent('sampling.settings.modal.specify.client.rate_next', {
  47. organization,
  48. project_id: projectId,
  49. });
  50. if (!defined(value)) {
  51. return;
  52. }
  53. onGoNext();
  54. }
  55. const isValid = isValidSampleRate(value);
  56. return (
  57. <Fragment>
  58. <Header closeButton>
  59. <h4>{t('Specify current client(SDK) sample rate')}</h4>
  60. </Header>
  61. <Body>
  62. <StyledNumberField
  63. label={tct(
  64. 'Find the [textHighlight:tracesSampleRate] option in your SDK config, and copy it’s value into the field below.',
  65. {
  66. textHighlight: <TextHighlight />,
  67. }
  68. )}
  69. type="number"
  70. name="current-client-sampling"
  71. placeholder="0.1"
  72. step="0.1"
  73. value={value ?? null}
  74. onChange={newValue => {
  75. onChange(newValue === '' ? undefined : newValue);
  76. }}
  77. stacked
  78. flexibleControlStateSize
  79. inline={false}
  80. />
  81. <SamplingProjectIncompatibleAlert
  82. organization={organization}
  83. projectId={projectId}
  84. isProjectIncompatible={isProjectIncompatible}
  85. />
  86. </Body>
  87. <Footer>
  88. <FooterActions>
  89. <Button href={SERVER_SIDE_SAMPLING_DOC_LINK} onClick={handleReadDocs} external>
  90. {t('Read Docs')}
  91. </Button>
  92. <ButtonBar gap={1}>
  93. <Stepper>{t('Step 1 of 3')}</Stepper>
  94. <Button onClick={closeModal}>{t('Cancel')}</Button>
  95. <Button
  96. priority="primary"
  97. onClick={handleGoNext}
  98. disabled={!isValid || isProjectIncompatible}
  99. title={!isValid ? t('Sample rate is not valid') : undefined}
  100. >
  101. {t('Next')}
  102. </Button>
  103. </ButtonBar>
  104. </FooterActions>
  105. </Footer>
  106. </Fragment>
  107. );
  108. }
  109. const TextHighlight = styled('span')`
  110. color: ${p => p.theme.gray300};
  111. `;