mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 18:35:07 +03:00
- fix install badge state in wrappers detail page - add "Install" button in top action bar - "Install wrapper" if required extensions _aren't_ installed - "Add new wrapper" if required extensions _are_ installed - make wrappers "one-click install" by - showing the required extensions in the CreateWrappersSheet - and automatically installing them on wrapper submission Only available behind `isMarketplaceEnabled` flag at the moment. https://github.com/user-attachments/assets/38f5549d-938e-4e2f-a723-53b9a028e9dc
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useMemo } from 'react'
|
|
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
const WRAPPER_REQUIRED_EXTENSION_NAMES = ['wrappers', 'supabase_vault']
|
|
|
|
interface AddWrapperButtonProps {
|
|
type?: 'default' | 'primary' | 'outline'
|
|
onClick: () => void
|
|
}
|
|
|
|
export const AddWrapperButton = ({ type = 'default', onClick }: AddWrapperButtonProps) => {
|
|
const { can: canCreateWrapper } = useAsyncCheckPermissions(
|
|
PermissionAction.TENANT_SQL_ADMIN_WRITE,
|
|
'wrappers'
|
|
)
|
|
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: extensions } = useDatabaseExtensionsQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const needsExtensions = useMemo(
|
|
() =>
|
|
WRAPPER_REQUIRED_EXTENSION_NAMES.some(
|
|
(name) => !extensions?.find((ext) => ext.name === name)?.installed_version
|
|
),
|
|
[extensions]
|
|
)
|
|
|
|
return (
|
|
<ButtonTooltip
|
|
type={type}
|
|
onClick={onClick}
|
|
disabled={!canCreateWrapper}
|
|
tooltip={{
|
|
content: {
|
|
text: !canCreateWrapper
|
|
? 'You need additional permissions to create a foreign data wrapper'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
{needsExtensions ? 'Install wrapper' : 'Add new wrapper'}
|
|
</ButtonTooltip>
|
|
)
|
|
}
|