organizationSampleRateField.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 {organizationSamplingForm} from 'sentry/views/settings/dynamicSampling/utils/organizationSamplingForm';
  8. import {useAccess} from 'sentry/views/settings/projectMetrics/access';
  9. const {useFormField} = organizationSamplingForm;
  10. export function OrganizationSampleRateField({}) {
  11. const field = useFormField('targetSampleRate');
  12. const {hasAccess} = useAccess({access: ['org:write']});
  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. width={100}
  33. type="number"
  34. min={0}
  35. max={100}
  36. disabled={!hasAccess}
  37. value={field.value}
  38. onChange={event => field.onChange(event.target.value)}
  39. />
  40. </Tooltip>
  41. {field.error ? (
  42. <ErrorMessage>{field.error}</ErrorMessage>
  43. ) : field.hasChanged ? (
  44. <PreviousValue>{t('previous: %f%%', field.initialValue)}</PreviousValue>
  45. ) : null}
  46. </InputWrapper>
  47. </FieldGroup>
  48. );
  49. }
  50. const PreviousValue = styled('span')`
  51. font-size: ${p => p.theme.fontSizeExtraSmall};
  52. color: ${p => p.theme.subText};
  53. `;
  54. const ErrorMessage = styled('span')`
  55. font-size: ${p => p.theme.fontSizeExtraSmall};
  56. color: ${p => p.theme.error};
  57. `;
  58. const InputWrapper = styled('div')`
  59. padding-top: 8px;
  60. height: 58px;
  61. display: flex;
  62. flex-direction: column;
  63. gap: 4px;
  64. `;