Skip to content

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

fix: error when closing last query in list

Alaister Youngec3d38417da1
diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index f220b2f3250..7546b4001b1 100644
--- a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -105,12 +105,6 @@ const DropdownMenu = observer(({ tabInfo }: { tabInfo: QueryTab }) => {
buttonLabel="Confirm"
visible={deleteModalOpen}
onSelectConfirm={async () => {
- // TODO: remove this hack
- // it's needed because the onClick handler from the menu item registers here, instead
- // of on just the menu item. Meaning that the selectTab runs, causing an error.
- // Once a fix is made in supabase/ui this can safely be removed.
- await new Promise((resolve) => setTimeout(resolve, 10))
-
sqlEditorStore.closeTab(id)
await contentStore.del(id)
diff --git a/studio/components/ui/ConfirmationModal.tsx b/studio/components/ui/ConfirmationModal.tsx
index a99758f8101..b503b3e0939 100644
--- a/studio/components/ui/ConfirmationModal.tsx
+++ b/studio/components/ui/ConfirmationModal.tsx
@@ -1,4 +1,5 @@
import { Modal, Button, Space } from '@supabase/ui'
+import { MouseEventHandler } from 'react'
import { FC, useState, useEffect } from 'react'
interface Props {
@@ -34,7 +35,9 @@ const ConfirmationModal: FC<Props> = ({
const [loading, setLoading] = useState(false)
- const onConfirm = () => {
+ const onConfirm: MouseEventHandler<HTMLButtonElement> = (e) => {
+ e.preventDefault()
+ e.stopPropagation()
setLoading(true)
onSelectConfirm()
}
@@ -48,7 +51,7 @@ const ConfirmationModal: FC<Props> = ({
size={size}
onCancel={onSelectCancel}
customFooter={
- <div className="flex items-center w-full space-x-3">
+ <div className="flex w-full items-center space-x-3">
<Button block type="secondary" onClick={onSelectCancel}>
Cancel
</Button>
diff --git a/studio/localStores/sqlEditor/SqlEditorStore.js b/studio/localStores/sqlEditor/SqlEditorStore.js
index 71bd5bdb69d..ad56af1d15e 100644
--- a/studio/localStores/sqlEditor/SqlEditorStore.js
+++ b/studio/localStores/sqlEditor/SqlEditorStore.js
@@ -73,6 +73,10 @@ class SqlEditorStore {
}
get activeTab() {
+ if (this.tabs.length === 1) {
+ this.selectedTabId = this.tabs[0].id
+ }
+
const found = this.tabs.find((x) => x.id === this.selectedTabId)
return found
}
@@ -294,10 +298,10 @@ class SqlEditorStore {
}
closeTab(id) {
- this.tabs.filter((x) => x.id !== id)
+ const tabs = this.tabs.filter((x) => x.id !== id)
// if user close selectedTab, select the last tab if available
- if (this.tabs.length && this.selectedTabId === id) {
- const nextId = this.tabs[this.tabs.length - 1].id
+ if (tabs.length && this.selectedTabId === id) {
+ const nextId = tabs[tabs.length - 1].id
if (nextId) {
this.selectedTabId = nextId