Skip to content

Commit 088e639

Browse files
committed
#RI-5270 - fix json plugin formatter
1 parent 0bd631c commit 088e639

File tree

1 file changed

+17
-14
lines changed
  • redisinsight/ui/src/packages/clients-list/src/components/json-view

1 file changed

+17
-14
lines changed

redisinsight/ui/src/packages/clients-list/src/components/json-view/JSONView.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,32 @@ interface Props {
1111
const JSONView = (props: Props) => {
1212
const { value, command = '' } = props
1313

14-
const [formattedValue, setFormattedValue] = useState('')
14+
const [result, setResult] = useState<any>(null)
1515

1616
useEffect(() => {
17-
try {
18-
JSONBigInt({ useNativeBigInt: true }).parse(value)
19-
} catch (_err) {
20-
const formatResponse = async () => {
21-
const formattedResponse = await formatRedisReply(value, command)
22-
setFormattedValue(formattedResponse)
17+
const parseJSON = async (value: string, command: string) => {
18+
try {
19+
const json = JSONBigInt({ useNativeBigInt: true }).parse(value)
20+
setResult({ value: json, isValid: true })
21+
} catch (_err) {
22+
const reply = await formatRedisReply(value, command)
23+
setResult({ value: reply, isValid: false })
2324
}
24-
formatResponse()
2525
}
26-
}, [])
26+
27+
parseJSON(value, command)
28+
}, [value])
29+
30+
if (!result) return null
2731

2832
return (
2933
<>
30-
{formattedValue && (
31-
<div className="cli-output-response-success">{formattedValue}</div>
32-
)}
33-
{!formattedValue && (
34+
{result.isValid ? (
3435
<div className="jsonViewer" data-testid="json-view">
35-
<JsonPretty data={JSONBigInt({ useNativeBigInt: true }).parse(value)} space={2} />
36+
<JsonPretty data={result.value} space={2} />
3637
</div>
38+
) : (
39+
<div className="cli-output-response-success">{result.value}</div>
3740
)}
3841
</>
3942
)

0 commit comments

Comments
 (0)