Skip to content

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

Address comments

Joshen Lim1d19861c3754
diff --git a/studio/components/interfaces/App/CommandMenuWrapper.tsx b/studio/components/interfaces/App/CommandMenuWrapper.tsx
index 702bb053ae7..015fb2d8151 100644
--- a/studio/components/interfaces/App/CommandMenuWrapper.tsx
+++ b/studio/components/interfaces/App/CommandMenuWrapper.tsx
@@ -13,6 +13,7 @@ import { uuidv4 } from 'lib/helpers'
import { useProfile } from 'lib/profile'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
import { createSqlSnippetSkeleton } from '../SQLEditor/SQLEditor.utils'
+import { OPT_IN_TAGS } from 'lib/constants'
const CommandMenuWrapper = ({ children }: PropsWithChildren<{}>) => {
const { ref } = useParams()
@@ -22,7 +23,7 @@ const CommandMenuWrapper = ({ children }: PropsWithChildren<{}>) => {
const opt_in_tags = selectedOrganization?.opt_in_tags
const snap = useSqlEditorStateSnapshot()
- const isOptedInToAI = opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
+ const isOptedInToAI = opt_in_tags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
const { profile } = useProfile()
const { data: settings } = useProjectApiQuery({ projectRef: ref })
diff --git a/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
index 44383ae66cc..0468cf0117d 100644
--- a/studio/components/interfaces/BranchManagement/BranchManagement.tsx
+++ b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
@@ -26,6 +26,7 @@ import { useBranchesDisableMutation } from 'data/branches/branches-disable-mutat
import { Branch, useBranchesQuery } from 'data/branches/branches-query'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
import { useSelectedOrganization, useSelectedProject, useStore } from 'hooks'
+import { OPT_IN_TAGS } from 'lib/constants'
import { useAppUiStateSnapshot } from 'state/app'
import { MainBranchPanel } from './BranchPanels'
import CreateBranchSidePanel from './CreateBranchSidePanel'
@@ -40,7 +41,7 @@ const BranchManagement = () => {
const selectedOrg = useSelectedOrganization()
const hasAccessToBranching =
- selectedOrg?.opt_in_tags?.includes('PREVIEW_BRANCHES_OPT_IN') ?? false
+ selectedOrg?.opt_in_tags?.includes(OPT_IN_TAGS.PREVIEW_BRANCHES) ?? false
const hasBranchEnabled = project?.is_branch_enabled
const isBranch = project?.parent_project_ref !== undefined
diff --git a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
index 16facd87e61..69fbf343cf7 100644
--- a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
+++ b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
@@ -19,6 +19,7 @@ import {
import { useOrganizationUpdateMutation } from 'data/organizations/organization-update-mutation'
import { invalidateOrganizationsQuery } from 'data/organizations/organizations-query'
import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'
+import { OPT_IN_TAGS } from 'lib/constants'
import OrganizationDeletePanel from './OrganizationDeletePanel'
const GeneralSettings = () => {
@@ -30,14 +31,14 @@ const GeneralSettings = () => {
const { name, opt_in_tags } = selectedOrganization ?? {}
const formId = 'org-general-settings'
- const isOptedIntoAi = opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN')
+ const isOptedIntoAi = opt_in_tags?.includes(OPT_IN_TAGS.AI_SQL)
const initialValues = { name: name ?? '', isOptedIntoAi }
const canUpdateOrganization = useCheckPermissions(PermissionAction.UPDATE, 'organizations')
const canDeleteOrganization = useCheckPermissions(PermissionAction.UPDATE, 'organizations')
const { mutate: updateOrganization, isLoading: isUpdating } = useOrganizationUpdateMutation()
- const onUpdateOrganization = async (values: any, { setSubmitting, resetForm }: any) => {
+ const onUpdateOrganization = async (values: any, { resetForm }: any) => {
if (!canUpdateOrganization) {
return ui.setNotification({
category: 'error',
@@ -48,9 +49,12 @@ const GeneralSettings = () => {
if (!slug) return console.error('Slug is required')
const existingOptInTags = selectedOrganization?.opt_in_tags ?? []
- const updatedOptInTags = values.isOptedIntoAi
- ? existingOptInTags.concat(['AI_SQL_GENERATOR_OPT_IN'])
- : existingOptInTags.filter((x) => x !== 'AI_SQL_GENERATOR_OPT_IN')
+ const updatedOptInTags =
+ values.isOptedIntoAi && !existingOptInTags.includes(OPT_IN_TAGS.AI_SQL)
+ ? existingOptInTags.concat([OPT_IN_TAGS.AI_SQL])
+ : !values.isOptedIntoAi && existingOptInTags.includes(OPT_IN_TAGS.AI_SQL)
+ ? existingOptInTags.filter((x) => x !== OPT_IN_TAGS.AI_SQL)
+ : existingOptInTags
updateOrganization(
{ slug, name: values.name, opt_in_tags: updatedOptInTags },
diff --git a/studio/components/interfaces/SQLEditor/AISchemaSuggestionPopover.tsx b/studio/components/interfaces/SQLEditor/AISchemaSuggestionPopover.tsx
index 656be8b0662..5183c0765de 100644
--- a/studio/components/interfaces/SQLEditor/AISchemaSuggestionPopover.tsx
+++ b/studio/components/interfaces/SQLEditor/AISchemaSuggestionPopover.tsx
@@ -1,7 +1,7 @@
import * as Popover from '@radix-ui/react-popover'
import { motion } from 'framer-motion'
import { useLocalStorageQuery, useSelectedOrganization, useSelectedProject } from 'hooks'
-import { IS_PLATFORM } from 'lib/constants'
+import { IS_PLATFORM, OPT_IN_TAGS } from 'lib/constants'
import { PropsWithChildren, useEffect, useState } from 'react'
import { Button, IconInfo } from 'ui'
@@ -16,8 +16,7 @@ const AISchemaSuggestionPopover = ({
onClickSettings,
}: PropsWithChildren<AISchemaSuggestionPopoverProps>) => {
const selectedOrganization = useSelectedOrganization()
- const isOptedInToAI =
- selectedOrganization?.opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
+ const isOptedInToAI = selectedOrganization?.opt_in_tags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
const [hasEnabledAISchema] = useLocalStorageQuery('supabase_sql-editor-ai-schema', true)
const [isDelayComplete, setIsDelayComplete] = useState(false)
const [aiQueryCount] = useLocalStorageQuery('supabase_sql-editor-ai-query-count', 0)
diff --git a/studio/components/interfaces/SQLEditor/AISettingsModal.tsx b/studio/components/interfaces/SQLEditor/AISettingsModal.tsx
index cf705722865..aaa07e7e107 100644
--- a/studio/components/interfaces/SQLEditor/AISettingsModal.tsx
+++ b/studio/components/interfaces/SQLEditor/AISettingsModal.tsx
@@ -1,6 +1,6 @@
import { ModalProps } from '@ui/components/Modal/Modal'
import { useLocalStorageQuery, useSelectedOrganization, useStore } from 'hooks'
-import { IS_PLATFORM } from 'lib/constants'
+import { IS_PLATFORM, OPT_IN_TAGS } from 'lib/constants'
import Link from 'next/link'
import { Alert, IconExternalLink, Modal, Toggle } from 'ui'
export interface AISettingsModalProps {
@@ -9,8 +9,7 @@ export interface AISettingsModalProps {
const AISettingsModal = (props: ModalProps) => {
const selectedOrganization = useSelectedOrganization()
- const isOptedInToAI =
- selectedOrganization?.opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
+ const isOptedInToAI = selectedOrganization?.opt_in_tags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
const [hasEnabledAISchema, setHasEnabledAISchema] = useLocalStorageQuery(
'supabase_sql-editor-ai-schema-enabled',
true
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index f9efcecda73..ba145a7528d 100644
--- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -35,7 +35,7 @@ import {
useSelectedProject,
useStore,
} from 'hooks'
-import { IS_PLATFORM } from 'lib/constants'
+import { IS_PLATFORM, OPT_IN_TAGS } from 'lib/constants'
import { removeCommentsFromSql, uuidv4 } from 'lib/helpers'
import { useProfile } from 'lib/profile'
import Telemetry from 'lib/telemetry'
@@ -122,8 +122,7 @@ const SQLEditor = () => {
const selectedOrganization = useSelectedOrganization()
const selectedProject = useSelectedProject()
- const isOptedInToAI =
- selectedOrganization?.opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
+ const isOptedInToAI = selectedOrganization?.opt_in_tags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
const [hasEnabledAISchema] = useLocalStorageQuery('supabase_sql-editor-ai-schema-enabled', true)
const [isAcceptDiffLoading, setIsAcceptDiffLoading] = useState(false)
const [, setAiQueryCount] = useLocalStorageQuery('supabase_sql-editor-ai-query-count', 0)
diff --git a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
index 244734b598b..c7874ba7f7f 100644
--- a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
+++ b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
@@ -8,7 +8,7 @@ import {
useStore,
useFlag,
} from 'hooks'
-import { IS_PLATFORM } from 'lib/constants'
+import { IS_PLATFORM, OPT_IN_TAGS } from 'lib/constants'
import { format } from 'sql-formatter'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
import { AiIconAnimation, Button } from 'ui'
@@ -30,8 +30,7 @@ const UtilityTabResults = ({ id, isExecuting }: UtilityTabResultsProps) => {
const { setDebugSolution, setAiInput, setSqlDiff, sqlDiff } = useSqlEditor()
const selectedOrganization = useSelectedOrganization()
const selectedProject = useSelectedProject()
- const isOptedInToAI =
- selectedOrganization?.opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
+ const isOptedInToAI = selectedOrganization?.opt_in_tags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
const [hasEnabledAISchema] = useLocalStorageQuery('supabase_sql-editor-ai-schema-enabled', true)
const includeSchemaMetadata = (isOptedInToAI || !IS_PLATFORM) && hasEnabledAISchema
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
index e1aa1f34fc1..af857abb4f5 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
@@ -13,6 +13,7 @@ import { useAppUiStateSnapshot } from 'state/app'
import BranchingWaitlistPopover from './BranchingWaitlistPopover'
import GithubRepositorySelection from './GithubRepositorySelection'
import VercelProjectSelection from './VercelProjectSelection'
+import { OPT_IN_TAGS } from 'lib/constants'
const EnableBranchingButton = () => {
const { ui } = useStore()
@@ -45,7 +46,7 @@ const EnableBranchingButton = () => {
})
const hasAccessToBranching =
- selectedOrg?.opt_in_tags?.includes('PREVIEW_BRANCHES_OPT_IN') ?? false
+ selectedOrg?.opt_in_tags?.includes(OPT_IN_TAGS.PREVIEW_BRANCHES) ?? false
const hasGithubIntegrationInstalled =
integrations?.some((integration) => integration.integration.name === 'GitHub') ?? false
diff --git a/studio/lib/constants/index.ts b/studio/lib/constants/index.ts
index 159643b6dee..614c67455ad 100644
--- a/studio/lib/constants/index.ts
+++ b/studio/lib/constants/index.ts
@@ -90,3 +90,8 @@ export const USAGE_APPROACHING_THRESHOLD = 0.75
export const LOCAL_STORAGE_KEYS = {
RECENTLY_VISITED_ORGANIZATION: 'supabase-organization',
}
+
+export const OPT_IN_TAGS = {
+ AI_SQL: 'AI_SQL_GENERATOR_OPT_IN',
+ PREVIEW_BRANCHES: 'PREVIEW_BRANCHES_OPT_IN',
+}