index.tsx 2.5 KB

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