onDemandMetricAlert.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import {Button} from 'sentry/components/button';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {IconClose, IconWarning} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import {Color} from 'sentry/utils/theme';
  9. import useDismissAlert from 'sentry/utils/useDismissAlert';
  10. const EXTRAPOLATED_AREA_STRIPE_IMG =
  11. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAABkAQMAAACFAjPUAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAZQTFRFpKy5SVlzL3npZAAAAA9JREFUeJxjsD/AMIqIQwBIyGOd43jaDwAAAABJRU5ErkJggg==';
  12. export const extrapolatedAreaStyle = {
  13. color: {
  14. repeat: 'repeat',
  15. image: EXTRAPOLATED_AREA_STRIPE_IMG,
  16. rotation: 0.785,
  17. scaleX: 0.5,
  18. },
  19. opacity: 1.0,
  20. };
  21. export function OnDemandWarningIcon({
  22. msg,
  23. color = 'gray300',
  24. }: {
  25. msg: React.ReactNode;
  26. color?: Color;
  27. }) {
  28. return (
  29. <Tooltip skipWrapper title={msg}>
  30. <HoverableIconWarning color={color} />
  31. </Tooltip>
  32. );
  33. }
  34. const LOCAL_STORAGE_KEY = 'on-demand-empty-alert-dismissed';
  35. export function OnDemandMetricAlert({
  36. message,
  37. dismissable = false,
  38. }: {
  39. message: React.ReactNode;
  40. dismissable?: boolean;
  41. }) {
  42. const {dismiss, isDismissed} = useDismissAlert({key: LOCAL_STORAGE_KEY});
  43. if (dismissable && isDismissed) {
  44. return null;
  45. }
  46. return (
  47. <InfoAlert showIcon>
  48. {message}
  49. {dismissable && (
  50. <DismissButton
  51. priority="link"
  52. size="sm"
  53. icon={<IconClose size="xs" />}
  54. aria-label={t('Close Alert')}
  55. onClick={dismiss}
  56. />
  57. )}
  58. </InfoAlert>
  59. );
  60. }
  61. const InfoAlert = styled(Alert)`
  62. display: flex;
  63. align-items: flex-start;
  64. & > span {
  65. display: flex;
  66. flex-grow: 1;
  67. justify-content: space-between;
  68. line-height: 1.5em;
  69. }
  70. `;
  71. const DismissButton = styled(Button)`
  72. pointer-events: all;
  73. &:hover {
  74. opacity: 0.5;
  75. }
  76. `;
  77. const HoverableIconWarning = styled(IconWarning)`
  78. &:hover {
  79. cursor: pointer;
  80. }
  81. `;