mirror of
https://github.com/supabase/supabase.git
synced 2026-07-21 15:07:35 -04:00
c713135384
- 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
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import type { IntegrationDefinition, Navigation } from './Integrations.constants'
|
|
|
|
export type InstallActionType = 'oauth' | 'add-wrapper' | 'installed' | 'install-sheet' | null
|
|
|
|
export type DatabaseExtension = {
|
|
name: string
|
|
installed_version: string | null
|
|
}
|
|
|
|
/**
|
|
* Returns whether all required extensions for an integration are enabled in the database.
|
|
*/
|
|
export function areRequiredExtensionsInstalledFor(
|
|
integration: IntegrationDefinition | undefined,
|
|
extensions: DatabaseExtension[] | undefined
|
|
): boolean {
|
|
if (!integration?.requiredExtensions?.length || !extensions) return false
|
|
return integration.requiredExtensions.every(
|
|
(name) => !!extensions.find((ext) => ext.name === name)?.installed_version
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Returns the filtered navigation items for an integration based on install / feature-flag state.
|
|
* If the marketplace flag is off, only expose the Wrappers tab once extensions are installed
|
|
*/
|
|
export function getFilteredNavItems({
|
|
integration,
|
|
isInstalled,
|
|
isMarketplaceEnabled,
|
|
areRequiredExtensionsInstalled,
|
|
}: {
|
|
integration: IntegrationDefinition | undefined
|
|
isInstalled: boolean
|
|
isMarketplaceEnabled: boolean
|
|
areRequiredExtensionsInstalled: boolean
|
|
}): Navigation[] {
|
|
if (!integration?.navigation) return []
|
|
if (isInstalled || integration.type !== 'wrapper') return integration.navigation
|
|
if (isMarketplaceEnabled || areRequiredExtensionsInstalled) return integration.navigation
|
|
return integration.navigation.filter((nav) => nav.route !== 'wrappers')
|
|
}
|
|
|
|
/**
|
|
* Returns which install action type to render for an integration.
|
|
*/
|
|
export function getInstallActionType({
|
|
integration,
|
|
isMarketplaceEnabled,
|
|
areRequiredExtensionsInstalled,
|
|
isInstalled,
|
|
}: {
|
|
integration: IntegrationDefinition | undefined
|
|
isMarketplaceEnabled: boolean
|
|
areRequiredExtensionsInstalled: boolean
|
|
isInstalled: boolean
|
|
}): InstallActionType {
|
|
if (!integration) return null
|
|
if (integration.type === 'oauth') return 'oauth'
|
|
if (integration.type === 'wrapper' && (isMarketplaceEnabled || areRequiredExtensionsInstalled)) {
|
|
return 'add-wrapper'
|
|
}
|
|
if (isInstalled) return 'installed'
|
|
return 'install-sheet'
|
|
}
|