OverviewTab.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'
  6. import { IntegrationOverviewTabV2 } from '../Integration/IntegrationOverviewTabV2'
  7. import { useIsMarketplaceEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
  8. import { DataApiEnableSwitch } from '@/components/interfaces/Settings/API/DataApiEnableSwitch'
  9. import { DataApiProjectUrlCard } from '@/components/interfaces/Settings/API/DataApiProjectUrlCard'
  10. import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled'
  11. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  12. import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants'
  13. const DataApiOverview = () => {
  14. const { ref: projectRef } = useParams()
  15. const { data: project, isPending: isProjectLoading } = useSelectedProjectQuery()
  16. const { isEnabled, isPending: isConfigLoading } = useIsDataApiEnabled({ projectRef })
  17. const isLoading = isProjectLoading || isConfigLoading
  18. return (
  19. <div className="max-w-4xl flex flex-col">
  20. {!isProjectLoading && project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY ? (
  21. <Alert variant="destructive">
  22. <AlertCircle size={16} />
  23. <AlertTitle>API settings are unavailable as the project is not active</AlertTitle>
  24. </Alert>
  25. ) : (
  26. <>
  27. <div
  28. className={cn(
  29. IS_PLATFORM && (isLoading || !isEnabled) && 'opacity-50 pointer-events-none'
  30. )}
  31. >
  32. <DataApiProjectUrlCard />
  33. </div>
  34. {IS_PLATFORM ? (
  35. <DataApiEnableSwitch />
  36. ) : (
  37. <Admonition
  38. type="default"
  39. title="Managed via configuration variables"
  40. 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."
  41. />
  42. )}
  43. </>
  44. )}
  45. </div>
  46. )
  47. }
  48. export const DataApiOverviewTab = () => {
  49. const isMarketplaceEnabled = useIsMarketplaceEnabled()
  50. if (isMarketplaceEnabled) {
  51. return (
  52. <IntegrationOverviewTabV2>
  53. <DataApiOverview />
  54. </IntegrationOverviewTabV2>
  55. )
  56. } else {
  57. return (
  58. <IntegrationOverviewTab>
  59. <div className="px-10">
  60. <DataApiOverview />
  61. </div>
  62. </IntegrationOverviewTab>
  63. )
  64. }
  65. }