Skip to content

Commit f356a2b

Browse files
committed
fix: column indices
1 parent f545e49 commit f356a2b

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

src/components/QueryResultTable/utils/getColumnWidth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
import {INDEX_COLUMN} from '../../../store/reducers/query/query';
12
import type {KeyValueRow} from '../../../types/api/query';
23

34
export const MAX_COLUMN_WIDTH = 600;
45
export const HEADER_PADDING = 20;
6+
export const INDEX_COLUMN_WIDTH = 80;
57

68
export const getColumnWidth = ({data, name}: {data?: KeyValueRow[]; name: string}) => {
79
let maxColumnContentLength = name.length;
810

11+
if (INDEX_COLUMN.name === name) {
12+
return INDEX_COLUMN_WIDTH;
13+
}
14+
915
if (data) {
1016
for (const row of data) {
1117
const cellLength = row[name] ? String(row[name]).length : 0;

src/components/ResizeableDataTable/ResizeableDataTable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {DataTableProps, Settings} from '@gravity-ui/react-data-table';
22
import DataTable, {updateColumnsWidth} from '@gravity-ui/react-data-table';
33

4+
import {INDEX_COLUMN} from '../../store/reducers/query/query';
45
import {cn} from '../../utils/cn';
56
import {useTableResize} from '../../utils/hooks/useTableResize';
67

@@ -27,6 +28,7 @@ export function ResizeableDataTable<T>({
2728
const newSettings: Settings = {
2829
...settings,
2930
defaultResizeable: true,
31+
displayIndices: columns.filter(({name}) => INDEX_COLUMN.name === name).length === 0,
3032
};
3133

3234
return (

src/services/api/viewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export class ViewerAPI extends BaseYdbAPI {
451451
const resultIndex = chunk.meta.result_index;
452452
const mergedChunk = mergedChunks.get(resultIndex);
453453

454-
if (mergedChunk) {
454+
if (mergedChunk && mergedChunk.result.rows && chunk.result.rows) {
455455
mergedChunk.result.rows.push(...chunk.result.rows);
456456
} else {
457457
mergedChunks.set(resultIndex, chunk);

src/store/reducers/query/query.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {createSlice} from '@reduxjs/toolkit';
33
import type {PayloadAction} from '@reduxjs/toolkit';
44

55
import {settingsManager} from '../../../services/settings';
6+
import type {ColumnType} from '../../../types/api/query';
67
import {TracingLevelNumber} from '../../../types/api/query';
78
import type {QueryAction, QueryRequestParams, QuerySettings} from '../../../types/store/query';
89
import type {StreamingChunk} from '../../../types/store/streaming';
@@ -23,6 +24,7 @@ import {
2324
} from './utils';
2425

2526
const MAXIMUM_QUERIES_IN_HISTORY = 20;
27+
export const INDEX_COLUMN: ColumnType = {name: '#', type: 'Uint64'};
2628

2729
const queriesHistoryInitial = settingsManager.readUserSettingsValue(
2830
QUERIES_HISTORY_KEY,
@@ -152,20 +154,33 @@ const slice = createSlice({
152154
} = chunk;
153155

154156
if (columns && !state.result.data.resultSets?.[resultIndex]?.columns?.length) {
157+
const columnsWithIndex = [INDEX_COLUMN, ...columns];
155158
if (!state.result.data.resultSets) {
156159
state.result.data.resultSets = [];
157160
}
158161

159162
if (state.result.data.resultSets[resultIndex]) {
160-
state.result.data.resultSets[resultIndex].columns = columns;
163+
state.result.data.resultSets[resultIndex].columns = columnsWithIndex;
161164
} else {
162-
state.result.data.resultSets[resultIndex] = {columns, result: []};
165+
state.result.data.resultSets[resultIndex] = {
166+
columns: columnsWithIndex,
167+
result: [],
168+
};
163169
}
164170
}
165171
// Convert and append new rows
166-
if (rows.length > 0 && state.result.data.resultSets?.[resultIndex]?.columns) {
172+
if (
173+
rows &&
174+
rows.length > 0 &&
175+
state.result.data.resultSets?.[resultIndex]?.columns
176+
) {
177+
const currentRows = state.result.data.resultSets[resultIndex].result;
178+
let currentIndex = currentRows?.length || 1;
179+
180+
const indexedRows = rows.map((row) => [currentIndex++, ...row]);
181+
167182
const formattedRows = parseResult(
168-
rows,
183+
indexedRows,
169184
state.result.data.resultSets[resultIndex].columns,
170185
);
171186

src/types/store/streaming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface StreamDataChunk {
2020
};
2121
result: {
2222
columns?: ColumnType[];
23-
rows: ArrayRow[];
23+
rows: ArrayRow[] | null;
2424
};
2525
}
2626

0 commit comments

Comments
 (0)