Skip to content

Commit 8483ef3

Browse files
Merge pull request #4089 from RedisInsight/e2e/feature/RI-6231-SPIKE]-Fix-the-rounding-issue-for-JSON-data-type
E2e/feature/ri 6231 spike] fix the rounding issue for json data type
2 parents beb00f9 + 6cac1e0 commit 8483ef3

File tree

16 files changed

+410
-46
lines changed

16 files changed

+410
-46
lines changed

redisinsight/api/src/modules/browser/rejson-rl/rejson-rl.service.spec.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('JsonService', () => {
215215
expect(result).toEqual({
216216
downloaded: true,
217217
path: testPath,
218-
data: testData,
218+
data: JSON.stringify(testData),
219219
});
220220
});
221221
it('should return data (number)', async () => {
@@ -236,7 +236,7 @@ describe('JsonService', () => {
236236
expect(result).toEqual({
237237
downloaded: true,
238238
path: testPath,
239-
data: testData,
239+
data: JSON.stringify(testData),
240240
});
241241
});
242242
it('should return data (integer)', async () => {
@@ -257,7 +257,7 @@ describe('JsonService', () => {
257257
expect(result).toEqual({
258258
downloaded: true,
259259
path: testPath,
260-
data: testData,
260+
data: JSON.stringify(testData),
261261
});
262262
});
263263
it('should return data (boolean)', async () => {
@@ -278,7 +278,7 @@ describe('JsonService', () => {
278278
expect(result).toEqual({
279279
downloaded: true,
280280
path: testPath,
281-
data: testData,
281+
data: JSON.stringify(testData),
282282
});
283283
});
284284
it('should return data (null)', async () => {
@@ -299,7 +299,7 @@ describe('JsonService', () => {
299299
expect(result).toEqual({
300300
downloaded: true,
301301
path: testPath,
302-
data: testData,
302+
data: JSON.stringify(testData),
303303
});
304304
});
305305
it('should return data (array)', async () => {
@@ -328,7 +328,7 @@ describe('JsonService', () => {
328328
expect(result).toEqual({
329329
downloaded: true,
330330
path: testPath,
331-
data: testData,
331+
data: JSON.stringify(testData),
332332
});
333333
});
334334
it('should return data (object)', async () => {
@@ -355,7 +355,7 @@ describe('JsonService', () => {
355355
expect(result).toEqual({
356356
downloaded: true,
357357
path: testPath,
358-
data: testData,
358+
data: JSON.stringify(testData),
359359
});
360360
});
361361
it('should return full json data when forceRetrieve is true', async () => {
@@ -393,7 +393,7 @@ describe('JsonService', () => {
393393
expect(result).toEqual({
394394
downloaded: true,
395395
path: testPath,
396-
data: testData,
396+
data: JSON.stringify(testData),
397397
});
398398
});
399399
});
@@ -432,7 +432,7 @@ describe('JsonService', () => {
432432
expect(result).toEqual({
433433
downloaded: true,
434434
path: testPath,
435-
data: testData,
435+
data: JSON.stringify(testData),
436436
});
437437
});
438438

@@ -462,7 +462,7 @@ describe('JsonService', () => {
462462
expect(result).toEqual({
463463
downloaded: true,
464464
path: testPath,
465-
data: testData,
465+
data: JSON.stringify(testData),
466466
});
467467
});
468468
});
@@ -503,11 +503,11 @@ describe('JsonService', () => {
503503
expect(result).toEqual({
504504
downloaded: false,
505505
path: testPath,
506-
data: testData,
506+
data: JSON.stringify(testData),
507507
type: 'string',
508508
});
509509
});
510-
it('should return array with scalar values and safe struct types descriptions', async () => {
510+
it('should return array with scalar values as strings and safe struct types descriptions', async () => {
511511
const testData = [
512512
12,
513513
3.14,
@@ -555,35 +555,35 @@ describe('JsonService', () => {
555555
path: '[0]',
556556
cardinality: 1,
557557
type: 'integer',
558-
value: testData[0],
558+
value: String(testData[0]),
559559
},
560560
{
561561
key: 1,
562562
path: '[1]',
563563
cardinality: 1,
564564
type: 'number',
565-
value: testData[1],
565+
value: String(testData[1]),
566566
},
567567
{
568568
key: 2,
569569
path: '[2]',
570570
cardinality: 1,
571571
type: 'string',
572-
value: testData[2],
572+
value: `"${testData[2]}"`,
573573
},
574574
{
575575
key: 3,
576576
path: '[3]',
577577
cardinality: 1,
578578
type: 'boolean',
579-
value: testData[3],
579+
value: String(testData[3]),
580580
},
581581
{
582582
key: 4,
583583
path: '[4]',
584584
cardinality: 1,
585585
type: 'null',
586-
value: testData[4],
586+
value: String(testData[4]),
587587
},
588588
{
589589
key: 5,
@@ -654,19 +654,19 @@ describe('JsonService', () => {
654654
path: `${path}[0]`,
655655
cardinality: 1,
656656
type: 'integer',
657-
value: testData[0],
657+
value: String(testData[0]),
658658
},
659659
{
660660
key: 1,
661661
path: `${path}[1]`,
662662
cardinality: 1,
663663
type: 'string',
664-
value: testData[1],
664+
value: `"${testData[1]}"`,
665665
},
666666
],
667667
});
668668
});
669-
it('should return object with scalar values and safe struct types descriptions', async () => {
669+
it('should return object with scalar values as strings and safe struct types descriptions', async () => {
670670
const testData = {
671671
fInt: 12,
672672
fNum: 3.14,
@@ -752,35 +752,35 @@ describe('JsonService', () => {
752752
path: '["fInt"]',
753753
cardinality: 1,
754754
type: 'integer',
755-
value: testData.fInt,
755+
value: String(testData.fInt),
756756
},
757757
{
758758
key: 'fNum',
759759
path: '["fNum"]',
760760
cardinality: 1,
761761
type: 'number',
762-
value: testData.fNum,
762+
value: String(testData.fNum),
763763
},
764764
{
765765
key: 'fStr',
766766
path: '["fStr"]',
767767
cardinality: 1,
768768
type: 'string',
769-
value: testData.fStr,
769+
value: `"${testData.fStr}"`,
770770
},
771771
{
772772
key: 'fBool',
773773
path: '["fBool"]',
774774
cardinality: 1,
775775
type: 'boolean',
776-
value: testData.fBool,
776+
value: String(testData.fBool),
777777
},
778778
{
779779
key: 'fNull',
780780
path: '["fNull"]',
781781
cardinality: 1,
782782
type: 'null',
783-
value: testData.fNull,
783+
value: String(testData.fNull),
784784
},
785785
{
786786
key: 'fArr',
@@ -797,7 +797,7 @@ describe('JsonService', () => {
797797
],
798798
});
799799
});
800-
it('should return object with scalar values in a custom path', async () => {
800+
it('should return object with scalar values as strings in a custom path', async () => {
801801
const path = '["customPath"]';
802802
const testData = {
803803
fInt: 12,
@@ -855,14 +855,14 @@ describe('JsonService', () => {
855855
path: `${path}["fInt"]`,
856856
cardinality: 1,
857857
type: 'integer',
858-
value: testData.fInt,
858+
value: String(testData.fInt),
859859
},
860860
{
861861
key: 'fStr',
862862
path: `${path}["fStr"]`,
863863
cardinality: 1,
864864
type: 'string',
865-
value: testData.fStr,
865+
value: `"${testData.fStr}"`,
866866
},
867867
],
868868
});

redisinsight/api/src/modules/browser/rejson-rl/rejson-rl.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RejsonRlService {
5151
);
5252
}
5353

54-
return JSON.parse(data);
54+
return data
5555
}
5656

5757
private async estimateSize(

redisinsight/api/test/api/rejson-rl/POST-databases-id-rejson_rl-get.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('POST /databases/:instanceId/rejson-rl/get', () => {
6464
responseBody: {
6565
downloaded: true,
6666
path: '.',
67-
data: constants.TEST_REJSON_VALUE_3,
67+
data: JSON.stringify(constants.TEST_REJSON_VALUE_3),
6868
},
6969
},
7070
].map(mainCheckFn);
@@ -83,7 +83,7 @@ describe('POST /databases/:instanceId/rejson-rl/get', () => {
8383
responseBody: {
8484
downloaded: true,
8585
path: '.',
86-
data: constants.TEST_REJSON_VALUE_3,
86+
data: JSON.stringify(constants.TEST_REJSON_VALUE_3),
8787
},
8888
},
8989
{
@@ -97,7 +97,7 @@ describe('POST /databases/:instanceId/rejson-rl/get', () => {
9797
responseBody: {
9898
downloaded: true,
9999
path: '.object.field',
100-
data: 'value',
100+
data: `"${'value'}"`,
101101
},
102102
},
103103
{
@@ -111,7 +111,7 @@ describe('POST /databases/:instanceId/rejson-rl/get', () => {
111111
responseBody: {
112112
downloaded: true,
113113
path: '["array"][1]',
114-
data: 2,
114+
data: String(2),
115115
},
116116
},
117117
{
@@ -175,7 +175,7 @@ describe('POST /databases/:instanceId/rejson-rl/get', () => {
175175
responseBody: {
176176
downloaded: false,
177177
path: '["object"]["some"]',
178-
data: constants.TEST_REJSON_VALUE_3.object.some, // full value right now
178+
data: `"${constants.TEST_REJSON_VALUE_3.object.some}"`, // full value right now
179179
type: 'string',
180180
},
181181
},

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { KeyDetailsHeader, KeyDetailsHeaderProps } from 'uiSrc/pages/browser/mod
1212
import { stringToBuffer } from 'uiSrc/utils'
1313
import { IJSONData } from 'uiSrc/pages/browser/modules/key-details/components/rejson-details/interfaces'
1414
import RejsonDetails from './rejson-details'
15+
import { parseJsonData } from './utils'
1516

1617
import styles from './styles.module.scss'
1718

@@ -26,6 +27,8 @@ const RejsonDetailsWrapper = (props: Props) => {
2627

2728
const [expandedRows, setExpandedRows] = useState<Set<string>>(new Set())
2829

30+
const updatedData = parseJsonData(data)
31+
2932
useEffect(() => {
3033
setExpandedRows(new Set())
3134
}, [nameString])
@@ -96,11 +99,11 @@ const RejsonDetailsWrapper = (props: Props) => {
9699
data-testid="progress-key-json"
97100
/>
98101
)}
99-
{!isUndefined(data) && (
102+
{!isUndefined(updatedData) && (
100103
<RejsonDetails
101104
selectedKey={selectedKey || stringToBuffer('')}
102105
dataType={type || ''}
103-
data={data as IJSONData}
106+
data={updatedData as IJSONData}
104107
length={length}
105108
parentPath={path}
106109
expandedRows={expandedRows}

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/components/edit-entire-item-action/EditEntireItemAction.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const EditEntireItemAction = (props: Props) => {
8383
aria-label="Cancel add"
8484
className={styles.declineBtn}
8585
onClick={onCancel}
86+
data-testid="cancel-edit-btn"
8687
/>
8788
<EuiButtonIcon
8889
iconSize="m"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface DynamicTypesProps {
6464

6565
interface JSONCommonProps {
6666
keyName: string | number
67-
value: IJSONValue
67+
value: string | number | boolean | bigint
6868
cardinality?: number
6969
selectedKey: RedisResponseBuffer
7070
path?: string

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const RejsonDynamicTypes = (props: DynamicTypesProps) => {
6868

6969
const data = { ...item, parentPath }
7070
if (['array', 'object'].includes(item.type)) return renderJSONObject(data, item.type)
71+
7172
return renderScalar(data)
7273
}
7374

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ const RejsonObject = (props: JSONObjectProps) => {
7979
const onClickEditEntireObject = () => {
8080
handleFetchVisualisationResults(path, true).then((data: REJSONResponse) => {
8181
setEditEntireObject(true)
82-
setValueOfEntireObject(typeof data.data === 'object' ? JSON.stringify(data.data, undefined, 4) : data.data)
82+
setValueOfEntireObject(typeof data.data === 'object' ? JSON.stringify(data.data, (_key, value) => (
83+
typeof value === 'bigint'
84+
? value.toString()
85+
: value
86+
), 4) : data.data)
8387
})
8488
}
8589

0 commit comments

Comments
 (0)