organizationSampleRateField.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import FieldGroup from 'sentry/components/forms/fieldGroup';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {PercentInput} from 'sentry/views/settings/dynamicSampling/percentInput';
  7. import {useHasDynamicSamplingWriteAccess} from 'sentry/views/settings/dynamicSampling/utils/access';
  8. import {organizationSamplingForm} from 'sentry/views/settings/dynamicSampling/utils/organizationSamplingForm';
  9. const {useFormField} = organizationSamplingForm;
  10. export function OrganizationSampleRateField({}) {
  11. const field = useFormField('targetSampleRate');
  12. const hasAccess = useHasDynamicSamplingWriteAccess();
  13. return (
  14. <FieldGroup
  15. disabled={!hasAccess}
  16. required
  17. label={t('Target Sample Rate')}
  18. help={t(
  19. 'Sentry automatically adapts the sample rates of your projects based on this organization-wide target.'
  20. )}
  21. >
  22. <InputWrapper
  23. css={css`
  24. width: 160px;
  25. `}
  26. >
  27. <Tooltip
  28. disabled={hasAccess}
  29. title={t('You do not have permission to change the sample rate.')}
  30. >
  31. <PercentInput
  32. type="number"
  33. disabled={!hasAccess}
  34. value={field.value}
  35. onChange={event => field.onChange(event.target.value)}
  36. />
  37. </Tooltip>
  38. {field.error ? (
  39. <ErrorMessage>{field.error}</ErrorMessage>
  40. ) : field.hasChanged ? (
  41. <PreviousValue>{t('previous: %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 ErrorMessage = styled('span')`
  52. font-size: ${p => p.theme.fontSizeExtraSmall};
  53. color: ${p => p.theme.error};
  54. `;
  55. const InputWrapper = styled('div')`
  56. padding-top: 8px;
  57. height: 58px;
  58. display: flex;
  59. flex-direction: column;
  60. gap: 4px;
  61. `;