Skip to content

Commit b1a7959

Browse files
committed
fix pr comments
1 parent f325519 commit b1a7959

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import cx from 'classnames'
1313

1414
import FieldMessage from 'uiSrc/components/field-message/FieldMessage'
1515
import { Nullable } from 'uiSrc/utils'
16-
import { validateRejsonValue } from '../../utils'
16+
import { isValidJSON } from '../../utils'
17+
import { JSONErrors } from '../../constants'
1718

1819
import styles from '../../styles.module.scss'
1920

@@ -42,9 +43,8 @@ const EditEntireItemAction = (props: Props) => {
4243
const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
4344
e.preventDefault()
4445

45-
const error = validateRejsonValue(value)
46-
if (error) {
47-
setError(error)
46+
if (!isValidJSON(value)) {
47+
setError(JSONErrors.valueJSONFormat)
4848
return
4949
}
5050

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import PopoverDelete from 'uiSrc/pages/browser/components/popover-delete/Popover
99
import { bufferToString, createDeleteFieldHeader, createDeleteFieldMessage, Nullable } from 'uiSrc/utils'
1010
import FieldMessage from 'uiSrc/components/field-message/FieldMessage'
1111

12-
import { JSONScalarValue, JSONScalarProps } from '../interfaces'
13-
import { generatePath, getClassNameByValue, validateRejsonValue } from '../utils'
12+
import { JSONScalarProps } from '../interfaces'
13+
import { generatePath, getClassNameByValue, isValidJSON } from '../utils'
14+
import { JSONErrors } from '../constants'
1415

1516
import styles from '../styles.module.scss'
1617
import '../styles.scss'
@@ -43,10 +44,9 @@ const RejsonScalar = (props: JSONScalarProps) => {
4344
setError(null)
4445
}
4546

46-
const onApplyValue = (value: JSONScalarValue) => {
47-
const error = validateRejsonValue(value)
48-
if (error) {
49-
setError(error)
47+
const onApplyValue = (value: string) => {
48+
if (!isValidJSON(value)) {
49+
setError(JSONErrors.valueJSONFormat)
5050
return
5151
}
5252

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { isArray } from 'lodash'
2-
import { JSONErrors } from '../constants'
32
import { JSONScalarValue, ObjectTypes } from '../interfaces'
43
import styles from '../styles.module.scss'
54

@@ -38,15 +37,6 @@ export const wrapPath = (key: string, path: string = '') => {
3837
}
3938
}
4039

41-
export const validateRejsonValue = (value: any) => {
42-
try {
43-
JSON.parse(value as string)
44-
return null
45-
} catch (e) {
46-
return JSONErrors.valueJSONFormat
47-
}
48-
}
49-
5040
export const getClassNameByValue = (value: any) => {
5141
const type = typeof value
5242
// @ts-ignore

redisinsight/ui/src/telemetry/telemetryUtils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ const getJsonPathLevel = (path: string): string => {
6868
const levelsLength = jsonpath.parse(
6969
`$${path.startsWith('.') ? '' : '..'}${path}`,
7070
).length
71-
if (levelsLength === 1) {
72-
return 'root'
73-
}
74-
return `${levelsLength - 2}`
71+
72+
return levelsLength === 1 ? 'root' : `${levelsLength - 2}`
7573
} catch (e) {
7674
return 'root'
7775
}

0 commit comments

Comments
 (0)