samplingModal.tsx 3.1 KB

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