mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 20:35:07 +03:00
## Context Related to marketplace integrations Shifts Database Webhooks integration to the new Integrations UI. This one's a bit different from the previous PRs as this involves a full SQL installation query instead of only just a database extension. So am tweaking `Integrations.constants` a little. For context eventually all the integrations will be pulled remotely from a database, so am still trying to figure out an optimal data structure, but requirements will be clearer as we build out the UI RE installing integrations: - For now, if the integration has a provided SQL installation command, that'll take precedence - Else, if the integration has a provided SQL installation query, we'll use that on the /query endpoint - Otherwise, if the integration only requires database extensions, dashboard will generate the queries to install the extensions - In the case of the former tho, we won't allow users to choose which schema to install the extension in too Just ping me if any clarification's required! ## To test - [ ] Verify that you can install the database webhooks with the new integration UI - [ ] Verify that behaviour is status quo without the new integration UI
104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useFlag, useParams } from 'common'
|
|
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
|
|
import NoPermission from 'components/ui/NoPermission'
|
|
import { useHooksEnableMutation } from 'data/database/hooks-enable-mutation'
|
|
import { useSchemasQuery } from 'data/database/schemas-query'
|
|
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { toast } from 'sonner'
|
|
import { Admonition } from 'ui-patterns'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'
|
|
import { IntegrationOverviewTabV2 } from '../Integration/IntegrationOverviewTabV2'
|
|
|
|
export const WebhooksOverviewTab = () => {
|
|
const { ref: projectRef } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const isMarketplaceEnabled = useFlag('marketplaceIntegrations')
|
|
|
|
const {
|
|
data: schemas,
|
|
isSuccess: isSchemasLoaded,
|
|
refetch,
|
|
} = useSchemasQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const isHooksEnabled = schemas?.some((schema) => schema.name === 'supabase_functions')
|
|
const { can: canReadWebhooks, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(
|
|
PermissionAction.TENANT_SQL_ADMIN_READ,
|
|
'triggers'
|
|
)
|
|
|
|
const { mutate: enableHooks, isPending: isEnablingHooks } = useHooksEnableMutation({
|
|
onSuccess: async () => {
|
|
await refetch()
|
|
toast.success('Successfully enabled webhooks')
|
|
},
|
|
})
|
|
|
|
const enableHooksForProject = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
enableHooks({ ref: projectRef })
|
|
}
|
|
|
|
if (!isSchemasLoaded || isLoadingPermissions) {
|
|
return (
|
|
<div className="p-10">
|
|
<GenericSkeletonLoader />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!canReadWebhooks) {
|
|
return (
|
|
<div className="p-10">
|
|
<NoPermission isFullPage resourceText="view database webhooks" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (isMarketplaceEnabled) {
|
|
return <IntegrationOverviewTabV2 />
|
|
} else {
|
|
return (
|
|
<IntegrationOverviewTab
|
|
hideRequiredExtensionsSection
|
|
actions={
|
|
isSchemasLoaded && isHooksEnabled ? null : (
|
|
<Admonition
|
|
showIcon={false}
|
|
type="default"
|
|
title="Enable database webhooks on your project"
|
|
>
|
|
<p>
|
|
Database Webhooks can be used to trigger serverless functions or send requests to an
|
|
HTTP endpoint
|
|
</p>
|
|
<ButtonTooltip
|
|
className="mt-2 w-fit"
|
|
onClick={() => enableHooksForProject()}
|
|
disabled={isEnablingHooks}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canReadWebhooks
|
|
? 'You need additional permissions to enable webhooks'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
Enable webhooks
|
|
</ButtonTooltip>
|
|
</Admonition>
|
|
)
|
|
}
|
|
/>
|
|
)
|
|
}
|
|
}
|