Skip to content

Commit 1655397

Browse files
authored
feat: allowing switching between views when groupby is present (#9386)
* feat: allowing switching between views when groupby is present * feat: allowing switching between views when groupby is present * chore: remove console log
1 parent 718360a commit 1655397

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

frontend/src/pages/TracesExplorer/index.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function TracesExplorer(): JSX.Element {
5656
handleRunQuery,
5757
stagedQuery,
5858
handleSetConfig,
59+
updateQueriesData,
5960
} = useQueryBuilder();
6061

6162
const { options } = useOptionsMenu({
@@ -116,18 +117,33 @@ function TracesExplorer(): JSX.Element {
116117
set(stagedQuery, 'builder.queryTraceOperator[0].orderBy', []);
117118
}
118119

120+
if (view === ExplorerViews.LIST || view === ExplorerViews.TRACE) {
121+
// loop through all the queries and remove the group by
122+
123+
const updateQuery = updateQueriesData(
124+
currentQuery,
125+
'queryData',
126+
(item) => ({ ...item, groupBy: [], orderBy: [] }),
127+
);
128+
129+
setDefaultQuery(updateQuery);
130+
131+
setShouldReset(true);
132+
}
133+
119134
setSelectedView(view);
120135

121136
handleExplorerTabChange(
122137
view === ExplorerViews.TIMESERIES ? PANEL_TYPES.TIME_SERIES : view,
123138
);
124139
},
125140
[
126-
handleSetConfig,
127-
handleExplorerTabChange,
128141
selectedView,
129-
setSelectedView,
142+
currentQuery,
130143
stagedQuery,
144+
handleExplorerTabChange,
145+
handleSetConfig,
146+
updateQueriesData,
131147
],
132148
);
133149

@@ -194,11 +210,6 @@ function TracesExplorer(): JSX.Element {
194210

195211
useShareBuilderUrl({ defaultValue: defaultQuery, forceReset: shouldReset });
196212

197-
const isGroupByExist = useMemo(() => {
198-
const queryData = currentQuery?.builder?.queryData ?? [];
199-
return queryData.some((q) => (q?.groupBy?.length ?? 0) > 0);
200-
}, [currentQuery]);
201-
202213
const hasMultipleQueries = useMemo(
203214
() => currentQuery?.builder?.queryData?.length > 1,
204215
[currentQuery],
@@ -230,19 +241,6 @@ function TracesExplorer(): JSX.Element {
230241
return `Please use a Trace Operator to combine results of multiple span queries. Else you'd only see the results from query "${firstQuery.queryName}"`;
231242
}, [currentQuery]);
232243

233-
useEffect(() => {
234-
const shouldChangeView = isGroupByExist;
235-
236-
if (
237-
(selectedView === ExplorerViews.LIST ||
238-
selectedView === ExplorerViews.TRACE) &&
239-
shouldChangeView
240-
) {
241-
// Switch to timeseries view automatically
242-
handleChangeSelectedView(ExplorerViews.TIMESERIES);
243-
}
244-
}, [selectedView, isGroupByExist, handleChangeSelectedView]);
245-
246244
useEffect(() => {
247245
if (shouldReset) {
248246
setShouldReset(false);

0 commit comments

Comments
 (0)