Skip to content

Commit a880031

Browse files
authored
Fix project card instance size missing (supabase#39616)
* Fix project card instance size missing * Fix types
1 parent a8c6f77 commit a880031

File tree

6 files changed

+45
-44
lines changed

6 files changed

+45
-44
lines changed

apps/studio/components/interfaces/Home/Home.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ export const Home = () => {
133133
)}
134134
{showInstanceSize && (
135135
<ComputeBadgeWrapper
136-
project={{
137-
ref: project?.ref,
138-
organization_slug: organization?.slug,
139-
cloud_provider: project?.cloud_provider,
140-
infra_compute_size: project?.infra_compute_size,
141-
}}
136+
projectRef={project?.ref}
137+
slug={organization?.slug}
138+
cloudProvider={project?.cloud_provider}
139+
computeSize={project?.infra_compute_size}
142140
/>
143141
)}
144142
</div>

apps/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CardButton from 'components/ui/CardButton'
55
import { ComputeBadgeWrapper } from 'components/ui/ComputeBadgeWrapper'
66
import type { IntegrationProjectConnection } from 'data/integrations/integrations.types'
77
import { ProjectIndexPageLink } from 'data/prefetchers/project.$ref'
8-
import { OrgProject } from 'data/projects/org-projects-infinite-query'
8+
import { getComputeSize, OrgProject } from 'data/projects/org-projects-infinite-query'
99
import type { ResourceWarning } from 'data/usage/resource-warnings-query'
1010
import { useCustomContent } from 'hooks/custom-content/useCustomContent'
1111
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
@@ -14,6 +14,7 @@ import { inferProjectStatus } from './ProjectCard.utils'
1414
import { ProjectCardStatus } from './ProjectCardStatus'
1515

