Skip to content

Commit ff50970

Browse files
authored
Merge pull request #3231 from RedisInsight/bugfix/RI-5523-allow-json-non-native-big-int
RI-5523: Fallback to non-native big integers for JSON formatting
2 parents a0e14f6 + ebb3b8c commit ff50970

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

redisinsight/ui/src/components/json-viewer/components/json-pretty/JsonPretty.spec.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import JSONBigInt from 'json-bigint'
23
import { render, screen } from 'uiSrc/utils/test-utils'
34

45
import JsonPretty from './JsonPretty'
@@ -24,4 +25,16 @@ describe('JsonPretty', () => {
2425

2526
expect(screen.getByTestId('json-primitive-component')).toBeInTheDocument()
2627
})
28+
29+
it('should render json primitive component with big number', () => {
30+
const json = JSONBigInt({ useNativeBigInt: true }).parse('1234567890123456789012345678901234567890')
31+
render(<JsonPretty data={json} />)
32+
expect(screen.getByTestId('json-primitive-component')).toBeInTheDocument()
33+
})
34+
35+
it('should render json primitive component with big float', () => {
36+
const json = JSONBigInt({ useNativeBigInt: false }).parse('1234567890123456789012345678901234567890.1234567890123456789012345678901234567890')
37+
render(<JsonPretty data={json} />)
38+
expect(screen.getByTestId('json-primitive-component')).toBeInTheDocument()
39+
})
2740
})

redisinsight/ui/src/components/json-viewer/components/json-pretty/JsonPretty.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { isArray, isObject } from 'uiSrc/components/json-viewer/utils'
77
import { IDefaultProps } from 'uiSrc/components/json-viewer/interfaces'
88

99
const JsonPretty = ({ data, ...props }: IDefaultProps) => {
10+
if (data?._isBigNumber) {
11+
return <JsonPrimitive data={data} {...props} />
12+
}
13+
1014
if (isArray(data)) {
1115
return <JsonArray data={data} {...props} />
1216
}

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), useNativeBigInt: false, ...props })
6969

7070
const formattingBuffer = (
7171
reply: RedisResponseBuffer,

0 commit comments

Comments
 (0)