useIcebergWrapper.tsx35 lines · main
| 1 | import { INTEGRATIONS } from '@/components/interfaces/Integrations/Landing/Integrations.constants' |
| 2 | import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query' |
| 3 | import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' |
| 4 | |
| 5 | export const useIcebergWrapperExtension = () => { |
| 6 | const { data: project } = useSelectedProjectQuery() |
| 7 | const { data: extensionsData, isPending: isExtensionsLoading } = useDatabaseExtensionsQuery({ |
| 8 | projectRef: project?.ref, |
| 9 | connectionString: project?.connectionString, |
| 10 | }) |
| 11 | |
| 12 | const integration = INTEGRATIONS.find((i) => i.id === 'iceberg_wrapper') |
| 13 | |
| 14 | if (!integration || integration.type !== 'wrapper') { |
| 15 | // This should never happen |
| 16 | return { extension: undefined, state: 'not-found' } |
| 17 | } |
| 18 | |
| 19 | const wrapperMeta = integration.meta |
| 20 | |
| 21 | const wrappersExtension = extensionsData?.find((ext) => ext.name === 'wrappers') |
| 22 | const isWrappersExtensionInstalled = !!wrappersExtension?.installed_version |
| 23 | const hasRequiredVersion = |
| 24 | (wrappersExtension?.installed_version ?? '') >= (wrapperMeta?.minimumExtensionVersion ?? '') |
| 25 | |
| 26 | const state: 'loading' | 'installed' | 'needs-upgrade' | 'not-installed' = isExtensionsLoading |
| 27 | ? 'loading' |
| 28 | : isWrappersExtensionInstalled |
| 29 | ? hasRequiredVersion |
| 30 | ? 'installed' |
| 31 | : 'needs-upgrade' |
| 32 | : 'not-installed' |
| 33 | |
| 34 | return { extension: wrappersExtension, state } |
| 35 | } |