TopSection.tsx 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { ReactFlowProvider } from '@xyflow/react'
  2. import Link from 'next/link'
  3. import { Badge, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
  4. import { InstanceConfiguration } from '../Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration'
  5. import { ActivityStats } from '@/components/interfaces/ProjectHome/ActivityStats'
  6. import { ProjectConnectionPopover } from '@/components/interfaces/ProjectHome/ProjectConnectionPopover'
  7. import { ProjectPausedState } from '@/components/layouts/ProjectLayout/PausedState/ProjectPausedState'
  8. import { InlineLink } from '@/components/ui/InlineLink'
  9. import { ProjectUpgradeFailedBanner } from '@/components/ui/ProjectUpgradeFailedBanner'
  10. import { useBranchesQuery } from '@/data/branches/branches-query'
  11. import { useProjectDetailQuery } from '@/data/projects/project-detail-query'
  12. import { useIsOrioleDb, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  13. import { DOCS_URL, PROJECT_STATUS } from '@/lib/constants'
  14. export const TopSection = () => {
  15. const isOrioleDb = useIsOrioleDb()
  16. const { data: project } = useSelectedProjectQuery()
  17. const { data: parentProject } = useProjectDetailQuery({ ref: project?.parent_project_ref })
  18. const { data: branches } = useBranchesQuery({
  19. projectRef: project?.parent_project_ref ?? project?.ref,
  20. })
  21. const mainBranch = branches?.find((branch) => branch.is_default)
  22. const currentBranch = branches?.find((branch) => branch.project_ref === project?.ref)
  23. const isMainBranch = currentBranch?.name === mainBranch?.name
  24. const isPaused = project?.status === PROJECT_STATUS.INACTIVE
  25. const projectName =
  26. currentBranch && !isMainBranch
  27. ? currentBranch.name
  28. : project?.name
  29. ? project.name
  30. : 'Welcome to your project'
  31. if (isPaused) {
  32. return <ProjectPausedState />
  33. }
  34. return (
  35. <div className="flex flex-col gap-y-4">
  36. <div className="grid grid-cols-1 md:grid-cols-2 gap-8 py-0 w-full items-center">
  37. <div className="flex flex-col">
  38. <div className="flex flex-row flex-wrap items-center gap-4 w-full">
  39. <div>
  40. {!isMainBranch && (
  41. <Link
  42. href={`/project/${parentProject?.ref}`}
  43. className="text-sm text-foreground-light"
  44. >
  45. {parentProject?.name}
  46. </Link>
  47. )}
  48. <div className="flex items-center gap-x-2">
  49. <h1 className="text-3xl">{projectName}</h1>
  50. {isOrioleDb && (
  51. <Tooltip>
  52. <TooltipTrigger asChild>
  53. <Badge variant="warning">OrioleDB</Badge>
  54. </TooltipTrigger>
  55. <TooltipContent side="bottom" align="start" className="max-w-80 text-center">
  56. This project is using Postgres with OrioleDB which is currently in preview and
  57. not suitable for production workloads. View our{' '}
  58. <InlineLink href={`${DOCS_URL}/guides/database/orioledb`}>
  59. documentation
  60. </InlineLink>{' '}
  61. for all limitations.
  62. </TooltipContent>
  63. </Tooltip>
  64. )}
  65. </div>
  66. <ProjectConnectionPopover projectRef={project?.ref} />
  67. </div>
  68. </div>
  69. <div className="mt-8">
  70. <ActivityStats />
  71. </div>
  72. </div>
  73. <div>
  74. <div
  75. className={cn(
  76. 'w-full h-[400px] md:h-[500px] border border-muted rounded-md overflow-hidden flex flex-col relative'
  77. )}
  78. >
  79. <ReactFlowProvider>
  80. <InstanceConfiguration diagramOnly />
  81. </ReactFlowProvider>
  82. </div>
  83. </div>
  84. </div>
  85. <ProjectUpgradeFailedBanner />
  86. </div>
  87. )
  88. }