widgetDetails.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {TabList, TabPanels, Tabs} from 'sentry/components/tabs';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {isCustomMetric, MetricWidgetQueryParams} from 'sentry/utils/metrics';
  8. import {CodeLocations} from 'sentry/views/ddm/codeLocations';
  9. import {useDDMContext} from 'sentry/views/ddm/context';
  10. import {SampleTable} from 'sentry/views/ddm/sampleTable';
  11. enum Tab {
  12. SAMPLES = 'samples',
  13. CODE_LOCATIONS = 'codeLocations',
  14. }
  15. export function WidgetDetails() {
  16. const {selectedWidgetIndex, widgets, focusArea} = useDDMContext();
  17. const [selectedTab, setSelectedTab] = useState(Tab.SAMPLES);
  18. // the tray is minimized when the main content is maximized
  19. const selectedWidget = widgets[selectedWidgetIndex] as
  20. | MetricWidgetQueryParams
  21. | undefined;
  22. const isCodeLocationsDisabled =
  23. selectedWidget?.mri && !isCustomMetric({mri: selectedWidget.mri});
  24. if (isCodeLocationsDisabled && selectedTab === Tab.CODE_LOCATIONS) {
  25. setSelectedTab(Tab.SAMPLES);
  26. }
  27. return (
  28. <TrayWrapper>
  29. <Tabs value={selectedTab} onChange={setSelectedTab}>
  30. <TabList>
  31. <TabList.Item key={Tab.SAMPLES}>{t('Samples')}</TabList.Item>
  32. <TabList.Item
  33. textValue={t('Code Location')}
  34. key={Tab.CODE_LOCATIONS}
  35. disabled={isCodeLocationsDisabled}
  36. >
  37. <Tooltip
  38. title={t(
  39. 'This metric is automatically collected by Sentry. It is not bound to a specific line of your code.'
  40. )}
  41. disabled={!isCodeLocationsDisabled}
  42. >
  43. <span style={{pointerEvents: 'all'}}>{t('Code Location')}</span>
  44. </Tooltip>
  45. </TabList.Item>
  46. </TabList>
  47. <ContentWrapper>
  48. <TabPanels>
  49. <TabPanels.Item key={Tab.SAMPLES}>
  50. <SampleTable
  51. mri={selectedWidget?.mri}
  52. query={selectedWidget?.query}
  53. {...focusArea?.range}
  54. />
  55. </TabPanels.Item>
  56. <TabPanels.Item key={Tab.CODE_LOCATIONS}>
  57. <CodeLocations mri={selectedWidget?.mri} {...focusArea?.range} />
  58. </TabPanels.Item>
  59. </TabPanels>
  60. </ContentWrapper>
  61. </Tabs>
  62. </TrayWrapper>
  63. );
  64. }
  65. const TrayWrapper = styled('div')`
  66. padding-top: ${space(4)};
  67. display: grid;
  68. grid-template-rows: auto auto 1fr;
  69. `;
  70. const ContentWrapper = styled('div')`
  71. position: relative;
  72. padding: ${space(2)} 0;
  73. `;