samplingModal.tsx 3.1 KB

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