@@ -10,5 +10,3 @@ const BackupsEmpty = () => {
)
}
-
-export default BackupsEmpty
diff --git a/apps/studio/components/interfaces/Database/Backups/BackupsList.tsx b/apps/studio/components/interfaces/Database/Backups/BackupsList.tsx
index 484bfe785ec..7e131ff9992 100644
--- a/apps/studio/components/interfaces/Database/Backups/BackupsList.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/BackupsList.tsx
@@ -14,9 +14,9 @@ import { setProjectStatus } from 'data/projects/projects-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from 'lib/constants'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
-import BackupItem from './BackupItem'
-import BackupsEmpty from './BackupsEmpty'
-import BackupsStorageAlert from './BackupsStorageAlert'
+import { BackupItem } from './BackupItem'
+import { BackupsEmpty } from './BackupsEmpty'
+import { BackupsStorageAlert } from './BackupsStorageAlert'
const BackupsList = () => {
const router = useRouter()
diff --git a/apps/studio/components/interfaces/Database/Backups/BackupsStorageAlert.tsx b/apps/studio/components/interfaces/Database/Backups/BackupsStorageAlert.tsx
index e1544e14393..52e0c0184e3 100644
--- a/apps/studio/components/interfaces/Database/Backups/BackupsStorageAlert.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/BackupsStorageAlert.tsx
@@ -1,7 +1,6 @@
-import { AlertDescription_Shadcn_, Alert_Shadcn_ } from 'ui'
-import { WarningIcon } from 'ui'
+import { AlertDescription_Shadcn_, Alert_Shadcn_, WarningIcon } from 'ui'
-const BackupsStorageAlert = () => {
+export const BackupsStorageAlert = () => {
return (
@@ -13,5 +12,3 @@ const BackupsStorageAlert = () => {
)
}
-
-export default BackupsStorageAlert
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
index 7e6f70b3f3f..33a4d11e0b8 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
@@ -6,7 +6,7 @@ import { useParams } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { FormPanel } from 'components/ui/Forms/FormPanel'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { getPITRRetentionDuration } from './PITR.utils'
const PITRNotice = ({}) => {
@@ -14,7 +14,7 @@ const PITRNotice = ({}) => {
const { data: addonsResponse } = useProjectAddonsQuery({ projectRef })
const retentionPeriod = getPITRRetentionDuration(addonsResponse?.selected_addons ?? [])
- const canUpdateSubscription = useCheckPermissions(
+ const { can: canUpdateSubscription } = useAsyncCheckProjectPermissions(
PermissionAction.BILLING_WRITE,
'stripe.subscriptions'
)
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
index 86a651a0da5..fa2819c877f 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
@@ -18,8 +18,8 @@ import {
Modal,
WarningIcon,
} from 'ui'
-import BackupsEmpty from '../BackupsEmpty'
-import BackupsStorageAlert from '../BackupsStorageAlert'
+import { BackupsEmpty } from '../BackupsEmpty'
+import { BackupsStorageAlert } from '../BackupsStorageAlert'
import type { Timezone } from './PITR.types'
import { getClientTimezone } from './PITR.utils'
import PITRStatus from './PITRStatus'
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
index 128a84e006e..0f774102693 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
@@ -3,13 +3,13 @@ import { useParams } from 'common'
import dayjs from 'dayjs'
import { AlertCircle } from 'lucide-react'
+import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { FormPanel } from 'components/ui/Forms/FormPanel'
import { useBackupsQuery } from 'data/database/backups-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import type { Timezone } from './PITR.types'
import { TimezoneSelection } from './TimezoneSelection'
-import { ButtonTooltip } from 'components/ui/ButtonTooltip'
interface PITRStatusProps {
selectedTimezone: Timezone
@@ -41,7 +41,7 @@ const PITRStatus = ({
.tz(selectedTimezone?.utc[0])
.format('DD MMM YYYY, HH:mm:ss')
- const canTriggerPhysicalBackup = useCheckPermissions(
+ const { can: canTriggerPhysicalBackup } = useAsyncCheckProjectPermissions(
PermissionAction.INFRA_EXECUTE,
'queue_job.walg.prepare_restore'
)
diff --git a/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx b/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx
index e25d3fad340..c7868594841 100644
--- a/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx
@@ -4,7 +4,7 @@ import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { Badge, Button } from 'ui'
import { TimestampInfo } from 'ui-patterns'
-import BackupsEmpty from '../BackupsEmpty'
+import { BackupsEmpty } from '../BackupsEmpty'
interface BackupsListProps {
onSelectRestore: (id: number) => void
diff --git a/apps/studio/components/interfaces/Database/Extensions/ExtensionCard.tsx b/apps/studio/components/interfaces/Database/Extensions/ExtensionCard.tsx
index 68d280a0268..9e1e2c38af0 100644
--- a/apps/studio/components/interfaces/Database/Extensions/ExtensionCard.tsx
+++ b/apps/studio/components/interfaces/Database/Extensions/ExtensionCard.tsx
@@ -7,7 +7,7 @@ import { toast } from 'sonner'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useDatabaseExtensionDisableMutation } from 'data/database-extensions/database-extension-disable-mutation'
import { DatabaseExtension } from 'data/database-extensions/database-extensions-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { useIsOrioleDb, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { extensions } from 'shared-data'
import { Button, cn, Switch, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
@@ -28,7 +28,7 @@ const ExtensionCard = ({ extension }: ExtensionCardProps) => {
const [isDisableModalOpen, setIsDisableModalOpen] = useState(false)
const [showConfirmEnableModal, setShowConfirmEnableModal] = useState(false)
- const canUpdateExtensions = useCheckPermissions(
+ const { can: canUpdateExtensions } = useAsyncCheckProjectPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'extensions'
)
diff --git a/apps/studio/components/interfaces/Database/Extensions/Extensions.tsx b/apps/studio/components/interfaces/Database/Extensions/Extensions.tsx
index 73ca129d0c5..b9e629dcda1 100644
--- a/apps/studio/components/interfaces/Database/Extensions/Extensions.tsx
+++ b/apps/studio/components/interfaces/Database/Extensions/Extensions.tsx
@@ -9,7 +9,7 @@ import InformationBox from 'components/ui/InformationBox'
import NoSearchResults from 'components/ui/NoSearchResults'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
-import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { Input } from 'ui'
import ExtensionCard from './ExtensionCard'
@@ -42,11 +42,8 @@ const Extensions = () => {
(ext) => !isNull(ext.installed_version)
)
- const canUpdateExtensions = useCheckPermissions(
- PermissionAction.TENANT_SQL_ADMIN_WRITE,
- 'extensions'
- )
- const isPermissionsLoaded = usePermissionsLoaded()
+ const { can: canUpdateExtensions, isSuccess: isPermissionsLoaded } =
+ useAsyncCheckProjectPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'extensions')
useEffect(() => {
if (filter !== undefined) setFilterString(filter as string)
diff --git a/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionList.tsx b/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionList.tsx
index 9e42241f27c..4d72806bd16 100644
--- a/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionList.tsx
+++ b/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionList.tsx
@@ -6,7 +6,7 @@ import { useRouter } from 'next/router'
import Table from 'components/to-be-cleaned/Table'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useDatabaseFunctionsQuery } from 'data/database-functions/database-functions-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
import {
@@ -50,7 +50,7 @@ const FunctionList = ({
(func) => func.name.toLocaleLowerCase()
)
const projectRef = selectedProject?.ref
- const canUpdateFunctions = useCheckPermissions(
+ const { can: canUpdateFunctions } = useAsyncCheckProjectPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'functions'
)
diff --git a/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx b/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx
index 0af82c75f81..9f478304989 100644
--- a/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx
+++ b/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx
@@ -13,7 +13,7 @@ import SchemaSelector from 'components/ui/SchemaSelector'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useDatabaseFunctionsQuery } from 'data/database-functions/database-functions-query'
import { useSchemasQuery } from 'data/database/schemas-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { useIsProtectedSchema } from 'hooks/useProtectedSchemas'
@@ -51,18 +51,19 @@ const FunctionsList = ({
router.push(url)
}
- const canCreateFunctions = useCheckPermissions(
+ const { can: canCreateFunctions } = useAsyncCheckProjectPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'functions'
)
- const { data: schemas } = useSchemasQuery({
+ const { isSchemaLocked } = useIsProtectedSchema({ schema: selectedSchema })
+
+ // [Joshen] This is to preload the data for the Schema Selector
+ useSchemasQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
- const { isSchemaLocked } = useIsProtectedSchema({ schema: selectedSchema })
-
const {
data: functions,
error,
diff --git a/apps/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx b/apps/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx
index 4f37d899979..c259acb39d0 100644
--- a/apps/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx
+++ b/apps/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx
@@ -1,3 +1,4 @@
+import { PostgresTrigger } from '@supabase/postgres-meta'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { includes, noop } from 'lodash'
import { Edit3, MoreVertical, Trash } from 'lucide-react'
@@ -7,7 +8,7 @@ import { useParams } from 'common'
import Table from 'components/to-be-cleaned/Table'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useDatabaseHooksQuery } from 'data/database-triggers/database-triggers-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { BASE_PATH } from 'lib/constants'
import {
@@ -23,11 +24,16 @@ import {
export interface HookListProps {
schema: string
filterString: string
- editHook: (hook: any) => void
- deleteHook: (hook: any) => void
+ editHook: (hook: PostgresTrigger) => void
+ deleteHook: (hook: PostgresTrigger) => void
}
-const HookList = ({ schema, filterString, editHook = noop, deleteHook = noop }: HookListProps) => {
+export const HookList = ({
+ schema,
+ filterString,
+ editHook = noop,
+ deleteHook = noop,
+}: HookListProps) => {
const { ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const { data: hooks } = useDatabaseHooksQuery({
@@ -39,16 +45,19 @@ const HookList = ({ schema, filterString, editHook = noop, deleteHook = noop }:
const restUrlTld = restUrl ? new URL(restUrl).hostname.split('.').pop() : 'co'
const filteredHooks = (hooks ?? []).filter(
- (x: any) =>
+ (x) =>
includes(x.name.toLowerCase(), filterString.toLowerCase()) &&
x.schema === schema &&
x.function_args.length >= 2
)
- const canUpdateWebhook = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'triggers')
+ const { can: canUpdateWebhook } = useAsyncCheckProjectPermissions(
+ PermissionAction.TENANT_SQL_ADMIN_WRITE,
+ 'triggers'
+ )
return (
<>
- {filteredHooks.map((x: any) => {
+ {filteredHooks.map((x) => {
const isEdgeFunction = (url: string) =>
url.includes(`https://${ref}.functions.supabase.${restUrlTld}/`) ||
url.includes(`https://${ref}.supabase.${restUrlTld}/functions/`)
@@ -134,5 +143,3 @@ const HookList = ({ schema, filterString, editHook = noop, deleteHook = noop }:
>
)
}
-
-export default HookList
diff --git a/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx b/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
index e255efb78d0..7340883f745 100644
--- a/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
+++ b/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
@@ -1,3 +1,4 @@
+import { PostgresTrigger } from '@supabase/postgres-meta'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { includes, map as lodashMap, uniqBy } from 'lodash'
import { Search } from 'lucide-react'
@@ -9,20 +10,27 @@ import { DocsButton } from 'components/ui/DocsButton'
import NoSearchResults from 'components/ui/NoSearchResults'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useDatabaseHooksQuery } from 'data/database-triggers/database-triggers-query'
-import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions'
+import {
+ useAsyncCheckProjectPermissions,
+ usePermissionsLoaded,
+} from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { noop } from 'lib/void'
import { Input } from 'ui'
-import HooksListEmpty from './HooksListEmpty'
-import SchemaTable from './SchemaTable'
+import { HooksListEmpty } from './HooksListEmpty'
+import { SchemaTable } from './SchemaTable'
export interface HooksListProps {
createHook: () => void
- editHook: (hook: any) => void
- deleteHook: (hook: any) => void
+ editHook: (hook: PostgresTrigger) => void
+ deleteHook: (hook: PostgresTrigger) => void
}
-const HooksList = ({ createHook = noop, editHook = noop, deleteHook = noop }: HooksListProps) => {
+export const HooksList = ({
+ createHook = noop,
+ editHook = noop,
+ deleteHook = noop,
+}: HooksListProps) => {
const { data: project } = useSelectedProjectQuery()
const {
data: hooks,
@@ -41,7 +49,10 @@ const HooksList = ({ createHook = noop, editHook = noop, deleteHook = noop }: Ho
)
const filteredHookSchemas = lodashMap(uniqBy(filteredHooks, 'schema'), 'schema')
- const canCreateWebhooks = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'triggers')
+ const { can: canCreateWebhooks } = useAsyncCheckProjectPermissions(
+ PermissionAction.TENANT_SQL_ADMIN_WRITE,
+ 'triggers'
+ )
const isPermissionsLoaded = usePermissionsLoaded()
return (
@@ -108,5 +119,3 @@ const HooksList = ({ createHook = noop, editHook = noop, deleteHook = noop }: Ho
)
}
-
-export default HooksList
diff --git a/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksListEmpty.tsx b/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksListEmpty.tsx
index 2d466c0708b..0aa73a04c31 100644
--- a/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksListEmpty.tsx
+++ b/apps/studio/components/interfaces/Database/Hooks/HooksList/HooksListEmpty.tsx
@@ -1,6 +1,6 @@
import Table from 'components/to-be-cleaned/Table'
-const HooksListEmpty = () => {
+export const HooksListEmpty = () => {
return (