sampleDataAlert.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. export function SampleDataAlert() {
  11. const user = ConfigStore.get('user');
  12. const organization = useOrganization();
  13. const {dismiss, isDismissed} = useDismissAlert({
  14. key: `${organization.slug}-${user.id}:sample-data-alert-dismissed`,
  15. });
  16. if (isDismissed) {
  17. return null;
  18. }
  19. return (
  20. <Alert type="warning" showIcon>
  21. <AlertContent>
  22. {t(
  23. 'Based on your search criteria and sample rate, the events available may be limited because Discover uses sampled data only.'
  24. )}
  25. <DismissButton
  26. priority="link"
  27. icon={<IconClose />}
  28. onClick={dismiss}
  29. aria-label={t('Dismiss Alert')}
  30. title={t('Dismiss Alert')}
  31. />
  32. </AlertContent>
  33. </Alert>
  34. );
  35. }
  36. const DismissButton = styled(Button)`
  37. color: ${p => p.theme.alert.warning.iconColor};
  38. pointer-events: all;
  39. &:hover {
  40. color: ${p => p.theme.alert.warning.iconHoverColor};
  41. opacity: 0.5;
  42. }
  43. `;
  44. const AlertContent = styled('div')`
  45. display: grid;
  46. grid-template-columns: 1fr max-content;
  47. gap: ${space(1)};
  48. align-items: center;
  49. `;