samplingModeSwitch.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import styled from '@emotion/styled';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import SwitchButton from 'sentry/components/switchButton';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t, tct} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import {openSamplingModeSwitchModal} from 'sentry/views/settings/dynamicSampling/samplingModeSwitchModal';
  9. import {useHasDynamicSamplingWriteAccess} from 'sentry/views/settings/dynamicSampling/utils/access';
  10. interface Props {
  11. /**
  12. * The initial target rate for the automatic sampling mode.
  13. */
  14. initialTargetRate?: number;
  15. }
  16. export function SamplingModeSwitch({initialTargetRate}: Props) {
  17. const {samplingMode} = useOrganization();
  18. const hasAccess = useHasDynamicSamplingWriteAccess();
  19. const handleSwitchMode = () => {
  20. openSamplingModeSwitchModal({
  21. samplingMode: samplingMode === 'organization' ? 'project' : 'organization',
  22. initialTargetRate,
  23. });
  24. };
  25. return (
  26. <Wrapper>
  27. <Tooltip
  28. title={tct(
  29. 'Manually specify the percentage of incoming traffic that should be stored for each project. [link:Read the docs]',
  30. {
  31. link: (
  32. <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
  33. ),
  34. }
  35. )}
  36. showUnderline
  37. >
  38. {t('Advanced Mode')}
  39. </Tooltip>
  40. <Tooltip
  41. disabled={hasAccess}
  42. title={t('You do not have permission to change this setting.')}
  43. >
  44. <SwitchButton
  45. size="lg"
  46. toggle={handleSwitchMode}
  47. isDisabled={!hasAccess}
  48. isActive={samplingMode === 'project'}
  49. />
  50. </Tooltip>
  51. </Wrapper>
  52. );
  53. }
  54. const Wrapper = styled('label')`
  55. display: flex;
  56. align-items: center;
  57. gap: ${space(1)};
  58. margin-bottom: 0;
  59. `;