Skip to content

Commit 805a339

Browse files
fix(QueryResultTable): fix table error on null cell sort (#590)
1 parent b09345e commit 805a339

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/components/QueryResultTable/QueryResultTable.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ const prepareTypedColumns = (columns: ColumnType[]) => {
3636
align: columnType === 'number' ? DataTable.RIGHT : DataTable.LEFT,
3737
sortAccessor: (row) => {
3838
const value = row[name];
39-
if (value === undefined || value === null) return null;
39+
40+
if (value === undefined || value === null) {
41+
return null;
42+
}
43+
4044
return columnType === 'number' ? BigInt(value) : value;
4145
},
42-
render: ({value}) => <Cell value={value as string} />,
46+
render: ({row}) => <Cell value={String(row[name])} />,
4347
};
4448

4549
return column;
@@ -56,7 +60,7 @@ const prepareGenericColumns = (data: KeyValueRow[]) => {
5660
name,
5761
align: isNumeric(data[0][name]) ? DataTable.RIGHT : DataTable.LEFT,
5862
sortAccessor: (row) => (isNumeric(row[name]) ? Number(row[name]) : row[name]),
59-
render: ({value}) => <Cell value={value as string} />,
63+
render: ({row}) => <Cell value={String(row[name])} />,
6064
};
6165

6266
return column;

src/utils/query.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,14 @@ export const prepareQueryResponse = (data?: KeyValueRow[]) => {
175175
for (const field in row) {
176176
if (Object.prototype.hasOwnProperty.call(row, field)) {
177177
const type = typeof row[field];
178-
if (type === 'object' || type === 'boolean' || Array.isArray(row[field])) {
178+
179+
// Although typeof null == 'object'
180+
// null result should be preserved
181+
if (
182+
(row[field] !== null && type === 'object') ||
183+
type === 'boolean' ||
184+
Array.isArray(row[field])
185+
) {
179186
formattedData[field] = JSON.stringify(row[field]);
180187
} else {
181188
formattedData[field] = row[field];

0 commit comments

Comments
 (0)