Skip to content

Commit 7d4cd5e

Browse files
committed
RI-6339
1 parent b44c3cb commit 7d4cd5e

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/RejsonDetailsWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ const RejsonDetailsWrapper = (props: Props) => {
2525
const { id: instanceId } = useSelector(connectedInstanceSelector)
2626
const { viewType } = useSelector(keysSelector)
2727

28-
const updatedData = parseJsonData(data)
29-
3028
const [expandedRows, setExpandedRows] = useState<Set<string>>(new Set())
3129

30+
const updatedData = parseJsonData(data)
31+
3232
useEffect(() => {
3333
setExpandedRows(new Set())
3434
}, [nameString])

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/rejson-details/RejsonDetails.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'uiSrc/slices/browser/rejson'
1010
import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
1111

12-
import { getBrackets, isRealArray, isRealObject, wrapPath } from '../utils'
12+
import { getBrackets, isRealArray, isRealObject, parseJsonData, wrapPath } from '../utils'
1313
import { BaseProps, ObjectTypes } from '../interfaces'
1414
import RejsonDynamicTypes from '../rejson-dynamic-types'
1515
import { AddItem } from '../components'
@@ -32,8 +32,14 @@ const RejsonDetails = (props: BaseProps) => {
3232

3333
const dispatch = useDispatch()
3434

35-
const handleFetchVisualisationResults = (path: string, forceRetrieve = false) =>
35+
const handleFetchVisualisationResults = (path: string, forceRetrieve = false) => new Promise((resolve, reject) => {
3636
dispatch<any>(fetchVisualisationResults(path, forceRetrieve))
37+
.then((data: any) => resolve({
38+
...data,
39+
data: parseJsonData(data?.data)
40+
}))
41+
.catch(reject)
42+
})
3743

3844
const handleAppendRejsonArrayItemAction = (keyName: RedisResponseBuffer, path: string, data: string) => {
3945
dispatch(appendReJSONArrayItemAction(keyName, path, data, length))

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/rejson-dynamic-types/RejsonDynamicTypes.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import RejsonDynamicTypes from './RejsonDynamicTypes'
66

77
const mockedProps = mock<DynamicTypesProps>()
88

9-
const mockedDownloadedSimpleArray = '[1, 2, 3]'
9+
const mockedDownloadedSimpleArray = [1, 2, 3]
1010

1111
describe('RejsonDynamicTypes Component', () => {
1212
it('renders correctly simple downloaded JSON', () => {

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/rejson-dynamic-types/RejsonDynamicTypes.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react'
33
import { isNull, isObject } from 'lodash'
44
import { MAX_LEFT_PADDING_NESTING } from '../constants'
55
import { DynamicTypesProps, ObjectTypes } from '../interfaces'
6-
import { generatePath, isScalar, parseJsonData } from '../utils'
6+
import { generatePath, isScalar } from '../utils'
77

88
import RejsonScalar from '../rejson-scalar'
99
import RejsonObject from '../rejson-object'
@@ -102,7 +102,7 @@ const RejsonDynamicTypes = (props: DynamicTypesProps) => {
102102
return Object.entries(data).map(([key, value]) => renderArrayItem(key, value))
103103
}
104104

105-
return renderResult(parseJsonData(data))
105+
return renderResult(data)
106106
}
107107

108108
export default RejsonDynamicTypes

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe('JSONUtils', () => {
8282

8383
describe('JSON Parsing Utils', () => {
8484
const bigintAsString = '1188950299261208742'
85+
const scientificNotation = 1.2345678901234568e+29
8586

8687
describe('parseValue', () => {
8788
it('should handle non-string values', () => {
@@ -131,6 +132,19 @@ describe('JSONUtils', () => {
131132
expect(result[0].toString()).toBe(bigintAsString)
132133
expect(result[1]).toBe('test')
133134
})
135+
136+
it('should handle extremely large integers and maintain scientific notation', () => {
137+
const resultFromString = parseValue(`'${scientificNotation}'`, 'integer')
138+
expect(resultFromString).toBe(`'${scientificNotation}'`)
139+
140+
const resultFromInt = parseValue(scientificNotation, 'integer')
141+
expect(resultFromInt).toBe(scientificNotation)
142+
143+
// Also test parsing as part of JSON
144+
const jsonWithLargeInt = `{"value": ${scientificNotation}}`
145+
const parsedJson = parseValue(jsonWithLargeInt)
146+
expect(parsedJson.value).toBe(scientificNotation)
147+
})
134148
})
135149

136150
describe('parseJsonData', () => {

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ export const isValidKey = (key: string): boolean => /^"([^"\\]|\\.)*"$/.test(key
6666
const JSONParser = JSONBigInt({
6767
useNativeBigInt: true,
6868
strict: false,
69-
// Parse all numbers as BigInt if they exceed safe integer
70-
alwaysParseAsBig: false,
71-
// This option helps with scientific notation
72-
storeAsString: true
7369
})
7470

7571
export const parseValue = (value: any, type?: string): any => {
@@ -114,7 +110,11 @@ export const parseValue = (value: any, type?: string): any => {
114110
}
115111
return parsed
116112
} catch (e) {
117-
return value
113+
try {
114+
return JSON.parse(value)
115+
} catch (error) {
116+
return value
117+
}
118118
}
119119
}
120120

0 commit comments

Comments
 (0)