InfrastructureInfo.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { useParams } from 'common'
  2. import Link from 'next/link'
  3. import {
  4. Badge,
  5. Button,
  6. Input,
  7. InputGroup,
  8. InputGroupAddon,
  9. InputGroupInput,
  10. Tooltip,
  11. TooltipContent,
  12. TooltipTrigger,
  13. } from 'ui'
  14. import { Admonition } from 'ui-patterns/admonition'
  15. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  16. import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
  17. import { ProjectUpgradeAlert } from '../General/Infrastructure/ProjectUpgradeAlert'
  18. import {
  19. ReadReplicasWarning,
  20. ValidationErrorsWarning,
  21. ValidationWarningsAdmonition,
  22. } from './UpgradeWarnings'
  23. import { NoticeBar } from '@/components/interfaces/DiskManagement/ui/NoticeBar'
  24. import {
  25. ScaffoldContainer,
  26. ScaffoldDivider,
  27. ScaffoldSection,
  28. ScaffoldSectionContent,
  29. ScaffoldSectionDetail,
  30. } from '@/components/layouts/Scaffold'
  31. import AlertError from '@/components/ui/AlertError'
  32. import { useProjectUpgradeEligibilityQuery } from '@/data/config/project-upgrade-eligibility-query'
  33. import { useProjectServiceVersionsQuery } from '@/data/projects/project-service-versions'
  34. import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
  35. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  36. import { useIsOrioleDb, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  37. export const InfrastructureInfo = () => {
  38. const { ref } = useParams()
  39. const { data: project } = useSelectedProjectQuery()
  40. const {
  41. projectAuthAll: authEnabled,
  42. projectSettingsDatabaseUpgrades: showDatabaseUpgrades,
  43. databaseReplication: showReplication,
  44. } = useIsFeatureEnabled([
  45. 'project_auth:all',
  46. 'project_settings:database_upgrades',
  47. 'database:replication',
  48. ])
  49. const {
  50. data,
  51. error,
  52. isPending: isLoadingUpgradeEligibility,
  53. isError: isErrorUpgradeEligibility,
  54. isSuccess: isSuccessUpgradeEligibility,
  55. } = useProjectUpgradeEligibilityQuery({
  56. projectRef: ref,
  57. })
  58. const {
  59. data: serviceVersions,
  60. error: serviceVersionsError,
  61. isPending: isLoadingServiceVersions,
  62. isError: isErrorServiceVersions,
  63. isSuccess: isSuccessServiceVersions,
  64. } = useProjectServiceVersionsQuery({ projectRef: ref })
  65. const { data: databases } = useReadReplicasQuery({ projectRef: ref })
  66. const { current_app_version, current_app_version_release_channel, latest_app_version } =
  67. data || {}
  68. const isOnLatestVersion = current_app_version === latest_app_version
  69. const currentPgVersion = (current_app_version ?? '')
  70. .split('briven-postgres-')[1]
  71. ?.replace('-orioledb', '')
  72. const isVisibleReleaseChannel =
  73. current_app_version_release_channel &&
  74. !['ga', 'withdrawn'].includes(current_app_version_release_channel)
  75. ? current_app_version_release_channel
  76. : undefined
  77. const isOrioleDb = useIsOrioleDb()
  78. const latestPgVersion = (latest_app_version ?? '').split('briven-postgres-')[1]
  79. const isInactive = project?.status === 'INACTIVE'
  80. const hasReadReplicas = (databases ?? []).length > 1
  81. return (
  82. <>
  83. <ScaffoldDivider />
  84. {project?.cloud_provider !== 'FLY' && showReplication && (
  85. <ScaffoldContainer>
  86. <ScaffoldSection isFullWidth>
  87. <NoticeBar
  88. visible={true}
  89. type="default"
  90. title="Management of read replicas has moved"
  91. description="Read replicas is now managed under Replication in the Database section."
  92. actions={
  93. <Button type="default" asChild>
  94. <Link href={`/project/${ref}/database/replication`} className="no-underline!">
  95. Go to Replication
  96. </Link>
  97. </Button>
  98. }
  99. />
  100. </ScaffoldSection>
  101. </ScaffoldContainer>
  102. )}
  103. <ScaffoldContainer>
  104. <ScaffoldSection>
  105. <ScaffoldSectionDetail>
  106. <h4 className="text-base capitalize m-0">Service versions</h4>
  107. <p className="text-foreground-light text-sm pr-8 mt-1">
  108. Service versions and upgrade eligibility for your provisioned instance.
  109. </p>
  110. </ScaffoldSectionDetail>
  111. <ScaffoldSectionContent>
  112. {isInactive ? (
  113. <Admonition
  114. type="note"
  115. showIcon={false}
  116. title="Service versions cannot be retrieved while project is paused"
  117. description="Restoring the project will update Postgres to the newest version"
  118. />
  119. ) : (
  120. <>
  121. {/* [Joshen] Double check why we need this waterfall loading behaviour here */}
  122. {isLoadingUpgradeEligibility && <GenericSkeletonLoader />}
  123. {isErrorUpgradeEligibility && (
  124. <AlertError error={error} subject="Failed to retrieve Postgres version" />
  125. )}
  126. {isSuccessUpgradeEligibility && (
  127. <>
  128. {isLoadingServiceVersions && <GenericSkeletonLoader />}
  129. {isErrorServiceVersions && (
  130. <AlertError
  131. error={serviceVersionsError}
  132. subject="Failed to retrieve versions"
  133. />
  134. )}
  135. {isSuccessServiceVersions && (
  136. <>
  137. {authEnabled && (
  138. <FormItemLayout
  139. label="Auth version"
  140. layout="vertical"
  141. isReactForm={false}
  142. >
  143. <Input readOnly disabled value={serviceVersions?.gotrue ?? ''} />
  144. </FormItemLayout>
  145. )}
  146. <FormItemLayout
  147. label="PostgREST version"
  148. layout="vertical"
  149. isReactForm={false}
  150. >
  151. <Input readOnly disabled value={serviceVersions?.postgrest ?? ''} />
  152. </FormItemLayout>
  153. <FormItemLayout
  154. label="Postgres version"
  155. layout="vertical"
  156. isReactForm={false}
  157. >
  158. <InputGroup>
  159. <InputGroupInput
  160. readOnly
  161. disabled
  162. value={
  163. currentPgVersion || serviceVersions?.['briven-postgres'] || ''
  164. }
  165. />
  166. <InputGroupAddon align="inline-end">
  167. {[
  168. isVisibleReleaseChannel && (
  169. <Tooltip key="release-channel">
  170. <TooltipTrigger>
  171. <Badge variant="warning" className="mr-1">
  172. {isVisibleReleaseChannel}
  173. </Badge>
  174. </TooltipTrigger>
  175. <TooltipContent side="bottom" className="w-44 text-center">
  176. This project uses a {isVisibleReleaseChannel} database version
  177. release
  178. </TooltipContent>
  179. </Tooltip>
  180. ),
  181. isOrioleDb && (
  182. <Tooltip key="orioledb">
  183. <TooltipTrigger>
  184. <Badge variant="default" className="mr-1">
  185. OrioleDB
  186. </Badge>
  187. </TooltipTrigger>
  188. <TooltipContent side="bottom" className="w-44 text-center">
  189. This project uses OrioleDB
  190. </TooltipContent>
  191. </Tooltip>
  192. ),
  193. isOnLatestVersion && (
  194. <Tooltip key="latest-version">
  195. <TooltipTrigger>
  196. <Badge variant="success" className="mr-1">
  197. Latest
  198. </Badge>
  199. </TooltipTrigger>
  200. <TooltipContent side="bottom" className="w-52 text-center">
  201. Project is on the latest version of Postgres that Briven
  202. supports
  203. </TooltipContent>
  204. </Tooltip>
  205. ),
  206. ]}
  207. </InputGroupAddon>
  208. </InputGroup>
  209. </FormItemLayout>
  210. </>
  211. )}
  212. {showDatabaseUpgrades && data && data.eligible ? (
  213. hasReadReplicas ? (
  214. <ReadReplicasWarning latestPgVersion={latestPgVersion} />
  215. ) : (
  216. <ProjectUpgradeAlert />
  217. )
  218. ) : null}
  219. {showDatabaseUpgrades && data && !data.eligible && (
  220. <ValidationErrorsWarning validationErrors={data.validation_errors} />
  221. )}
  222. {showDatabaseUpgrades && data && data.warnings && (
  223. <ValidationWarningsAdmonition warnings={data.warnings} />
  224. )}
  225. </>
  226. )}
  227. </>
  228. )}
  229. </ScaffoldSectionContent>
  230. </ScaffoldSection>
  231. </ScaffoldContainer>
  232. </>
  233. )
  234. }