OverviewTab.tsx70 lines · main
1import { useParams } from 'common'
2import { AlertCircle } from 'lucide-react'
3import { Alert, AlertTitle, cn } from 'ui'
4import { Admonition } from 'ui-patterns/admonition'
5
6import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'
7import { IntegrationOverviewTabV2 } from '../Integration/IntegrationOverviewTabV2'
8import { useIsMarketplaceEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
9import { DataApiEnableSwitch } from '@/components/interfaces/Settings/API/DataApiEnableSwitch'
10import { DataApiProjectUrlCard } from '@/components/interfaces/Settings/API/DataApiProjectUrlCard'
11import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled'
12import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
13import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants'
14
15const 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
52export 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}