targetSampleRateField.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import styled from '@emotion/styled';
  2. import FieldGroup from 'sentry/components/forms/fieldGroup';
  3. import {InputGroup} from 'sentry/components/inputGroup';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {dynamicSamplingForm} from 'sentry/views/settings/dynamicSampling/dynamicSamplingForm';
  7. import {useAccess} from 'sentry/views/settings/projectMetrics/access';
  8. const {useFormField} = dynamicSamplingForm;
  9. export function TargetSampleRateField({}) {
  10. const field = useFormField('targetSampleRate');
  11. const {hasAccess} = useAccess({access: ['org:write']});
  12. return (
  13. <FieldGroup
  14. disabled={!hasAccess}
  15. required
  16. label={t('Target Sample Rate')}
  17. help={t(
  18. 'Sentry will balance the sample rates of your projects automatically based on an overall target for your organization.'
  19. )}
  20. error={field.error}
  21. >
  22. <InputWrapper>
  23. <Tooltip
  24. disabled={hasAccess}
  25. title={t('You do not have permission to change the sample rate.')}
  26. >
  27. <InputGroup>
  28. <InputGroup.Input
  29. width={100}
  30. type="number"
  31. disabled={!hasAccess}
  32. value={field.value}
  33. onChange={event => field.onChange(event.target.value)}
  34. />
  35. <InputGroup.TrailingItems>
  36. <TrailingPercent>%</TrailingPercent>
  37. </InputGroup.TrailingItems>
  38. </InputGroup>
  39. </Tooltip>
  40. {field.hasChanged ? (
  41. <PreviousValue>{t('previous rate: %f%%', field.initialValue)}</PreviousValue>
  42. ) : null}
  43. </InputWrapper>
  44. </FieldGroup>
  45. );
  46. }
  47. const PreviousValue = styled('span')`
  48. font-size: ${p => p.theme.fontSizeExtraSmall};
  49. color: ${p => p.theme.subText};
  50. `;
  51. const InputWrapper = styled('div')`
  52. padding-top: 8px;
  53. height: 58px;
  54. display: flex;
  55. flex-direction: column;
  56. gap: 4px;
  57. `;
  58. const TrailingPercent = styled('strong')`
  59. padding: 0 2px;
  60. `;