Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix JSON side panel crashing when value is a number

Joshen Limdb5f5a6d234e
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
index f6e0eaba2da..5cf22e5a9e2 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
@@ -123,7 +123,7 @@ const InputField: FC<Props> = ({
onClick={() => onEditJson({ column: field.name, jsonString: field.value })}
icon={<IconLink />}
>
- View data
+ View JSON
</Button>
}
/>
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx
index e69fe986c95..87ab1f2c8db 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx
@@ -1,6 +1,5 @@
import Editor, { useMonaco } from '@monaco-editor/react'
import { FC, useEffect, useRef, useState } from 'react'
-import { Typography } from '@supabase/ui'
interface Props {
queryId?: string
@@ -13,7 +12,7 @@ const JsonEditor: FC<Props> = ({
queryId = '',
defaultValue = '',
readOnly = false,
- onInputChange = (value) => {},
+ onInputChange = () => {},
}) => {
const monaco = useMonaco()
const editorRef = useRef()
@@ -56,13 +55,13 @@ const JsonEditor: FC<Props> = ({
})
}
- const Loading = () => <Typography.Title level={4}>Loading</Typography.Title>
+ const Loading = () => <h4>Loading</h4>
return (
<Editor
className="monaco-editor"
theme="vs-dark"
- defaultLanguage={'json'}
+ defaultLanguage="json"
defaultValue={defaultValue}
path={queryId}
loading={<Loading />}
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonEditor.tsx
index 67ce557846c..9adadec1895 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonEditor.tsx
@@ -13,7 +13,7 @@ type JsonEditProps = {
jsonString: string
visible: boolean
closePanel: () => void
- onSaveJSON: (value: string) => void
+ onSaveJSON: (value: string | number) => void
}
const JsonEdit: FC<JsonEditProps> = ({ column, jsonString, visible, closePanel, onSaveJSON }) => {
@@ -90,7 +90,7 @@ const Editor: FC<EditorProps> = ({ column, value, onChange }) => {
<Typography.Title level={4}>Edit JSON Field: {column}</Typography.Title>
<div className="dark:border-dark h-96 w-full flex-grow border">
- <JsonEditor onInputChange={onChange} defaultValue={value} />
+ <JsonEditor onInputChange={onChange} defaultValue={value.toString()} />
</div>
</>
)
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
index 02d985c796d..938fa79ec87 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
@@ -209,7 +209,7 @@ const RowEditor: FC<Props> = ({
column={selectedValueForJsonEdit?.column ?? ''}
jsonString={selectedValueForJsonEdit?.jsonString ?? ''}
closePanel={() => setSelectedValueForJsonEdit(undefined)}
- onSaveJSON={(value: string) => {
+ onSaveJSON={(value: string | number) => {
onUpdateField({ [selectedValueForJsonEdit?.column ?? '']: value })
setSelectedValueForJsonEdit(undefined)
}}
diff --git a/studio/lib/helpers.ts b/studio/lib/helpers.ts
index ec95a3b4eb2..a52bb8c367b 100644
--- a/studio/lib/helpers.ts
+++ b/studio/lib/helpers.ts
@@ -13,7 +13,9 @@ export const tryParseJson = (jsonString: any) => {
export const minifyJSON = (prettifiedJSON: string) => {
try {
- return JSON.stringify(JSON.parse(prettifiedJSON))
+ const res = JSON.stringify(JSON.parse(prettifiedJSON))
+ if (Number(res) !== NaN) return Number(res)
+ else return res
} catch (err) {
throw err
}