projectSampling.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {useState} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {Button} from 'sentry/components/button';
  5. import FieldGroup from 'sentry/components/forms/fieldGroup';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Panel from 'sentry/components/panels/panel';
  8. import PanelBody from 'sentry/components/panels/panelBody';
  9. import PanelHeader from 'sentry/components/panels/panelHeader';
  10. import QuestionTooltip from 'sentry/components/questionTooltip';
  11. import {SegmentedControl} from 'sentry/components/segmentedControl';
  12. import {Tooltip} from 'sentry/components/tooltip';
  13. import {t, tct} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import useProjects from 'sentry/utils/useProjects';
  16. import {ProjectsEditTable} from 'sentry/views/settings/dynamicSampling/projectsEditTable';
  17. import {SamplingModeField} from 'sentry/views/settings/dynamicSampling/samplingModeField';
  18. import {projectSamplingForm} from 'sentry/views/settings/dynamicSampling/utils/projectSamplingForm';
  19. const {useFormState, FormProvider} = projectSamplingForm;
  20. export function ProjectSampling() {
  21. const {projects} = useProjects();
  22. const [period, setPeriod] = useState<'24h' | '30d'>('24h');
  23. // TODO(aknaus): Fetch initial project rates from API
  24. const fakeInitialProjectRates = projects.reduce(
  25. (acc, project) => {
  26. acc[project.id] = (Math.round(Math.random() * 10000) / 100).toString();
  27. return acc;
  28. },
  29. {} as Record<string, string>
  30. );
  31. const formState = useFormState({
  32. projectRates: fakeInitialProjectRates,
  33. });
  34. return (
  35. <FormProvider formState={formState}>
  36. <form onSubmit={event => event.preventDefault()}>
  37. <Panel>
  38. <PanelHeader>{t('Manual Sampling')}</PanelHeader>
  39. <PanelBody>
  40. <FieldGroup
  41. label={t('Sampling Mode')}
  42. help={t('The current configuration mode for dynamic sampling.')}
  43. >
  44. <div
  45. css={css`
  46. display: flex;
  47. align-items: center;
  48. gap: ${space(1)};
  49. `}
  50. >
  51. {t('Manual')}{' '}
  52. <QuestionTooltip
  53. size="sm"
  54. isHoverable
  55. title={tct(
  56. 'Manual mode allows you to set fixed sample rates for each project. [link:Learn more]',
  57. {
  58. link: (
  59. <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
  60. ),
  61. }
  62. )}
  63. />
  64. </div>
  65. </FieldGroup>
  66. <SamplingModeField />
  67. </PanelBody>
  68. </Panel>
  69. <HeadingRow>
  70. <h4>{t('Customize Projects')}</h4>
  71. <Tooltip
  72. title={t(
  73. 'The time period for which the projected sample rates are calculated.'
  74. )}
  75. >
  76. <SegmentedControl value={period} onChange={setPeriod} size="xs">
  77. <SegmentedControl.Item key="24h">{t('24h')}</SegmentedControl.Item>
  78. <SegmentedControl.Item key="30d">{t('30d')}</SegmentedControl.Item>
  79. </SegmentedControl>
  80. </Tooltip>
  81. </HeadingRow>
  82. <p>{t('Set custom rates for traces starting at each of your projects.')}</p>
  83. <ProjectsEditTable period={period} />
  84. <FormActions>
  85. <Button disabled>{t('Reset')}</Button>
  86. <Button priority="primary" disabled>
  87. {t('Apply Changes')}
  88. </Button>
  89. </FormActions>
  90. </form>
  91. </FormProvider>
  92. );
  93. }
  94. const FormActions = styled('div')`
  95. display: grid;
  96. grid-template-columns: repeat(2, max-content);
  97. gap: ${space(1)};
  98. justify-content: flex-end;
  99. padding-bottom: ${space(4)};
  100. `;
  101. const HeadingRow = styled('div')`
  102. display: flex;
  103. align-items: center;
  104. justify-content: space-between;
  105. padding-top: ${space(3)};
  106. padding-bottom: ${space(1.5)};
  107. & > * {
  108. margin: 0;
  109. }
  110. `;