sampleDataAlert.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import styled from '@emotion/styled';
  2. import {Alert} from 'sentry/components/alert';
  3. import {Button} from 'sentry/components/button';
  4. import {IconClose} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import useDismissAlert from 'sentry/utils/useDismissAlert';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {useUser} from 'sentry/utils/useUser';
  10. const EXCLUDED_CONDITIONS = [
  11. 'event.type:error',
  12. '!event.type:transaction',
  13. 'event.type:csp',
  14. 'event.type:default',
  15. 'handled:',
  16. 'unhandled:',
  17. 'culprit:',
  18. 'issue:',
  19. 'level:',
  20. 'unreal.crash_type:',
  21. 'stack.',
  22. 'error.',
  23. ];
  24. export function SampleDataAlert({query}: {query?: string}) {
  25. const user = useUser();
  26. const {slug, isDynamicallySampled} = useOrganization();
  27. const {dismiss, isDismissed} = useDismissAlert({
  28. key: `${slug}-${user.id}:sample-data-alert-dismissed`,
  29. });
  30. const isQueryingErrors = EXCLUDED_CONDITIONS.some(condition =>
  31. query?.includes(condition)
  32. );
  33. if (isDismissed || !isDynamicallySampled || isQueryingErrors) {
  34. return null;
  35. }
  36. return (
  37. <Alert.Container>
  38. <Alert type="warning" showIcon>
  39. <AlertContent>
  40. {t(
  41. 'Based on your search criteria and sample rate, the events available may be limited because Discover uses sampled data only.'
  42. )}
  43. <DismissButton
  44. priority="link"
  45. icon={<IconClose />}
  46. onClick={dismiss}
  47. aria-label={t('Dismiss Alert')}
  48. title={t('Dismiss Alert')}
  49. />
  50. </AlertContent>
  51. </Alert>
  52. </Alert.Container>
  53. );
  54. }
  55. const DismissButton = styled(Button)`
  56. color: ${p => p.theme.alert.warning.color};
  57. pointer-events: all;
  58. &:hover {
  59. opacity: 0.5;
  60. }
  61. `;
  62. const AlertContent = styled('div')`
  63. display: grid;
  64. grid-template-columns: 1fr max-content;
  65. gap: ${space(1)};
  66. align-items: center;
  67. `;