samplingModal.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import type {ReactNode} from 'react';
  2. import {Fragment, useState} from 'react';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  6. import {Button} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import RadioGroup from 'sentry/components/forms/controls/radioGroup';
  9. import Link from 'sentry/components/links/link';
  10. import {t, tct} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import type {Organization, Project} from 'sentry/types';
  13. import type EventView from 'sentry/utils/discover/eventView';
  14. type Props = {
  15. eventView: EventView;
  16. isMEPEnabled: boolean;
  17. onApply: (isMEPEnabled: boolean) => void;
  18. organization: Organization;
  19. projects: Project[];
  20. } & ModalRenderProps;
  21. function SamplingModal(props: Props) {
  22. const {Header, Body, Footer, organization, eventView, isMEPEnabled, projects} = props;
  23. const project = projects.find(p => `${eventView.project[0]}` === p.id);
  24. const choices: [string, ReactNode][] = [
  25. ['true', t('Automatically switch to sampled data when required')],
  26. ['false', t('Always show sampled data')],
  27. ];
  28. const [choice, setChoice] = useState(choices[isMEPEnabled ? 0 : 1][0]);
  29. return (
  30. <Fragment>
  31. <Header closeButton>
  32. <h4>{t('Sampling Settings')}</h4>
  33. </Header>
  34. <Body>
  35. <Instruction>
  36. {tct(
  37. "The visualizations shown are based on your data without any filters or sampling. This does not contribute to your quota usage but transaction details are limited. If you'd like to improve accuracy, we recommend adding more transactions to your quota. or modifying your dataset through [projectSettings: Sampling in settings].",
  38. {
  39. projectSettings: (
  40. <Link
  41. to={`/settings/${organization.slug}/projects/${project?.slug}/performance/`}
  42. />
  43. ),
  44. }
  45. )}
  46. </Instruction>
  47. <Instruction>
  48. <RadioGroup
  49. style={{flex: 1}}
  50. choices={choices}
  51. value={choice}
  52. label=""
  53. onChange={(id: string) => setChoice(id)}
  54. />
  55. </Instruction>
  56. </Body>
  57. <Footer>
  58. <ButtonBar gap={1}>
  59. <Button priority="default" onClick={() => {}} data-test-id="reset-all">
  60. {t('Read the docs')}
  61. </Button>
  62. <Button
  63. aria-label={t('Apply')}
  64. priority="primary"
  65. onClick={event => {
  66. event.preventDefault();
  67. props.closeModal();
  68. // Use onApply since modal might be outside of the provider due to portal/wormholing.
  69. props.onApply(choice === 'true');
  70. }}
  71. data-test-id="apply-threshold"
  72. >
  73. {t('Apply')}
  74. </Button>
  75. </ButtonBar>
  76. </Footer>
  77. </Fragment>
  78. );
  79. }
  80. const Instruction = styled('div')`
  81. margin-bottom: ${space(4)};
  82. `;
  83. export default SamplingModal;
  84. export const modalCss = css`
  85. width: 100%;
  86. max-width: 650px;
  87. margin: 70px auto;
  88. `;