organizationSampleRateField.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import FieldGroup from 'sentry/components/forms/fieldGroup';
  4. import {InputGroup} from 'sentry/components/inputGroup';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {t} from 'sentry/locale';
  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. error={field.error}
  22. >
  23. <InputWrapper
  24. css={css`
  25. width: 150px;
  26. `}
  27. >
  28. <Tooltip
  29. disabled={hasAccess}
  30. title={t('You do not have permission to change the sample rate.')}
  31. >
  32. <InputGroup>
  33. <InputGroup.Input
  34. width={100}
  35. type="number"
  36. min={0}
  37. max={100}
  38. disabled={!hasAccess}
  39. value={field.value}
  40. onChange={event => field.onChange(event.target.value)}
  41. />
  42. <InputGroup.TrailingItems>
  43. <TrailingPercent>%</TrailingPercent>
  44. </InputGroup.TrailingItems>
  45. </InputGroup>
  46. </Tooltip>
  47. {field.hasChanged ? (
  48. <PreviousValue>{t('previous: %f%%', field.initialValue)}</PreviousValue>
  49. ) : null}
  50. </InputWrapper>
  51. </FieldGroup>
  52. );
  53. }
  54. const PreviousValue = styled('span')`
  55. font-size: ${p => p.theme.fontSizeExtraSmall};
  56. color: ${p => p.theme.subText};
  57. `;
  58. const InputWrapper = styled('div')`
  59. padding-top: 8px;
  60. height: 58px;
  61. display: flex;
  62. flex-direction: column;
  63. gap: 4px;
  64. `;
  65. const TrailingPercent = styled('strong')`
  66. padding: 0 2px;
  67. `;