Skip to content

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

Show Run selected CTA if there's selected text in sql editor (#18951)

Joshen Lim77bb3e4017c9
diff --git a/studio/components/interfaces/SQLEditor/MonacoEditor.tsx b/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
index a11101c3a45..28bd9cc7f9f 100644
--- a/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
+++ b/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
@@ -15,11 +15,12 @@ import { createSqlSnippetSkeleton } from './SQLEditor.utils'
export type MonacoEditorProps = {
id: string
+ className?: string
editorRef: MutableRefObject<IStandaloneCodeEditor | null>
monacoRef: MutableRefObject<Monaco | null>
autoFocus?: boolean
executeQuery: () => void
- className?: string
+ onHasSelection: (value: boolean) => void
}
const MonacoEditor = ({
@@ -29,6 +30,7 @@ const MonacoEditor = ({
autoFocus = true,
className,
executeQuery,
+ onHasSelection,
}: MonacoEditorProps) => {
const { ref, content } = useParams()
const router = useRouter()
@@ -61,6 +63,13 @@ const MonacoEditor = ({
},
})
+ editor.onDidChangeCursorSelection(({ selection }) => {
+ const noSelection =
+ selection.startLineNumber === selection.endLineNumber &&
+ selection.startColumn === selection.endColumn
+ onHasSelection(!noSelection)
+ })
+
// add margin above first line
editorRef.current.changeViewZones((accessor) => {
accessor.addZone({
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index 612816a975b..1477e147dfc 100644
--- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -111,6 +111,7 @@ const SQLEditor = () => {
const [debugSolution, setDebugSolution] = useState<string>()
const [sqlDiff, setSqlDiff] = useState<ContentDiff>()
const [pendingTitle, setPendingTitle] = useState<string>()
+ const [hasSelection, setHasSelection] = useState<boolean>(false)
const inputRef = useRef<HTMLInputElement>(null)
const supabaseAIEnabled = useFlag('sqlEditorSupabaseAI')
@@ -950,6 +951,7 @@ const SQLEditor = () => {
editorRef={editorRef}
monacoRef={monacoRef}
executeQuery={executeQuery}
+ onHasSelection={setHasSelection}
/>
</motion.div>
</>
@@ -963,6 +965,7 @@ const SQLEditor = () => {
id={id}
isExecuting={isExecuting}
isDisabled={isDiffOpen}
+ hasSelection={hasSelection}
prettifyQuery={prettifyQuery}
executeQuery={executeQuery}
/>
diff --git a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
index c8e29827545..bee4ca97daa 100644
--- a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
+++ b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
@@ -11,6 +11,7 @@ export type UtilityActionsProps = {
id: string
isExecuting?: boolean
isDisabled?: boolean
+ hasSelection: boolean
prettifyQuery: () => void
executeQuery: () => void
}
@@ -19,6 +20,7 @@ const UtilityActions = ({
id,
isExecuting = false,
isDisabled = false,
+ hasSelection,
prettifyQuery,
executeQuery,
}: UtilityActionsProps) => {
@@ -69,7 +71,7 @@ const UtilityActions = ({
</div>
}
>
- RUN
+ {hasSelection ? 'Run selected' : 'Run'}
</Button>
</>
)
diff --git a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx
index 1c96bd69099..37cfa3ce024 100644
--- a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx
+++ b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx
@@ -6,6 +6,7 @@ export type UtilityPanelProps = {
id: string
isExecuting?: boolean
isDisabled?: boolean
+ hasSelection: boolean
prettifyQuery: () => void
executeQuery: () => void
}
@@ -14,12 +15,13 @@ const UtilityPanel = ({
id,
isExecuting,
isDisabled,
+ hasSelection,
prettifyQuery,
executeQuery,
}: UtilityPanelProps) => {
return (
<>
- <div className="flex justify-between overflow-visible px-6 py-2">
+ <div className="flex justify-between overflow-visible px-6 py-2 border-b">
<ResultsDropdown id={id} isExecuting={isExecuting} />
<div className="inline-flex items-center justify-end">
@@ -27,6 +29,7 @@ const UtilityPanel = ({
id={id}
isExecuting={isExecuting}
isDisabled={isDisabled}
+ hasSelection={hasSelection}
prettifyQuery={prettifyQuery}
executeQuery={executeQuery}
/>
diff --git a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
index aae6f0985e9..51339b4faa0 100644
--- a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
+++ b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
@@ -163,7 +163,7 @@ const UtilityTabResults = ({ id, isExecuting }: UtilityTabResultsProps) => {
return (
<div className="bg-table-header-light dark:bg-table-header-dark">
<p className="m-0 border-0 px-6 py-4 text-sm text-foreground-light">
- Click <code>RUN</code> to execute your query.
+ Click <code>Run</code> to execute your query.
</p>
</div>
)