index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {Fragment, useCallback, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {openModal} from 'sentry/actionCreators/modal';
  4. import {Button} from 'sentry/components/button';
  5. import {TabList, Tabs} from 'sentry/components/tabs';
  6. import {IconTable} from 'sentry/icons/iconTable';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  10. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  11. import {useSpanTags} from '../contexts/spanTagsContext';
  12. import {TracesTable} from './tracesTable/index';
  13. import {AggregatesTable} from './aggregatesTable';
  14. import {ColumnEditorModal} from './columnEditorModal';
  15. import {SpansTable} from './spansTable';
  16. enum Tab {
  17. SPAN = 'span',
  18. TRACE = 'trace',
  19. }
  20. interface ExploreTablesProps {}
  21. export function ExploreTables({}: ExploreTablesProps) {
  22. const [resultMode] = useResultMode();
  23. return (
  24. <Fragment>
  25. {resultMode === 'aggregate' && <ExploreAggregatesTable />}
  26. {resultMode === 'samples' && <ExploreSamplesTable />}
  27. </Fragment>
  28. );
  29. }
  30. function ExploreAggregatesTable() {
  31. return <AggregatesTable />;
  32. }
  33. function ExploreSamplesTable() {
  34. const [tab, setTab] = useState(Tab.SPAN);
  35. const [fields, setFields] = useSampleFields();
  36. const numberTags = useSpanTags('number');
  37. const stringTags = useSpanTags('string');
  38. const openColumnEditor = useCallback(() => {
  39. openModal(
  40. modalProps => (
  41. <ColumnEditorModal
  42. {...modalProps}
  43. columns={fields}
  44. onColumnsChange={setFields}
  45. stringTags={stringTags}
  46. numberTags={numberTags}
  47. />
  48. ),
  49. {closeEvents: 'escape-key'}
  50. );
  51. }, [fields, setFields, stringTags, numberTags]);
  52. return (
  53. <Fragment>
  54. <SamplesTableHeader>
  55. <Tabs value={tab} onChange={setTab}>
  56. <TabList hideBorder>
  57. <TabList.Item key={Tab.SPAN}>{t('Span Samples')}</TabList.Item>
  58. <TabList.Item key={Tab.TRACE}>{t('Trace Samples')}</TabList.Item>
  59. </TabList>
  60. </Tabs>
  61. <Button
  62. disabled={tab !== Tab.SPAN}
  63. onClick={openColumnEditor}
  64. icon={<IconTable />}
  65. >
  66. {t('Edit Table')}
  67. </Button>
  68. </SamplesTableHeader>
  69. {tab === Tab.SPAN && <SpansTable />}
  70. {tab === Tab.TRACE && <TracesTable />}
  71. </Fragment>
  72. );
  73. }
  74. const SamplesTableHeader = styled('div')`
  75. display: flex;
  76. flex-direction: row;
  77. justify-content: space-between;
  78. margin-bottom: ${space(2)};
  79. `;