Skip to content

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

Add same behaviour to JsonEditor in grid and also add helper text

Joshen Lime24306706d5e
diff --git a/studio/components/grid/components/common/BlockKeys.tsx b/studio/components/grid/components/common/BlockKeys.tsx
index 3fe83440327..994b2a0252c 100644
--- a/studio/components/grid/components/common/BlockKeys.tsx
+++ b/studio/components/grid/components/common/BlockKeys.tsx
@@ -21,7 +21,10 @@ export const BlockKeys: React.FC<BlockKeysProps> = ({ onEscape, onEnter, value,
break
case 'Enter':
ev.stopPropagation()
- if (!ev.shiftKey && onEnter) onEnter(value)
+ if (!ev.shiftKey && onEnter) {
+ ev.preventDefault()
+ onEnter(value)
+ }
break
}
},
diff --git a/studio/components/grid/components/editor/JsonEditor.tsx b/studio/components/grid/components/editor/JsonEditor.tsx
index 66c3fa1e65d..7eaa0379a8f 100644
--- a/studio/components/grid/components/editor/JsonEditor.tsx
+++ b/studio/components/grid/components/editor/JsonEditor.tsx
@@ -1,4 +1,4 @@
-import * as React from 'react'
+import { useState, useCallback } from 'react'
import { EditorProps } from '@supabase/react-data-grid'
import { useTrackedState } from '../../store'
@@ -11,18 +11,22 @@ export function JsonEditor<TRow, TSummaryRow = unknown>({
onRowChange,
}: EditorProps<TRow, TSummaryRow>) {
const state = useTrackedState()
- const [isPopoverOpen, setIsPopoverOpen] = React.useState(true)
+ const [isPopoverOpen, setIsPopoverOpen] = useState(true)
const gridColumn = state.gridColumns.find((x) => x.name == column.key)
const initialValue = row[column.key as keyof TRow] as unknown
const jsonString = initialValue ? JSON.stringify(initialValue) : ''
const prettyJsonValue = prettifyJSON(jsonString)
- const [value, setValue] = React.useState<string | null>(prettyJsonValue)
+ const [value, setValue] = useState<string | null>(prettyJsonValue)
- const onEscape = React.useCallback((newValue: string | null) => {
- commitChange(newValue)
+ const cancelChanges = useCallback(() => {
+ onRowChange(row, true)
setIsPopoverOpen(false)
}, [])
+ const saveChanges = useCallback((newValue: string | null) => {
+ commitChange(newValue)
+ }, [])
+
function onChange(_value: string | undefined) {
if (!_value || _value == '') setValue(null)
else setValue(_value)
@@ -31,12 +35,14 @@ export function JsonEditor<TRow, TSummaryRow = unknown>({
function commitChange(newValue: string | null) {
if (!newValue) {
onRowChange({ ...row, [column.key]: null }, true)
+ setIsPopoverOpen(false)
} else if (verifyJSON(newValue)) {
const jsonValue = JSON.parse(newValue)
onRowChange({ ...row, [column.key]: jsonValue }, true)
+ setIsPopoverOpen(false)
} else {
const { onError } = state
- if (onError) onError(Error('invalid input'))
+ if (onError) onError(Error('Please enter a valid JSON'))
}
}
@@ -48,13 +54,17 @@ export function JsonEditor<TRow, TSummaryRow = unknown>({
sideOffset={-35}
className="rounded-none"
overlay={
- <BlockKeys value={value} onEscape={onEscape}>
+ <BlockKeys value={value} onEscape={cancelChanges} onEnter={saveChanges}>
<MonacoEditor
width={`${gridColumn?.width || column.width}px`}
value={value ?? ''}
language="json"
onChange={onChange}
/>
+ <div className="flex items-center justify-end p-2 bg-scale-400 space-x-2">
+ <p className="text-xs text-scale-1100">Save changes</p>
+ <code className="text-xs">⏎</code>
+ </div>
</BlockKeys>
}
>
diff --git a/studio/components/grid/components/editor/TextEditor.tsx b/studio/components/grid/components/editor/TextEditor.tsx
index 42db9f494e4..7b122efc5d8 100644
--- a/studio/components/grid/components/editor/TextEditor.tsx
+++ b/studio/components/grid/components/editor/TextEditor.tsx
@@ -44,6 +44,10 @@ export function TextEditor<TRow, TSummaryRow = unknown>({
value={value ?? ''}
onChange={onChange}
/>
+ <div className="flex items-center justify-end p-2 bg-scale-400 space-x-2">
+ <p className="text-xs text-scale-1100">Save changes</p>
+ <code className="text-xs">⏎</code>
+ </div>
</BlockKeys>
}
>
diff --git a/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js b/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js
index ed250a9b1f0..6c60ab9a013 100644
--- a/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js
+++ b/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js
@@ -290,7 +290,7 @@ const UtilityTabResults = observer(() => {
<div className="bg-table-header-light dark:bg-table-header-dark">
<p className="m-0 border-0 px-6 py-4 text-sm text-scale-1000">
Click <code>RUN</code> or hit{' '}
- <code>{window.navigator.platform.match(/^Mac/) ? 'cmd' : 'ctrl'} + ⏎</code> to execute
+ <code>{window.navigator.platform.match(/^Mac/) ? '⌘' : 'Ctrl'} + Enter</code> to execute
your query.
</p>
</div>