Skip to content

Commit d4dfddb

Browse files
committed
fix: better paddings
1 parent fa986f0 commit d4dfddb

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import {MAX_COLUMN_WIDTH, getColumnWidth} from './getColumnWidth';
1+
import {
2+
MAX_COLUMN_WIDTH,
3+
PADDING_NO_SORT_ICON,
4+
PADDING_WITH_SORT_ICON,
5+
getColumnWidth,
6+
} from './getColumnWidth';
27

38
describe('getColumnWidth', () => {
49
it('returns minimum width for empty data', () => {
510
const result = getColumnWidth({data: [], name: 'test', columnType: 'string'});
6-
expect(result).toBe(20 + 'test'.length * 10);
11+
expect(result).toBe(PADDING_NO_SORT_ICON + 'test'.length * 10);
712
});
813

914
it('calculates correct width for string columns', () => {
1015
const data = [{test: 'short'}, {test: 'medium length'}, {test: 'this is a longer string'}];
1116
const result = getColumnWidth({data, name: 'test', columnType: 'string'});
12-
expect(result).toBe(20 + 'this is a longer string'.length * 10);
17+
expect(result).toBe(PADDING_NO_SORT_ICON + 'this is a longer string'.length * 10);
1318
});
1419

1520
it('calculates correct width for number columns', () => {
1621
const data = [{test: 123}, {test: 456789}, {test: 0}];
1722
const result = getColumnWidth({data, name: 'test', columnType: 'number'});
18-
expect(result).toBe(40 + '456789'.length * 10);
23+
expect(result).toBe(PADDING_WITH_SORT_ICON + '456789'.length * 10);
1924
});
2025

2126
it('returns MAX_COLUMN_WIDTH when calculated width exceeds it', () => {
@@ -26,18 +31,18 @@ describe('getColumnWidth', () => {
2631

2732
it('handles undefined data correctly', () => {
2833
const result = getColumnWidth({name: 'test', columnType: 'string'});
29-
expect(result).toBe(20 + 'test'.length * 10);
34+
expect(result).toBe(PADDING_NO_SORT_ICON + 'test'.length * 10);
3035
});
3136

3237
it('handles missing values in data correctly', () => {
3338
const data = [{test: 'short'}, {}, {test: 'longer string'}];
3439
const result = getColumnWidth({data, name: 'test', columnType: 'string'});
35-
expect(result).toBe(20 + 'longer string'.length * 10);
40+
expect(result).toBe(PADDING_NO_SORT_ICON + 'longer string'.length * 10);
3641
});
3742

3843
it('uses column name length when all values are shorter', () => {
3944
const data = [{longColumnName: 'a'}, {longColumnName: 'bb'}];
4045
const result = getColumnWidth({data, name: 'longColumnName', columnType: 'string'});
41-
expect(result).toBe(20 + 'longColumnName'.length * 10);
46+
expect(result).toBe(PADDING_NO_SORT_ICON + 'longColumnName'.length * 10);
4247
});
4348
});

src/components/QueryResultTable/utils/getColumnWidth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type {KeyValueRow} from '../../../types/api/query';
22

33
export const MAX_COLUMN_WIDTH = 600;
4+
export const PADDING_WITH_SORT_ICON = 55;
5+
export const PADDING_NO_SORT_ICON = 35;
46

57
export const getColumnWidth = ({
68
data,
@@ -12,7 +14,7 @@ export const getColumnWidth = ({
1214
columnType?: string;
1315
}) => {
1416
let maxColumnContentLength = name.length;
15-
const headerPadding = columnType === 'number' ? 40 : 20;
17+
const headerPadding = columnType === 'number' ? PADDING_WITH_SORT_ICON : PADDING_NO_SORT_ICON;
1618

1719
if (data) {
1820
for (const row of data) {

0 commit comments

Comments
 (0)