Skip to content

Commit 75d1b2e

Browse files
committed
Add fallback to non big int option to cover large floats
1 parent a63d83d commit 75d1b2e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

redisinsight/ui/src/components/json-viewer/JSONViewer.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,40 @@ interface Props {
99
expanded?: boolean
1010
space?: number
1111
useNativeBigInt?: boolean
12+
fallbackToNonBigInt?: boolean
13+
}
14+
15+
const RenderJSONValue = (value: string, expanded: boolean, space: number, useNativeBigInt: boolean) => {
16+
const data = JSONBigInt({ useNativeBigInt }).parse(value)
17+
return (
18+
<div className={cx('jsonViewer', { 'jsonViewer-collapsed': !expanded })} data-testid="value-as-json">
19+
<JsonPretty data={data} space={space} />
20+
</div>
21+
)
1222
}
1323

1424
const JSONViewer = (props: Props) => {
15-
const { value, expanded = false, space = 2, useNativeBigInt = true } = props
25+
const { value, expanded = false, space = 2, useNativeBigInt = true, fallbackToNonBigInt } = props
1626

1727
try {
18-
const data = JSONBigInt({ useNativeBigInt }).parse(value)
19-
28+
const jsonValue = RenderJSONValue(value, expanded, space, useNativeBigInt)
2029
return {
21-
value: (
22-
<div className={cx('jsonViewer', { 'jsonViewer-collapsed': !expanded })} data-testid="value-as-json">
23-
<JsonPretty data={data} space={space} />
24-
</div>
25-
),
30+
value: jsonValue,
2631
isValid: true
2732
}
2833
} catch (e) {
34+
if (fallbackToNonBigInt) {
35+
try {
36+
const jsonValue = RenderJSONValue(value, expanded, space, false)
37+
return {
38+
value: jsonValue,
39+
isValid: true
40+
}
41+
} catch (e) {
42+
// ignore
43+
}
44+
}
45+
2946
return {
3047
value,
3148
isValid: false

redisinsight/ui/src/utils/formatters/valueFormatters.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const bufferToJSON = (
6565
reply: RedisResponseBuffer,
6666
props: FormattingProps
6767
): { value: JSX.Element | string, isValid: boolean } =>
68-
JSONViewer({ value: bufferToUTF8(reply), ...props })
68+
JSONViewer({ value: bufferToUTF8(reply), fallbackToNonBigInt: true, ...props })
6969

7070
const formattingBuffer = (
7171
reply: RedisResponseBuffer,

0 commit comments

Comments
 (0)