discoverSplitAlert.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {Tooltip} from 'sentry/components/tooltip';
  2. import {IconWarning} from 'sentry/icons';
  3. import {t, tct} from 'sentry/locale';
  4. import {DatasetSource} from 'sentry/utils/discover/types';
  5. import {type Widget, WidgetType} from 'sentry/views/dashboards/types';
  6. interface DiscoverSplitAlertProps {
  7. widget: Widget;
  8. onSetTransactionsDataset?: () => void;
  9. }
  10. export function useDiscoverSplitAlert({
  11. widget,
  12. onSetTransactionsDataset,
  13. }: DiscoverSplitAlertProps): JSX.Element | null {
  14. if (
  15. widget?.datasetSource !== DatasetSource.FORCED ||
  16. widget?.widgetType !== WidgetType.ERRORS
  17. ) {
  18. return null;
  19. }
  20. return tct(
  21. "We're splitting our datasets up to make it a bit easier to digest. We defaulted this widget to Errors. [editText]",
  22. {
  23. editText: onSetTransactionsDataset ? (
  24. <a
  25. onClick={() => {
  26. onSetTransactionsDataset();
  27. }}
  28. >
  29. {t('Switch to Transactions')}
  30. </a>
  31. ) : (
  32. t('Edit as you see fit.')
  33. ),
  34. }
  35. );
  36. }
  37. export function DiscoverSplitAlert({
  38. widget,
  39. onSetTransactionsDataset,
  40. }: DiscoverSplitAlertProps) {
  41. const splitAlert = useDiscoverSplitAlert({widget, onSetTransactionsDataset});
  42. if (widget?.datasetSource !== DatasetSource.FORCED) {
  43. return null;
  44. }
  45. if (splitAlert) {
  46. return (
  47. <Tooltip containerDisplayMode="inline-flex" isHoverable title={splitAlert}>
  48. <IconWarning color="warningText" aria-label={t('Dataset split warning')} />
  49. </Tooltip>
  50. );
  51. }
  52. return null;
  53. }