Skip to content

Commit 73da474

Browse files
fix: select column option in export button (#10709)
* fix: all option in trace export * fix: remove the hack, user can select fields * fix: hide column selection for trace export
1 parent 028c134 commit 73da474

File tree

5 files changed

+85
-21
lines changed

5 files changed

+85
-21
lines changed

frontend/src/components/DownloadOptionsMenu/DownloadOptionsMenu.test.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ describe.each([
116116
expect(screen.getByRole('dialog')).toBeInTheDocument();
117117
expect(screen.getByText('FORMAT')).toBeInTheDocument();
118118
expect(screen.getByText('Number of Rows')).toBeInTheDocument();
119-
expect(screen.getByText('Columns')).toBeInTheDocument();
119+
120+
if (dataSource === DataSource.TRACES) {
121+
expect(screen.queryByText('Columns')).not.toBeInTheDocument();
122+
} else {
123+
expect(screen.getByText('Columns')).toBeInTheDocument();
124+
}
120125
});
121126

122127
it('allows changing export format', () => {
@@ -146,6 +151,17 @@ describe.each([
146151
});
147152

148153
it('allows changing columns scope', () => {
154+
if (dataSource === DataSource.TRACES) {
155+
renderWithStore(dataSource);
156+
fireEvent.click(screen.getByTestId(testId));
157+
158+
expect(screen.queryByRole('radio', { name: 'All' })).not.toBeInTheDocument();
159+
expect(
160+
screen.queryByRole('radio', { name: 'Selected' }),
161+
).not.toBeInTheDocument();
162+
return;
163+
}
164+
149165
renderWithStore(dataSource);
150166
fireEvent.click(screen.getByTestId(testId));
151167

@@ -210,7 +226,12 @@ describe.each([
210226
mockUseQueryBuilder.mockReturnValue({ stagedQuery: mockQuery });
211227
renderWithStore(dataSource);
212228
fireEvent.click(screen.getByTestId(testId));
213-
fireEvent.click(screen.getByRole('radio', { name: 'Selected' }));
229+
230+
// For traces, column scope is always Selected and the radio is hidden
231+
if (dataSource !== DataSource.TRACES) {
232+
fireEvent.click(screen.getByRole('radio', { name: 'Selected' }));
233+
}
234+
214235
fireEvent.click(screen.getByText('Export'));
215236

216237
await waitFor(() => {
@@ -227,6 +248,11 @@ describe.each([
227248
});
228249

229250
it('sends no selectFields when column scope is All', async () => {
251+
// For traces, column scope is always Selected — this test only applies to other sources
252+
if (dataSource === DataSource.TRACES) {
253+
return;
254+
}
255+
230256
renderWithStore(dataSource);
231257
fireEvent.click(screen.getByTestId(testId));
232258
fireEvent.click(screen.getByRole('radio', { name: 'All' }));

frontend/src/components/DownloadOptionsMenu/DownloadOptionsMenu.tsx

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useMemo, useState } from 'react';
22
import { Button, Popover, Radio, Tooltip, Typography } from 'antd';
3+
import { TelemetryFieldKey } from 'api/v5/v5';
34
import { useExportRawData } from 'hooks/useDownloadOptionsMenu/useDownloadOptionsMenu';
45
import { Download, DownloadIcon, Loader2 } from 'lucide-react';
56
import { DataSource } from 'types/common/queryBuilder';
@@ -14,10 +15,12 @@ import './DownloadOptionsMenu.styles.scss';
1415

1516
interface DownloadOptionsMenuProps {
1617
dataSource: DataSource;
18+
selectedColumns?: TelemetryFieldKey[];
1719
}
1820

1921
export default function DownloadOptionsMenu({
2022
dataSource,
23+
selectedColumns,
2124
}: DownloadOptionsMenuProps): JSX.Element {
2225
const [exportFormat, setExportFormat] = useState<string>(DownloadFormats.CSV);
2326
const [rowLimit, setRowLimit] = useState<number>(DownloadRowCounts.TEN_K);
@@ -35,9 +38,19 @@ export default function DownloadOptionsMenu({
3538
await handleExportRawData({
3639
format: exportFormat,
3740
rowLimit,
38-
clearSelectColumns: columnsScope === DownloadColumnsScopes.ALL,
41+
clearSelectColumns:
42+
dataSource !== DataSource.TRACES &&
43+
columnsScope === DownloadColumnsScopes.ALL,
44+
selectedColumns,
3945
});
40-
}, [exportFormat, rowLimit, columnsScope, handleExportRawData]);
46+
}, [
47+
exportFormat,
48+
rowLimit,
49+
columnsScope,
50+
selectedColumns,
51+
handleExportRawData,
52+
dataSource,
53+
]);
4154

4255
const popoverContent = useMemo(
4356
() => (
@@ -72,18 +85,22 @@ export default function DownloadOptionsMenu({
7285
</Radio.Group>
7386
</div>
7487

75-
<div className="horizontal-line" />
88+
{dataSource !== DataSource.TRACES && (
89+
<>
90+
<div className="horizontal-line" />
7691

77-
<div className="columns-scope">
78-
<Typography.Text className="title">Columns</Typography.Text>
79-
<Radio.Group
80-
value={columnsScope}
81-
onChange={(e): void => setColumnsScope(e.target.value)}
82-
>
83-
<Radio value={DownloadColumnsScopes.ALL}>All</Radio>
84-
<Radio value={DownloadColumnsScopes.SELECTED}>Selected</Radio>
85-
</Radio.Group>
86-
</div>
92+
<div className="columns-scope">
93+
<Typography.Text className="title">Columns</Typography.Text>
94+
<Radio.Group
95+
value={columnsScope}
96+
onChange={(e): void => setColumnsScope(e.target.value)}
97+
>
98+
<Radio value={DownloadColumnsScopes.ALL}>All</Radio>
99+
<Radio value={DownloadColumnsScopes.SELECTED}>Selected</Radio>
100+
</Radio.Group>
101+
</div>
102+
</>
103+
)}
87104

88105
<Button
89106
type="primary"
@@ -97,7 +114,14 @@ export default function DownloadOptionsMenu({
97114
</Button>
98115
</div>
99116
),
100-
[exportFormat, rowLimit, columnsScope, isDownloading, handleExport],
117+
[
118+
exportFormat,
119+
rowLimit,
120+
columnsScope,
121+
isDownloading,
122+
handleExport,
123+
dataSource,
124+
],
101125
);
102126

103127
return (

frontend/src/container/LogsExplorerViews/LogsActionsContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ function LogsActionsContainer({
9292
/>
9393
</div>
9494
<div className="download-options-container">
95-
<DownloadOptionsMenu dataSource={DataSource.LOGS} />
95+
<DownloadOptionsMenu
96+
dataSource={DataSource.LOGS}
97+
selectedColumns={options?.selectColumns}
98+
/>
9699
</div>
97100
<div className="format-options-container">
98101
<LogsFormatOptionsMenu

frontend/src/container/TracesExplorer/ListView/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ function ListView({
239239
/>
240240
</div>
241241

242-
<DownloadOptionsMenu dataSource={DataSource.TRACES} />
242+
<DownloadOptionsMenu
243+
dataSource={DataSource.TRACES}
244+
selectedColumns={options?.selectColumns}
245+
/>
243246

244247
<TraceExplorerControls
245248
isLoading={isFetching}

frontend/src/hooks/useDownloadOptionsMenu/useDownloadOptionsMenu.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useCallback, useState } from 'react';
33
import { useSelector } from 'react-redux';
44
import { message } from 'antd';
55
import { downloadExportData } from 'api/v1/download/downloadExportData';
6-
import { prepareQueryRangePayloadV5 } from 'api/v5/v5';
6+
import { prepareQueryRangePayloadV5, TelemetryFieldKey } from 'api/v5/v5';
77
import { PANEL_TYPES } from 'constants/queryBuilder';
88
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
99
import { AppState } from 'store/reducers';
@@ -14,6 +14,7 @@ interface ExportOptions {
1414
format: string;
1515
rowLimit: number;
1616
clearSelectColumns: boolean;
17+
selectedColumns?: TelemetryFieldKey[];
1718
}
1819

1920
interface UseExportRawDataProps {
@@ -42,6 +43,7 @@ export function useExportRawData({
4243
format,
4344
rowLimit,
4445
clearSelectColumns,
46+
selectedColumns,
4547
}: ExportOptions): Promise<void> => {
4648
if (!stagedQuery) {
4749
return;
@@ -50,6 +52,12 @@ export function useExportRawData({
5052
try {
5153
setIsDownloading(true);
5254

55+
const selectColumnsOverride = clearSelectColumns
56+
? {}
57+
: selectedColumns?.length
58+
? { selectColumns: selectedColumns }
59+
: {};
60+
5361
const exportQuery = {
5462
...stagedQuery,
5563
builder: {
@@ -59,15 +67,15 @@ export function useExportRawData({
5967
groupBy: [],
6068
having: { expression: '' },
6169
limit: rowLimit,
62-
...(clearSelectColumns && { selectColumns: [] }),
70+
...selectColumnsOverride,
6371
})),
6472
queryTraceOperator: (stagedQuery.builder.queryTraceOperator || []).map(
6573
(traceOp) => ({
6674
...traceOp,
6775
groupBy: [],
6876
having: { expression: '' },
6977
limit: rowLimit,
70-
...(clearSelectColumns && { selectColumns: [] }),
78+
...selectColumnsOverride,
7179
}),
7280
),
7381
},

0 commit comments

Comments
 (0)