OverviewTab.tsx70 lines · main
| 1 | import { useParams } from 'common' |
| 2 | import { AlertCircle } from 'lucide-react' |
| 3 | import { Alert, AlertTitle, cn } from 'ui' |
| 4 | import { Admonition } from 'ui-patterns/admonition' |
| 5 | |
| 6 | import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab' |
| 7 | import { IntegrationOverviewTabV2 } from '../Integration/IntegrationOverviewTabV2' |
| 8 | import { useIsMarketplaceEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext' |
| 9 | import { DataApiEnableSwitch } from '@/components/interfaces/Settings/API/DataApiEnableSwitch' |
| 10 | import { DataApiProjectUrlCard } from '@/components/interfaces/Settings/API/DataApiProjectUrlCard' |
| 11 | import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled' |
| 12 | import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' |
| 13 | import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants' |
| 14 | |
| 15 | const DataApiOverview = () => { |
| 16 | const { ref: projectRef } = useParams() |
| 17 | const { data: project, isPending: isProjectLoading } = useSelectedProjectQuery() |
| 18 | const { isEnabled, isPending: isConfigLoading } = useIsDataApiEnabled({ projectRef }) |
| 19 | const isLoading = isProjectLoading || isConfigLoading |
| 20 | |
| 21 | return ( |
| 22 | <div className="max-w-4xl flex flex-col"> |
| 23 | {!isProjectLoading && project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY ? ( |
| 24 | <Alert variant="destructive"> |
| 25 | <AlertCircle size={16} /> |
| 26 | <AlertTitle>API settings are unavailable as the project is not active</AlertTitle> |
| 27 | </Alert> |
| 28 | ) : ( |
| 29 | <> |
| 30 | <div |
| 31 | className={cn( |
| 32 | IS_PLATFORM && (isLoading || !isEnabled) && 'opacity-50 pointer-events-none' |
| 33 | )} |
| 34 | > |
| 35 | <DataApiProjectUrlCard /> |
| 36 | </div> |
| 37 | {IS_PLATFORM ? ( |
| 38 | <DataApiEnableSwitch /> |
| 39 | ) : ( |
| 40 | <Admonition |
| 41 | type="default" |
| 42 | title="Managed via configuration variables" |
| 43 | description="Data API settings are configured via config.toml for CLI and local development, or via docker-compose.yml and .env for self-hosted deployments." |
| 44 | /> |
| 45 | )} |
| 46 | </> |
| 47 | )} |
| 48 | </div> |
| 49 | ) |
| 50 | } |
| 51 | |
| 52 | export const DataApiOverviewTab = () => { |
| 53 | const isMarketplaceEnabled = useIsMarketplaceEnabled() |
| 54 | |
| 55 | if (isMarketplaceEnabled) { |
| 56 | return ( |
| 57 | <IntegrationOverviewTabV2> |
| 58 | <DataApiOverview /> |
| 59 | </IntegrationOverviewTabV2> |
| 60 | ) |
| 61 | } else { |
| 62 | return ( |
| 63 | <IntegrationOverviewTab> |
| 64 | <div className="px-10"> |
| 65 | <DataApiOverview /> |
| 66 | </div> |
| 67 | </IntegrationOverviewTab> |
| 68 | ) |
| 69 | } |
| 70 | } |