Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a815ea8

Browse files
authoredApr 25, 2025··
Merge pull request #8 from upstash/DX-1841
fix: auto json formatting not working in list items
2 parents e5a1c15 + 9927a6d commit a815ea8

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed
 

‎src/components/databrowser/components/display/display-list-edit.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useEffect } from "react"
21
import type { SelectedItem } from "@/store"
32
import { useDatabrowserStore } from "@/store"
43
import type { ListDataType } from "@/types"
@@ -60,13 +59,6 @@ const ListEditForm = ({
6059
},
6160
})
6261

63-
useEffect(() => {
64-
form.reset({
65-
key: itemKey,
66-
value: itemValue,
67-
})
68-
}, [itemKey, itemValue])
69-
7062
const { mutateAsync: editItem, isPending } = useEditListItem()
7163
const { setSelectedListItem } = useDatabrowserStore()
7264

‎src/components/databrowser/components/display/display-simple.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,15 @@ const EditorDisplayForm = ({
4848

4949
// Updates default values after submit
5050
useEffect(() => {
51-
form.reset(
52-
{ value: data },
53-
{
54-
keepValues: false,
55-
}
56-
)
51+
form.reset({ value: data })
5752
}, [data])
5853

5954
const { editor, selector } = useField({ name: "value", form, data })
6055

6156
const { mutateAsync: setKey, isPending: isSettingKey } = useSetSimpleKey(dataKey, type)
6257

6358
const handleCancel = () => {
64-
form.reset()
59+
form.reset({ value: data })
6560
}
6661

6762
return (

‎src/components/databrowser/components/display/input/use-field.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export const useField = ({
3030

3131
// Attempt to format JSON everytime the underlying data changes
3232
useEffect(() => {
33-
if (!checkIsValidJSON(data)) {
34-
return
33+
if (contentType === "JSON" && checkIsValidJSON(data)) {
34+
form.setValue(name, formatJSON(data), {
35+
shouldDirty: false,
36+
})
37+
} else {
38+
form.setValue(name, data, {
39+
shouldDirty: false,
40+
})
3541
}
36-
37-
form.setValue(name, formatJSON(data), {
38-
shouldDirty: false,
39-
})
4042
}, [data])
4143

4244
const handleTypeChange = (type: ContentType) => {

0 commit comments

Comments
 (0)
Please sign in to comment.