datasetSelector.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import FeatureBadge from 'sentry/components/badge/featureBadge';
  4. import RadioGroup, {type RadioOption} from 'sentry/components/forms/controls/radioGroup';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import {t, tct} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {WidgetType} from 'sentry/views/dashboards/types';
  10. import {SectionHeader} from 'sentry/views/dashboards/widgetBuilder/components/common/sectionHeader';
  11. import {useWidgetBuilderContext} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
  12. import {BuilderStateAction} from 'sentry/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState';
  13. function WidgetBuilderDatasetSelector() {
  14. const organization = useOrganization();
  15. const {state, dispatch} = useWidgetBuilderContext();
  16. const datasetChoices: RadioOption<WidgetType>[] = [];
  17. datasetChoices.push([WidgetType.ERRORS, t('Errors')]);
  18. datasetChoices.push([WidgetType.TRANSACTIONS, t('Transactions')]);
  19. if (organization.features.includes('dashboards-eap')) {
  20. datasetChoices.push([
  21. WidgetType.SPANS,
  22. <FeatureBadgeAlignmentWrapper aria-label={t('Spans')} key={'dataset-choice-spans'}>
  23. {t('Spans')} <FeatureBadge type="alpha" />
  24. </FeatureBadgeAlignmentWrapper>,
  25. ]);
  26. }
  27. datasetChoices.push([WidgetType.ISSUE, t('Issues')]);
  28. datasetChoices.push([WidgetType.RELEASE, t('Releases')]);
  29. return (
  30. <Fragment>
  31. <StyledSectionHeader
  32. title={t('Dataset')}
  33. tooltipText={tct(
  34. `This reflects the type of information you want to use. To learn more, [link: read the docs].`,
  35. {
  36. link: (
  37. <ExternalLink href="https://docs.sentry.io/product/dashboards/widget-builder/#choose-your-dataset" />
  38. ),
  39. }
  40. )}
  41. />
  42. <DatasetChoices
  43. label={t('Dataset')}
  44. value={state.dataset ?? WidgetType.ERRORS}
  45. choices={datasetChoices}
  46. onChange={(newValue: WidgetType) =>
  47. dispatch({
  48. type: BuilderStateAction.SET_DATASET,
  49. payload: newValue,
  50. })
  51. }
  52. />
  53. </Fragment>
  54. );
  55. }
  56. export default WidgetBuilderDatasetSelector;
  57. const DatasetChoices = styled(RadioGroup<WidgetType>)`
  58. display: flex;
  59. flex-direction: row;
  60. flex-wrap: wrap;
  61. gap: ${space(2)};
  62. `;
  63. const FeatureBadgeAlignmentWrapper = styled('div')`
  64. ${FeatureBadge} {
  65. position: relative;
  66. top: -1px;
  67. }
  68. `;
  69. const StyledSectionHeader = styled(SectionHeader)`
  70. margin-bottom: ${space(2)};
  71. `;