1616
export interface ProjectCardProps {
17+
slug?: string
1718
project: OrgProject
1819
rewriteHref?: string
1920
githubIntegration?: IntegrationProjectConnection
@@ -22,6 +23,7 @@ export interface ProjectCardProps {
2223
}
2324

2425
export const ProjectCard = ({
26+
slug,
2527
project,
2628
rewriteHref,
2729
githubIntegration,
@@ -56,7 +58,12 @@ export const ProjectCard = ({
5658
<span className="text-sm text-foreground-light">{desc}</span>
5759
<div className="flex items-center gap-x-1.5">
5860
{project.status !== 'INACTIVE' && projectHomepageShowInstanceSize && (
59-
<ComputeBadgeWrapper project={project} />
61+
<ComputeBadgeWrapper
62+
slug={slug}
63+
projectRef={project.ref}
64+
cloudProvider={project.cloud_provider}
65+
computeSize={getComputeSize(project)}
66+
/>
6067
)}
6168
{isVercelIntegrated && (
6269
<div className="w-fit p-1 border rounded-md flex items-center text-black dark:text-white">

apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export const ProjectList = ({ organization: organization_, rewriteHref }: Projec
241241
{sortedProjects?.map((project) => (
242242
<ProjectCard
243243
key={project.ref}
244+
slug={slug}
244245
project={project}
245246
rewriteHref={rewriteHref ? rewriteHref(project.ref) : undefined}
246247
resourceWarnings={resourceWarnings?.find(

apps/studio/components/interfaces/Home/ProjectList/ProjectTableRow.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import InlineSVG from 'react-inlinesvg'
44

55
import { ComputeBadgeWrapper } from 'components/ui/ComputeBadgeWrapper'
66
import type { IntegrationProjectConnection } from 'data/integrations/integrations.types'
7-
import { OrgProject } from 'data/projects/org-projects-infinite-query'
7+
import { getComputeSize, OrgProject } from 'data/projects/org-projects-infinite-query'
88
import type { ResourceWarning } from 'data/usage/resource-warnings-query'
99
import { BASE_PATH } from 'lib/constants'
1010
import { Organization } from 'types'
@@ -96,12 +96,10 @@ export const ProjectTableRow = ({
9696
<div className="w-fit">
9797
{project.status !== 'INACTIVE' ? (
9898
<ComputeBadgeWrapper
99-
project={{
100-
ref: project.ref,
101-
organization_slug: organization?.slug,
102-
cloud_provider: infraInformation?.cloud_provider,
103-
infra_compute_size: infraInformation?.infra_compute_size,
104-
}}
99+
slug={organization?.slug}
100+
projectRef={project.ref}
101+
cloudProvider={project.cloud_provider}
102+
computeSize={getComputeSize(project)}
105103
/>
106104
) : (
107105
<span className="text-xs text-foreground-light">-</span>

apps/studio/components/interfaces/HomeNew/TopSection.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { ComputeBadgeWrapper } from 'components/ui/ComputeBadgeWrapper'
77
import { InlineLink } from 'components/ui/InlineLink'
88
import { ProjectUpgradeFailedBanner } from 'components/ui/ProjectUpgradeFailedBanner'
99
import { useBranchesQuery } from 'data/branches/branches-query'
10+
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
1011
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
1112
import { useIsOrioleDb, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
1213
import { DOCS_URL, PROJECT_STATUS } from 'lib/constants'
1314
import { Badge, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
1415
import { InstanceConfiguration } from '../Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration'
15-
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
1616

1717
export const TopSection = () => {
1818
const isOrioleDb = useIsOrioleDb()
@@ -85,12 +85,10 @@ export const TopSection = () => {
8585
</Tooltip>
8686
)}
8787
<ComputeBadgeWrapper
88-
project={{
89-
ref: project?.ref,
90-
organization_slug: organization?.slug,
91-
cloud_provider: project?.cloud_provider,
92-
infra_compute_size: project?.infra_compute_size,
93-
}}
88+
projectRef={project?.ref}
89+
slug={organization?.slug}
90+
cloudProvider={project?.cloud_provider}
91+
computeSize={project?.infra_compute_size}
9492
/>
9593
</div>
9694
</div>

apps/studio/components/ui/ComputeBadgeWrapper.tsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Link from 'next/link'
22
import { useState } from 'react'
33

44
import { getAddons } from 'components/interfaces/Billing/Subscription/Subscription.utils'
5-
import { InfraInstanceSize } from 'components/interfaces/DiskManagement/DiskManagement.types'
5+
import { ProjectDetail } from 'data/projects/project-detail-query'
66
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
77
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
88
import { ProjectAddonVariantMeta } from 'data/subscriptions/types'
@@ -22,27 +22,28 @@ const Row = ({ label, stat }: { label: string; stat: React.ReactNode | string })
2222
}
2323

2424
interface ComputeBadgeWrapperProps {
25-
project: {
26-
ref?: string
27-
organization_slug?: string
28-
cloud_provider?: string
29-
infra_compute_size?: InfraInstanceSize
30-
}
25+
slug?: string
26+
projectRef?: string
27+
cloudProvider?: string
28+
computeSize?: ProjectDetail['infra_compute_size']
3129
}
3230

33-
export const ComputeBadgeWrapper = ({ project }: ComputeBadgeWrapperProps) => {
31+
export const ComputeBadgeWrapper = ({
32+
slug,
33+
projectRef,
34+
cloudProvider,
35+
computeSize,
36+
}: ComputeBadgeWrapperProps) => {
3437
// handles the state of the hover card
3538
// once open it will fetch the addons
3639
const [open, setOpenState] = useState(false)
3740

3841
// returns hardcoded values for infra
39-
const cpuArchitecture = getCloudProviderArchitecture(project.cloud_provider)
42+
const cpuArchitecture = getCloudProviderArchitecture(cloudProvider)
4043

4144
// fetches addons
4245
const { data: addons, isLoading: isLoadingAddons } = useProjectAddonsQuery(
43-
{
44-
projectRef: project.ref,
45-
},
46+
{ projectRef },
4647
{ enabled: open }
4748
)
4849
const selectedAddons = addons?.selected_addons ?? []
@@ -51,7 +52,7 @@ export const ComputeBadgeWrapper = ({ project }: ComputeBadgeWrapperProps) => {
5152
const computeInstanceMeta = computeInstance?.variant?.meta
5253

5354
const meta = (
54-
computeInstanceMeta === undefined && project.infra_compute_size === 'micro'
55+
computeInstanceMeta === undefined && computeSize === 'micro'
5556
? INSTANCE_MICRO_SPECS
5657
: computeInstanceMeta
5758
) as ProjectAddonVariantMeta
@@ -62,26 +63,24 @@ export const ComputeBadgeWrapper = ({ project }: ComputeBadgeWrapperProps) => {
6263

6364
const highestComputeAvailable = availableCompute?.[availableCompute.length - 1].identifier
6465

65-
const isHighestCompute =
66-
project?.infra_compute_size === highestComputeAvailable?.replace('ci_', '')
66+
const isHighestCompute = computeSize === highestComputeAvailable?.replace('ci_', '')
6767

6868
const { data, isLoading: isLoadingSubscriptions } = useOrgSubscriptionQuery(
69-
{ orgSlug: project?.organization_slug },
69+
{ orgSlug: slug },
7070
{ enabled: open }
7171
)
7272

73-
const isEligibleForFreeUpgrade =
74-
data?.plan.id !== 'free' && project?.infra_compute_size === 'nano'
73+
const isEligibleForFreeUpgrade = data?.plan.id !== 'free' && computeSize === 'nano'
7574

7675
const isLoading = isLoadingAddons || isLoadingSubscriptions
7776

78-
if (!project?.infra_compute_size) return null
77+
if (!computeSize) return null
7978

8079
return (
8180
<HoverCard onOpenChange={() => setOpenState(!open)} openDelay={280}>
8281
<HoverCardTrigger asChild className="group" onClick={(e) => e.stopPropagation()}>
8382
<div>
84-
<ComputeBadge infraComputeSize={project.infra_compute_size} />
83+
<ComputeBadge infraComputeSize={computeSize} />
8584
</div>
8685
</HoverCardTrigger>
8786
<HoverCardContent
@@ -94,7 +93,7 @@ export const ComputeBadgeWrapper = ({ project }: ComputeBadgeWrapperProps) => {
9493
<Separator />
9594
<div className="p-3 px-5 flex flex-row gap-4">
9695
<div>
97-
<ComputeBadge infraComputeSize={project?.infra_compute_size} />
96+
<ComputeBadge infraComputeSize={computeSize} />
9897
</div>
9998
<div className="flex flex-col gap-4">
10099
{isLoading ? (
@@ -145,7 +144,7 @@ export const ComputeBadgeWrapper = ({ project }: ComputeBadgeWrapperProps) => {
145144
</div>
146145
<div>
147146
<Button asChild type="default" htmlType="button" role="button">
148-
<Link href={`/project/${project?.ref}/settings/compute-and-disk`}>
147+
<Link href={`/project/${projectRef}/settings/compute-and-disk`}>
149148
Upgrade compute
150149
</Link>
151150
</Button>

0 commit comments

Comments
 (0)