Skip to content

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

chore: move visible state for ongoing queries to global app state (#33354)

Jonathan Summers-Muir467b0de9532f
diff --git a/apps/studio/components/interfaces/SQLEditor/OngoingQueriesPanel.tsx b/apps/studio/components/interfaces/SQLEditor/OngoingQueriesPanel.tsx
index e39e3274d49..6136b0d5eab 100644
--- a/apps/studio/components/interfaces/SQLEditor/OngoingQueriesPanel.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/OngoingQueriesPanel.tsx
@@ -1,6 +1,6 @@
import dayjs from 'dayjs'
import { RefreshCw, StopCircle } from 'lucide-react'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
import { toast } from 'sonner'
import AlertError from 'components/ui/AlertError'
@@ -27,16 +27,19 @@ import {
cn,
} from 'ui'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
+import { useAppStateSnapshot } from 'state/app-state'
+import { useParams } from 'common'
interface OngoingQueriesPanel {
- visible: boolean
onClose: () => void
}
-export const OngoingQueriesPanel = ({ visible, onClose }: OngoingQueriesPanel) => {
+export const OngoingQueriesPanel = () => {
const [_, setParams] = useUrlState({ replace: true })
+ const { viewOngoingQueries } = useParams()
const project = useSelectedProject()
const state = useDatabaseSelectorStateSnapshot()
+ const appState = useAppStateSnapshot()
const [selectedId, setSelectedId] = useState<number>()
const { data: databases } = useReadReplicasQuery({ projectRef: project?.ref })
@@ -61,6 +64,13 @@ export const OngoingQueriesPanel = ({ visible, onClose }: OngoingQueriesPanel) =
)
const queries = data ?? []
+ useEffect(() => {
+ if (viewOngoingQueries) {
+ appState.setOnGoingQueriesPanelOpen(true)
+ setParams({ viewOngoingQueries: undefined })
+ }
+ }, [viewOngoingQueries])
+
const { mutate: abortQuery, isLoading } = useQueryAbortMutation({
onSuccess: () => {
toast.success(`Successfully aborted query (ID: ${selectedId})`)
@@ -70,12 +80,12 @@ export const OngoingQueriesPanel = ({ visible, onClose }: OngoingQueriesPanel) =
const closePanel = () => {
setParams({ viewOngoingQueries: undefined })
- onClose()
+ appState.setOnGoingQueriesPanelOpen(false)
}
return (
<>
- <Sheet open={visible} onOpenChange={() => closePanel()}>
+ <Sheet open={appState.ongoingQueriesPanelOpen} onOpenChange={() => closePanel()}>
<SheetContent size="lg">
<SheetHeader>
<SheetTitle className="flex items-center gap-x-2">
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx
index d1cf9091b61..cf36ca5afb0 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorLayout.tsx
@@ -12,22 +12,7 @@ export interface SQLEditorLayoutProps {
}
const SQLEditorLayout = ({ title, children }: SQLEditorLayoutProps) => {
- const { viewOngoingQueries } = useParams()
- const [showOngoingQueries, setShowOngoingQueries] = useState(false)
-
- const productMenu = useMemo(
- () => (
- <SQLEditorMenu
- key="sql-editor-menu"
- onViewOngoingQueries={() => setShowOngoingQueries(true)}
- />
- ),
- []
- )
-
- useEffect(() => {
- if (viewOngoingQueries === 'true') setShowOngoingQueries(true)
- }, [viewOngoingQueries])
+ const productMenu = useMemo(() => <SQLEditorMenu key="sql-editor-menu" />, [])
return (
<ProjectLayout
@@ -38,10 +23,7 @@ const SQLEditorLayout = ({ title, children }: SQLEditorLayoutProps) => {
resizableSidebar
>
{children}
- <OngoingQueriesPanel
- visible={showOngoingQueries}
- onClose={() => setShowOngoingQueries(false)}
- />
+ <OngoingQueriesPanel />
</ProjectLayout>
)
}
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index fa171ff1e06..25ed207eb10 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -31,12 +31,9 @@ import {
} from 'ui-patterns/InnerSideMenu'
import { SQLEditorNav } from './SQLEditorNavV2/SQLEditorNav'
import { SearchList } from './SQLEditorNavV2/SearchList'
+import { getAppStateSnapshot } from 'state/app-state'
-interface SQLEditorMenuProps {
- onViewOngoingQueries: () => void
-}
-
-export const SQLEditorMenu = ({ onViewOngoingQueries }: SQLEditorMenuProps) => {
+export const SQLEditorMenu = () => {
const router = useRouter()
const { profile } = useProfile()
const project = useSelectedProject()
@@ -50,6 +47,7 @@ export const SQLEditorMenu = ({ onViewOngoingQueries }: SQLEditorMenuProps) => {
'inserted_at'
)
+ const appState = getAppStateSnapshot()
const debouncedSearch = useDebounce(search, 500)
const canCreateSQLSnippet = useCheckPermissions(PermissionAction.CREATE, 'user_content', {
@@ -188,7 +186,7 @@ export const SQLEditorMenu = ({ onViewOngoingQueries }: SQLEditorMenuProps) => {
</div>
<div className="p-4 border-t sticky bottom-0 bg-studio">
- <Button block type="default" onClick={onViewOngoingQueries}>
+ <Button block type="default" onClick={() => appState.setOnGoingQueriesPanelOpen(true)}>
View running queries
</Button>
</div>
diff --git a/apps/studio/state/app-state.ts b/apps/studio/state/app-state.ts
index 5b411b4e16f..5bea9701875 100644
--- a/apps/studio/state/app-state.ts
+++ b/apps/studio/state/app-state.ts
@@ -68,6 +68,7 @@ const getInitialState = () => {
showGenerateSqlModal: false,
navigationPanelOpen: false,
navigationPanelJustClosed: false,
+ ongoingQueriesPanelOpen: false,
}
}
@@ -111,6 +112,7 @@ const getInitialState = () => {
showGenerateSqlModal: false,
navigationPanelOpen: false,
navigationPanelJustClosed: false,
+ ongoingQueriesPanelOpen: false,
}
}
@@ -217,6 +219,11 @@ export const appState = proxy({
messages: [...appState.aiAssistantPanel.messages, message],
}
},
+
+ showOngoingQueriesPanelOpen: false,
+ setOnGoingQueriesPanelOpen: (value: boolean) => {
+ appState.ongoingQueriesPanelOpen = value
+ },
})
// Set up localStorage subscription