sampleDataAlert.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 ConfigStore from 'sentry/stores/configStore';
  7. import {space} from 'sentry/styles/space';
  8. import useDismissAlert from 'sentry/utils/useDismissAlert';
  9. import useOrganization from 'sentry/utils/useOrganization';
  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 = ConfigStore.get('user');
  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(
  31. condition => 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.iconColor};
  55. pointer-events: all;
  56. &:hover {
  57. color: ${p => p.theme.alert.warning.iconHoverColor};
  58. opacity: 0.5;
  59. }
  60. `;
  61. const AlertContent = styled('div')`
  62. display: grid;
  63. grid-template-columns: 1fr max-content;
  64. gap: ${space(1)};
  65. align-items: center;
  66. `;