sampleDataAlert.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 type="warning" showIcon>
  38. <AlertContent>
  39. {t(
  40. 'Based on your search criteria and sample rate, the events available may be limited because Discover uses sampled data only.'
  41. )}
  42. <DismissButton
  43. priority="link"
  44. icon={<IconClose />}
  45. onClick={dismiss}
  46. aria-label={t('Dismiss Alert')}
  47. title={t('Dismiss Alert')}
  48. />
  49. </AlertContent>
  50. </Alert>
  51. );
  52. }
  53. const DismissButton = styled(Button)`
  54. color: ${p => p.theme.alert.warning.color};
  55. pointer-events: all;
  56. &:hover {
  57. opacity: 0.5;
  58. }
  59. `;
  60. const AlertContent = styled('div')`
  61. display: grid;
  62. grid-template-columns: 1fr max-content;
  63. gap: ${space(1)};
  64. align-items: center;
  65. `;