index.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 {useSpanTags} from 'sentry/views/explore/contexts/spanTagsContext';
  11. import {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  12. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  13. import {Tab, useTab} from 'sentry/views/explore/hooks/useTab';
  14. import {AggregatesTable} from 'sentry/views/explore/tables/aggregatesTable';
  15. import {ColumnEditorModal} from 'sentry/views/explore/tables/columnEditorModal';
  16. import {SpansTable} from 'sentry/views/explore/tables/spansTable';
  17. import {TracesTable} from 'sentry/views/explore/tables/tracesTable/index';
  18. interface ExploreTablesProps {
  19. setError: Dispatch<SetStateAction<string>>;
  20. }
  21. export function ExploreTables({setError}: ExploreTablesProps) {
  22. const [resultMode] = useResultMode();
  23. return (
  24. <Fragment>
  25. {resultMode === 'aggregate' && <ExploreAggregatesTable setError={setError} />}
  26. {resultMode === 'samples' && <ExploreSamplesTable setError={setError} />}
  27. </Fragment>
  28. );
  29. }
  30. function ExploreAggregatesTable({setError}: ExploreTablesProps) {
  31. return <AggregatesTable setError={setError} />;
  32. }
  33. function ExploreSamplesTable({setError}: ExploreTablesProps) {
  34. const [tab, setTab] = useTab();
  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 setError={setError} />}
  70. {tab === Tab.TRACE && <TracesTable setError={setError} />}
  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. `;