Skip to content

Commit 5d8ca87

Browse files
committed
#4989 - resolve pr comments
1 parent 7297810 commit 5d8ca87

File tree

9 files changed

+35
-21
lines changed

9 files changed

+35
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const RejsonDetailsWrapper = (props: Props) => {
8585
<div className="flex-column" style={{ flex: '1', height: '100%' }}>
8686
<div
8787
data-testid="json-details"
88-
className={`${[styles.container].join(' ')}`}
88+
className={styles.container}
8989
>
9090
{loading && (
9191
<EuiProgress

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/components/add-item/AddItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
EuiFocusTrap,
88
EuiForm,
99
EuiOutsideClickDetector,
10-
EuiWindowEvent
10+
EuiWindowEvent,
11+
keys
1112
} from '@elastic/eui'
1213

1314
import FieldMessage from 'uiSrc/components/field-message/FieldMessage'
@@ -41,7 +42,7 @@ const AddItem = (props: Props) => {
4142
}, [key, value])
4243

4344
const handleOnEsc = (e: KeyboardEvent) => {
44-
if (e.code?.toLowerCase() === 'escape') {
45+
if (e.code?.toLowerCase() === keys.ESCAPE) {
4546
e.stopPropagation()
4647
onCancel?.()
4748
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
EuiForm,
77
EuiOutsideClickDetector,
88
EuiTextArea,
9-
EuiWindowEvent
9+
EuiWindowEvent,
10+
keys
1011
} from '@elastic/eui'
1112
import cx from 'classnames'
1213

@@ -32,7 +33,7 @@ const EditEntireItemAction = (props: Props) => {
3233
const [error, setError] = useState<Nullable<string>>(null)
3334

3435
const handleOnEsc = (e: KeyboardEvent) => {
35-
if (e.code?.toLowerCase() === 'escape') {
36+
if (e.code?.toLowerCase() === keys.ESCAPE) {
3637
e.stopPropagation()
3738
onCancel?.()
3839
}
@@ -41,7 +42,7 @@ const EditEntireItemAction = (props: Props) => {
4142
const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
4243
e.preventDefault()
4344

44-
const error: null | string = validateRejsonValue(value)
45+
const error = validateRejsonValue(value)
4546
if (error) {
4647
setError(error)
4748
return

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const EditItemFieldAction = ({
4141
deleting={deleting}
4242
closePopover={() => setDeleting('')}
4343
updateLoading={false}
44-
showPopover={(item) => { setDeleting(item) }}
44+
showPopover={setDeleting}
4545
handleDeleteItem={() => handleSubmitRemoveKey(path, keyName)}
4646
testid="remove-json-field"
4747
/>

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

Lines changed: 3 additions & 6 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 } from '../utils'
12+
import { getBrackets, isRealArray, isRealObject, wrapPath } from '../utils'
1313
import { BaseProps, ObjectTypes } from '../interfaces'
1414
import RejsonDynamicTypes from '../rejson-dynamic-types'
1515
import { AddItem } from '../components'
@@ -49,12 +49,9 @@ const RejsonDetails = (props: BaseProps) => {
4949
return
5050
}
5151

52-
try {
53-
const unescapedKey = JSON.parse(key!)
54-
const updatedPath = unescapedKey.includes('"') ? `['${unescapedKey}']` : `["${unescapedKey}"]`
52+
const updatedPath = wrapPath(key as string)
53+
if (updatedPath) {
5554
handleSetRejsonDataAction(selectedKey, updatedPath, value)
56-
} catch {
57-
//
5855
}
5956
}
6057

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cx from 'classnames'
44

55
import RejsonDynamicTypes from '../rejson-dynamic-types'
66
import { JSONObjectProps, ObjectTypes, REJSONResponse } from '../interfaces'
7-
import { generatePath, getBrackets } from '../utils'
7+
import { generatePath, getBrackets, wrapPath } from '../utils'
88

99
import { AddItem, AddItemFieldAction, EditEntireItemAction, EditItemFieldAction } from '../components'
1010

@@ -63,12 +63,9 @@ const RejsonObject = (props: JSONObjectProps) => {
6363
return
6464
}
6565

66-
try {
67-
const unescapedKey = JSON.parse(key as string)
68-
const updatedPath = unescapedKey.includes('"') ? `${path}['${unescapedKey}']` : `${path}["${unescapedKey}"]`
66+
const updatedPath = wrapPath(key as string, path)
67+
if (updatedPath) {
6968
handleSetRejsonDataAction(selectedKey, updatedPath, value)
70-
} catch {
71-
//
7269
}
7370
}
7471

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const RejsonScalar = (props: JSONScalarProps) => {
4444
}
4545

4646
const onApplyValue = (value: JSONScalarValue) => {
47-
const error: null | string = validateRejsonValue(value)
47+
const error = validateRejsonValue(value)
4848
if (error) {
4949
setError(error)
5050
return

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generatePath, getBrackets, isRealArray, isRealObject, isScalar, isValidKey } from './utils'
1+
import { generatePath, getBrackets, isRealArray, isRealObject, isScalar, isValidKey, wrapPath } from './utils'
22
import { ObjectTypes } from '../interfaces'
33

44
describe('JSONUtils', () => {
@@ -12,6 +12,15 @@ describe('JSONUtils', () => {
1212
})
1313
})
1414

15+
describe('wrapPath', () => {
16+
it('should properly wrap path', () => {
17+
expect(wrapPath('"key"')).toEqual('["key"]')
18+
expect(wrapPath('"ke\\"y"')).toEqual("['ke\"y']")
19+
expect(wrapPath('"key"', 'path')).toEqual('path["key"]')
20+
expect(wrapPath('"key\\""', 'path')).toEqual("path['key\"']")
21+
})
22+
})
23+
1524
describe('isScalar', () => {
1625
it('should return Truthy for scalar variables', () => {
1726
const string = 'string'

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ export const generatePath = (parentPath: string, keyName: string | number) => {
2929
return parentPath ? `${parentPath}[${currentPath}]` : `[${currentPath}]`
3030
}
3131

32+
export const wrapPath = (key: string, path: string = '') => {
33+
try {
34+
const unescapedKey = JSON.parse(key!)
35+
return unescapedKey.includes('"') ? `${path}['${unescapedKey}']` : `${path}["${unescapedKey}"]`
36+
} catch {
37+
return null
38+
}
39+
}
40+
3241
export const validateRejsonValue = (value: any) => {
3342
try {
3443
JSON.parse(value as string)

0 commit comments

Comments
 (0)