index.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  9. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  10. import {useSpanFieldSupportedTags} from 'sentry/views/performance/utils/useSpanFieldSupportedTags';
  11. import {ColumnEditorModal} from './columnEditorModal';
  12. import {SpansTable} from './spansTable';
  13. import {TracesTable} from './tracesTable';
  14. enum Tab {
  15. SPAN = 'span',
  16. TRACE = 'trace',
  17. }
  18. interface ExploreTablesProps {}
  19. export function ExploreTables({}: ExploreTablesProps) {
  20. const [resultMode] = useResultMode();
  21. return (
  22. <Fragment>
  23. {resultMode === 'aggregate' && <ExploreAggregateTable />}
  24. {resultMode === 'samples' && <ExploreSamplesTable />}
  25. </Fragment>
  26. );
  27. }
  28. function ExploreAggregateTable() {
  29. return <div>TODO: aggregate table</div>;
  30. }
  31. function ExploreSamplesTable() {
  32. const [tab, setTab] = useState(Tab.SPAN);
  33. const [fields, setFields] = useSampleFields();
  34. // TODO: This should be loaded from context to avoid loading tags twice.
  35. const tags = useSpanFieldSupportedTags();
  36. const openColumnEditor = useCallback(() => {
  37. openModal(
  38. modalProps => (
  39. <ColumnEditorModal
  40. {...modalProps}
  41. columns={fields}
  42. onColumnsChange={setFields}
  43. tags={tags}
  44. />
  45. ),
  46. {closeEvents: 'escape-key'}
  47. );
  48. }, [fields, setFields, tags]);
  49. return (
  50. <Fragment>
  51. <SamplesTableHeader>
  52. <Tabs value={tab} onChange={setTab}>
  53. <TabList hideBorder>
  54. <TabList.Item key={Tab.SPAN}>{t('Span Samples')}</TabList.Item>
  55. <TabList.Item key={Tab.TRACE}>{t('Trace Samples')}</TabList.Item>
  56. </TabList>
  57. </Tabs>
  58. <Button
  59. size="sm"
  60. disabled={tab !== Tab.SPAN}
  61. onClick={openColumnEditor}
  62. icon={<IconTable />}
  63. >
  64. {t('Columns')}
  65. </Button>
  66. </SamplesTableHeader>
  67. {tab === Tab.SPAN && <SpansTable />}
  68. {tab === Tab.TRACE && <TracesTable />}
  69. </Fragment>
  70. );
  71. }
  72. const SamplesTableHeader = styled('div')`
  73. display: flex;
  74. flex-direction: row;
  75. justify-content: space-between;
  76. `;