|
@@ -1,16 +1,18 @@
|
|
|
import {Fragment} from 'react';
|
|
|
-import {css} from '@emotion/react';
|
|
|
+import styled from '@emotion/styled';
|
|
|
|
|
|
import {
|
|
|
addErrorMessage,
|
|
|
addLoadingMessage,
|
|
|
addSuccessMessage,
|
|
|
} from 'sentry/actionCreators/indicator';
|
|
|
-import {Button} from 'sentry/components/button';
|
|
|
-import Confirm from 'sentry/components/confirm';
|
|
|
+import {openConfirmModal} from 'sentry/components/confirm';
|
|
|
import FieldGroup from 'sentry/components/forms/fieldGroup';
|
|
|
import ExternalLink from 'sentry/components/links/externalLink';
|
|
|
+import QuestionTooltip from 'sentry/components/questionTooltip';
|
|
|
+import {SegmentedControl} from 'sentry/components/segmentedControl';
|
|
|
import {t, tct} from 'sentry/locale';
|
|
|
+import {space} from 'sentry/styles/space';
|
|
|
import useOrganization from 'sentry/utils/useOrganization';
|
|
|
import {useUpdateOrganization} from 'sentry/views/settings/dynamicSampling/utils/useUpdateOrganization';
|
|
|
import {useAccess} from 'sentry/views/settings/projectMetrics/access';
|
|
@@ -50,65 +52,104 @@ export function SamplingModeField() {
|
|
|
});
|
|
|
|
|
|
const handleSwitchMode = () => {
|
|
|
- updateOrganization({
|
|
|
- samplingMode: samplingMode === 'organization' ? 'project' : 'organization',
|
|
|
+ openConfirmModal({
|
|
|
+ confirmText: t('Switch Mode'),
|
|
|
+ cancelText: t('Cancel'),
|
|
|
+ header: (
|
|
|
+ <h5>
|
|
|
+ {samplingMode === 'organization'
|
|
|
+ ? t('Switch to Manual Mode')
|
|
|
+ : t('Switch to Automatic Mode')}
|
|
|
+ </h5>
|
|
|
+ ),
|
|
|
+ message: (
|
|
|
+ <Fragment>
|
|
|
+ <p>
|
|
|
+ {samplingMode === 'organization'
|
|
|
+ ? switchToManualMessage
|
|
|
+ : switchToAutoMessage}
|
|
|
+ </p>
|
|
|
+ {samplingMode === 'organization' ? (
|
|
|
+ <p>{t('You can switch back to automatic mode at any time.')}</p>
|
|
|
+ ) : (
|
|
|
+ <p>
|
|
|
+ {tct(
|
|
|
+ 'By switching [strong:you will lose your manually defined sample rates].',
|
|
|
+ {
|
|
|
+ strong: <strong />,
|
|
|
+ }
|
|
|
+ )}
|
|
|
+ </p>
|
|
|
+ )}
|
|
|
+ </Fragment>
|
|
|
+ ),
|
|
|
+ onConfirm: () => {
|
|
|
+ updateOrganization({
|
|
|
+ samplingMode: samplingMode === 'organization' ? 'project' : 'organization',
|
|
|
+ });
|
|
|
+ },
|
|
|
});
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
<FieldGroup
|
|
|
disabled={!hasAccess}
|
|
|
- label={t('Switch Mode')}
|
|
|
- help={
|
|
|
- samplingMode === 'organization'
|
|
|
- ? t('Take control over the individual sample rates in your projects.')
|
|
|
- : t('Let Sentry monitor span volume and adjust sample rates automatically.')
|
|
|
- }
|
|
|
+ label={t('Sampling Mode')}
|
|
|
+ help={t('The current configuration mode for dynamic sampling.')}
|
|
|
>
|
|
|
- <Confirm
|
|
|
- disabled={!hasAccess || isPending}
|
|
|
- message={
|
|
|
- <Fragment>
|
|
|
- <p>
|
|
|
- {samplingMode === 'organization'
|
|
|
- ? switchToManualMessage
|
|
|
- : switchToAutoMessage}
|
|
|
- </p>
|
|
|
- {samplingMode === 'organization' ? (
|
|
|
- <p>{t('You can switch back to automatic mode at any time.')}</p>
|
|
|
- ) : (
|
|
|
- <p>
|
|
|
- {tct(
|
|
|
- 'By switching [strong:you will lose your manually defined sample rates].',
|
|
|
+ <ControlWrapper>
|
|
|
+ <SegmentedControl
|
|
|
+ disabled={!hasAccess || isPending}
|
|
|
+ label={t('Sampling mode')}
|
|
|
+ value={samplingMode}
|
|
|
+ onChange={handleSwitchMode}
|
|
|
+ >
|
|
|
+ <SegmentedControl.Item key="organization" textValue={t('Automatic')}>
|
|
|
+ <LabelWrapper>
|
|
|
+ {t('Automatic')}
|
|
|
+ <QuestionTooltip
|
|
|
+ isHoverable
|
|
|
+ size="sm"
|
|
|
+ title={tct(
|
|
|
+ 'Automatic mode allows you to set a target sample rate for your organization. Sentry automatically adjusts individual project rates to boost small projects and ensure equal visibility. [link:Learn more]',
|
|
|
{
|
|
|
- strong: <strong />,
|
|
|
+ link: (
|
|
|
+ <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
|
|
|
+ ),
|
|
|
}
|
|
|
)}
|
|
|
- </p>
|
|
|
- )}
|
|
|
- </Fragment>
|
|
|
- }
|
|
|
- header={
|
|
|
- <h5>
|
|
|
- {samplingMode === 'organization'
|
|
|
- ? t('Switch to Manual Mode')
|
|
|
- : t('Switch to Automatic Mode')}
|
|
|
- </h5>
|
|
|
- }
|
|
|
- confirmText={t('Switch Mode')}
|
|
|
- cancelText={t('Cancel')}
|
|
|
- onConfirm={handleSwitchMode}
|
|
|
- >
|
|
|
- <Button
|
|
|
- css={css`
|
|
|
- width: max-content;
|
|
|
- `}
|
|
|
- >
|
|
|
- {samplingMode === 'organization'
|
|
|
- ? t('Switch to Manual')
|
|
|
- : t('Switch to Automatic')}
|
|
|
- </Button>
|
|
|
- </Confirm>
|
|
|
+ />
|
|
|
+ </LabelWrapper>
|
|
|
+ </SegmentedControl.Item>
|
|
|
+ <SegmentedControl.Item key="project" textValue={t('Manual')}>
|
|
|
+ <LabelWrapper>
|
|
|
+ {t('Manual')}
|
|
|
+ <QuestionTooltip
|
|
|
+ isHoverable
|
|
|
+ size="sm"
|
|
|
+ title={tct(
|
|
|
+ 'Manual mode allows you to set fixed sample rates for each project. [link:Learn more]',
|
|
|
+ {
|
|
|
+ link: (
|
|
|
+ <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
|
|
|
+ ),
|
|
|
+ }
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ </LabelWrapper>
|
|
|
+ </SegmentedControl.Item>
|
|
|
+ </SegmentedControl>
|
|
|
+ </ControlWrapper>
|
|
|
</FieldGroup>
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+const ControlWrapper = styled('div')`
|
|
|
+ width: max-content;
|
|
|
+`;
|
|
|
+
|
|
|
+const LabelWrapper = styled('div')`
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: ${space(1)};
|
|
|
+`;
|