index.tsx 2.9 KB

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