Skip to content

Commit 65e23b2

Browse files
committed
fix: remove sorting
1 parent d4dfddb commit 65e23b2

File tree

4 files changed

+21
-48
lines changed

4 files changed

+21
-48
lines changed

src/components/QueryResultTable/QueryResultTable.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,8 @@ const prepareTypedColumns = (columns: ColumnType[], data?: KeyValueRow[]) => {
4040

4141
const column: Column<KeyValueRow> = {
4242
name,
43-
width: getColumnWidth({data: dataSlice, name, columnType}),
43+
width: getColumnWidth({data: dataSlice, name}),
4444
align: columnType === 'number' ? DataTable.RIGHT : DataTable.LEFT,
45-
sortAccessor: (row) => {
46-
const value = row[name];
47-
48-
if (value === undefined || value === null) {
49-
return null;
50-
}
51-
52-
return columnType === 'number' ? BigInt(value) : value;
53-
},
5445
render: ({row}) => <Cell value={String(row[name])} />,
5546
};
5647

@@ -63,11 +54,13 @@ const prepareGenericColumns = (data: KeyValueRow[]) => {
6354
return [];
6455
}
6556

57+
const dataSlice = data?.slice(0, WIDTH_PREDICTION_ROWS_COUNT);
58+
6659
return Object.keys(data[0]).map((name) => {
6760
const column: Column<KeyValueRow> = {
6861
name,
62+
width: getColumnWidth({data: dataSlice, name}),
6963
align: isNumeric(data[0][name]) ? DataTable.RIGHT : DataTable.LEFT,
70-
sortAccessor: (row) => (isNumeric(row[name]) ? Number(row[name]) : row[name]),
7164
render: ({row}) => <Cell value={String(row[name])} />,
7265
};
7366

@@ -94,6 +87,7 @@ export const QueryResultTable = (props: QueryResultTableProps) => {
9487
() => ({
9588
...TABLE_SETTINGS,
9689
...settingsMix,
90+
sortable: false,
9791
}),
9892
[settingsMix],
9993
);
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
1-
import {
2-
MAX_COLUMN_WIDTH,
3-
PADDING_NO_SORT_ICON,
4-
PADDING_WITH_SORT_ICON,
5-
getColumnWidth,
6-
} from './getColumnWidth';
1+
import {HEADER_PADDING, MAX_COLUMN_WIDTH, getColumnWidth} from './getColumnWidth';
72

83
describe('getColumnWidth', () => {
94
it('returns minimum width for empty data', () => {
10-
const result = getColumnWidth({data: [], name: 'test', columnType: 'string'});
11-
expect(result).toBe(PADDING_NO_SORT_ICON + 'test'.length * 10);
5+
const result = getColumnWidth({data: [], name: 'test'});
6+
expect(result).toBe(HEADER_PADDING + 'test'.length * 10);
127
});
138

149
it('calculates correct width for string columns', () => {
1510
const data = [{test: 'short'}, {test: 'medium length'}, {test: 'this is a longer string'}];
16-
const result = getColumnWidth({data, name: 'test', columnType: 'string'});
17-
expect(result).toBe(PADDING_NO_SORT_ICON + 'this is a longer string'.length * 10);
18-
});
19-
20-
it('calculates correct width for number columns', () => {
21-
const data = [{test: 123}, {test: 456789}, {test: 0}];
22-
const result = getColumnWidth({data, name: 'test', columnType: 'number'});
23-
expect(result).toBe(PADDING_WITH_SORT_ICON + '456789'.length * 10);
11+
const result = getColumnWidth({data, name: 'test'});
12+
expect(result).toBe(HEADER_PADDING + 'this is a longer string'.length * 10);
2413
});
2514

2615
it('returns MAX_COLUMN_WIDTH when calculated width exceeds it', () => {
2716
const data = [{test: 'a'.repeat(100)}];
28-
const result = getColumnWidth({data, name: 'test', columnType: 'string'});
17+
const result = getColumnWidth({data, name: 'test'});
2918
expect(result).toBe(MAX_COLUMN_WIDTH);
3019
});
3120

3221
it('handles undefined data correctly', () => {
33-
const result = getColumnWidth({name: 'test', columnType: 'string'});
34-
expect(result).toBe(PADDING_NO_SORT_ICON + 'test'.length * 10);
22+
const result = getColumnWidth({name: 'test'});
23+
expect(result).toBe(HEADER_PADDING + 'test'.length * 10);
3524
});
3625

3726
it('handles missing values in data correctly', () => {
3827
const data = [{test: 'short'}, {}, {test: 'longer string'}];
39-
const result = getColumnWidth({data, name: 'test', columnType: 'string'});
40-
expect(result).toBe(PADDING_NO_SORT_ICON + 'longer string'.length * 10);
28+
const result = getColumnWidth({data, name: 'test'});
29+
expect(result).toBe(HEADER_PADDING + 'longer string'.length * 10);
4130
});
4231

4332
it('uses column name length when all values are shorter', () => {
4433
const data = [{longColumnName: 'a'}, {longColumnName: 'bb'}];
45-
const result = getColumnWidth({data, name: 'longColumnName', columnType: 'string'});
46-
expect(result).toBe(PADDING_NO_SORT_ICON + 'longColumnName'.length * 10);
34+
const result = getColumnWidth({data, name: 'longColumnName'});
35+
expect(result).toBe(HEADER_PADDING + 'longColumnName'.length * 10);
4736
});
4837
});

src/components/QueryResultTable/utils/getColumnWidth.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,21 @@ import type {KeyValueRow} from '../../../types/api/query';
22

33
export const MAX_COLUMN_WIDTH = 600;
44
export const PADDING_WITH_SORT_ICON = 55;
5-
export const PADDING_NO_SORT_ICON = 35;
5+
export const HEADER_PADDING = 20;
66

7-
export const getColumnWidth = ({
8-
data,
9-
name,
10-
columnType,
11-
}: {
12-
data?: KeyValueRow[];
13-
name: string;
14-
columnType?: string;
15-
}) => {
7+
export const getColumnWidth = ({data, name}: {data?: KeyValueRow[]; name: string}) => {
168
let maxColumnContentLength = name.length;
17-
const headerPadding = columnType === 'number' ? PADDING_WITH_SORT_ICON : PADDING_NO_SORT_ICON;
189

1910
if (data) {
2011
for (const row of data) {
2112
const cellLength = row[name] ? String(row[name]).length : 0;
2213
maxColumnContentLength = Math.max(maxColumnContentLength, cellLength);
2314

24-
if (maxColumnContentLength * 10 + headerPadding >= MAX_COLUMN_WIDTH) {
15+
if (maxColumnContentLength * 10 + HEADER_PADDING >= MAX_COLUMN_WIDTH) {
2516
return MAX_COLUMN_WIDTH;
2617
}
2718
}
2819
}
2920

30-
return Math.min(maxColumnContentLength * 10 + headerPadding, MAX_COLUMN_WIDTH);
21+
return Math.min(maxColumnContentLength * 10 + HEADER_PADDING, MAX_COLUMN_WIDTH);
3122
};

src/containers/Tenant/Query/ExecuteResult/ExecuteResult.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export function ExecuteResult({
136136
<QueryResultTable
137137
data={currentResult?.result}
138138
columns={currentResult?.columns}
139-
settings={{sortable: false}}
140139
/>
141140
</div>
142141
</div>

0 commit comments

Comments
 (0)