@@ -12,6 +12,7 @@ import {
12
12
useExploreFields ,
13
13
useExploreMode ,
14
14
useSetExploreFields ,
15
+ useSetExploreMode ,
15
16
} from 'sentry/views/explore/contexts/pageParamsContext' ;
16
17
import { Mode } from 'sentry/views/explore/contexts/pageParamsContext/mode' ;
17
18
import { useSpanTags } from 'sentry/views/explore/contexts/spanTagsContext' ;
@@ -36,9 +37,83 @@ interface ExploreTablesProps extends BaseExploreTablesProps {
36
37
isProgressivelyLoading : boolean ;
37
38
spansTableResult : SpansTableResult ;
38
39
tracesTableResult : TracesTableResult ;
40
+ useTabs : boolean ;
39
41
}
40
42
41
43
export function ExploreTables ( props : ExploreTablesProps ) {
44
+ if ( props . useTabs ) {
45
+ return < ExploreTablesTabbed { ...props } /> ;
46
+ }
47
+ return < ExploreTablesUntabbed { ...props } /> ;
48
+ }
49
+
50
+ function ExploreTablesTabbed ( props : ExploreTablesProps ) {
51
+ const mode = useExploreMode ( ) ;
52
+ const setMode = useSetExploreMode ( ) ;
53
+
54
+ const fields = useExploreFields ( ) ;
55
+ const setFields = useSetExploreFields ( ) ;
56
+
57
+ const { tags : numberTags } = useSpanTags ( 'number' ) ;
58
+ const { tags : stringTags } = useSpanTags ( 'string' ) ;
59
+
60
+ const openColumnEditor = useCallback ( ( ) => {
61
+ openModal (
62
+ modalProps => (
63
+ < ColumnEditorModal
64
+ { ...modalProps }
65
+ columns = { fields }
66
+ onColumnsChange = { setFields }
67
+ stringTags = { stringTags }
68
+ numberTags = { numberTags }
69
+ />
70
+ ) ,
71
+ { closeEvents : 'escape-key' }
72
+ ) ;
73
+ } , [ fields , setFields , stringTags , numberTags ] ) ;
74
+
75
+ // HACK: This is pretty gross but to not break anything in the
76
+ // short term, we avoid introducing/removing any fields on the
77
+ // query. So we continue using the existing `mode` value and
78
+ // coalesce it with the `tab` value` to create a single tab.
79
+ const tab = mode === Mode . AGGREGATE ? mode : props . samplesTab ;
80
+ const setTab = useCallback (
81
+ ( option : Tab | Mode ) => {
82
+ if ( option === Mode . AGGREGATE ) {
83
+ setMode ( Mode . AGGREGATE ) ;
84
+ } else if ( option === Tab . SPAN || option === Tab . TRACE ) {
85
+ props . setSamplesTab ( option ) ;
86
+ }
87
+ } ,
88
+ [ setMode , props ]
89
+ ) ;
90
+
91
+ return (
92
+ < Fragment >
93
+ < SamplesTableHeader >
94
+ < Tabs value = { tab } onChange = { setTab } >
95
+ < TabList hideBorder >
96
+ < TabList . Item key = { Tab . SPAN } > { t ( 'Spans' ) } </ TabList . Item >
97
+ < TabList . Item key = { Tab . TRACE } > { t ( 'Traces' ) } </ TabList . Item >
98
+ < TabList . Item key = { Mode . AGGREGATE } > { t ( 'Aggregates' ) } </ TabList . Item >
99
+ </ TabList >
100
+ </ Tabs >
101
+ < Button
102
+ disabled = { tab !== Tab . SPAN }
103
+ onClick = { openColumnEditor }
104
+ icon = { < IconTable /> }
105
+ >
106
+ { t ( 'Edit Table' ) }
107
+ </ Button >
108
+ </ SamplesTableHeader >
109
+ { tab === Tab . SPAN && < SpansTable { ...props } /> }
110
+ { tab === Tab . TRACE && < TracesTable { ...props } /> }
111
+ { tab === Mode . AGGREGATE && < AggregatesTable { ...props } /> }
112
+ </ Fragment >
113
+ ) ;
114
+ }
115
+
116
+ function ExploreTablesUntabbed ( props : ExploreTablesProps ) {
42
117
const mode = useExploreMode ( ) ;
43
118
44
119
return (
0 commit comments