dynamicSamplingForm.tsx 745 B

123456789101112131415161718192021222324252627
  1. import {t} from 'sentry/locale';
  2. import {createForm} from 'sentry/views/settings/dynamicSampling/formContext';
  3. type FormFields = {
  4. samplingMode: 'auto' | 'manual';
  5. targetSampleRate: string;
  6. };
  7. export const dynamicSamplingForm = createForm<FormFields>({
  8. validators: {
  9. targetSampleRate: (value: string) => {
  10. if (value === '') {
  11. return t('This field is required.');
  12. }
  13. const numericValue = Number(value);
  14. if (isNaN(numericValue) ? t('Please enter a valid number.') : undefined) {
  15. return t('Please enter a valid number.');
  16. }
  17. if (numericValue < 0 || numericValue > 100) {
  18. return t('The sample rate must be between 0% and 100%');
  19. }
  20. return undefined;
  21. },
  22. },
  23. });