Repository navigation
chore(billing): show hints on aws mp onboarding page in case… - #41542
Conversation
… contract cannot be linked
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
WalkthroughAdds a contract-linking eligibility API, query hook, and cache key; introduces AwsMarketplaceContractNotLinkable component; refactors onboarding components to fetch onboarding info internally; and updates the AWS Marketplace onboarding page to branch rendering based on contract eligibility and organizations. Changes
Sequence DiagramsequenceDiagram
participant Page as Onboarding Page
participant HookElig as Contract Eligibility Hook
participant HookOrgs as Organizations Hook
participant API as Cloud Marketplace API
participant UI as UI Components
Page->>HookElig: useCloudMarketplaceContractLinkingEligibilityQuery(buyerId)
activate HookElig
HookElig->>API: GET /contract-linking-eligibility
API-->>HookElig: eligibility data
deactivate HookElig
HookElig-->>Page: data, isFetched
Page->>HookOrgs: useOrganizationsQuery()
activate HookOrgs
HookOrgs->>API: GET /organizations
API-->>HookOrgs: organizations
deactivate HookOrgs
HookOrgs-->>Page: data, isFetched
alt Loading
Page->>UI: render AwsMarketplaceOnboardingPlaceholder
else Not Eligible
Page->>UI: render AwsMarketplaceContractNotLinkable(reason)
else Eligible
Page->>UI: if organizations exist?
alt Has Organizations
UI->>UI: render AwsMarketplaceLinkExistingOrg(organizations)
else No Organizations
UI->>UI: render AwsMarketplaceCreateNewOrg()
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🎭 Playwright Test ResultsDetails
Skipped testsFeatures › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (6)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (1)
50-62: Optional chaining recommended for safer property access.While the previous comment addresses the main loading/error handling, this specific section accesses
onboardingInfoproperties. Once proper loading/error handling is added, consider using optional chaining for additional safety.{onboardingInfo && !onboardingInfo.aws_contract_auto_renewal && !onboardingInfo.aws_contract_is_private_offer && ( <AwsMarketplaceAutoRenewalWarning awsContractEndDate={onboardingInfo.aws_contract_end_date} awsContractSettingsUrl={onboardingInfo.aws_contract_settings_url} /> )} <ScaffoldSection> <ScaffoldSectionDetail className="text-base"> <p> - You've subscribed to the Supabase {onboardingInfo?.plan_name_selected_on_marketplace}{' '} + You've subscribed to the Supabase {onboardingInfo.plan_name_selected_on_marketplace}{' '} Plan via the AWS Marketplace. As a final step, you need to create a SupabaseNote: With proper early returns for undefined states, the optional chaining on line 61 becomes unnecessary.
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (1)
20-80: Consider extracting content components for better maintainability.The
determineCardContentfunction contains substantial JSX for each case. Consider extracting each case into its own component to improve readability and testability.🔎 Example refactor with extracted components
const NoActiveContractContent = () => ( <p> Thanks for purchasing Supabase through the AWS Marketplace. It'll take a moment for all systems to sync before you can link your Supabase organization to the AWS Marketplace. Please try again in a few minutes. </p> ) const AwsActivateCreditsContent = () => ( <> <p className="mb-4"> You've accepted a private offer for Supabase credits as part of AWS Activate. No further action is required on your end. </p> <p> Your Supabase organization's credit balance will be updated accordingly. Please note that it may take 1 or 2 days for this change to appear on the Dashboard. You can find the credit balance on the{' '} <Link className="underline" href={'/org/_/billing'}> organization's billing page </Link> . </p> <Button type="primary" size="medium" className="mt-8"> <Link href="/organizations">Go to Dashboard</Link> </Button> </> ) // Similar for other cases... function determineCardContent( reason: CloudMarketplaceContractLinkingEligibility['eligibility']['reasons'][0] ) { switch (reason) { case 'NO_ACTIVE_CONTRACT_FOUND': return <NoActiveContractContent /> case 'AWS_ACTIVATE_CREDITS_DEAL': return <AwsActivateCreditsContent /> case 'AGREEMENT_BASED_OFFER': return <AgreementBasedOfferContent /> default: return <DefaultContent /> } }This improves:
- Component testability (each content block can be tested independently)
- Readability (switch statement becomes more concise)
- Maintainability (easier to modify individual content blocks)
As per coding guidelines: "Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections".
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx (2)
55-58: Avoid type castingbuyerId as string; use the hook'senabledoption instead.The router query
buyer_idcan bestring | string[] | undefined. Casting directly tostringbypasses type safety. Consider validating and gating the query:Proposed fix
+ const validBuyerId = typeof buyerId === 'string' ? buyerId : undefined + const { data: onboardingInfo, isPending: isLoadingOnboardingInfo } = useCloudMarketplaceOnboardingInfoQuery({ - buyerId: buyerId as string, + buyerId: validBuyerId ?? '', + }, + { + enabled: !!validBuyerId, })As per coding guidelines, avoid type casting and validate values at runtime.
116-118: Same type casting issue withbuyerId.This repeats the
buyerId as stringcast. If you adopt the suggestedvalidBuyerIdvariable above, reuse it here.Proposed fix
const onSubmit: SubmitHandler<LinkExistingOrgForm> = async (values) => { - linkOrganization({ slug: values.orgSlug, buyerId: buyerId as string }) + linkOrganization({ slug: values.orgSlug, buyerId: validBuyerId! }) }Alternatively, add an early guard or disable the submit button when
validBuyerIdis falsy.apps/studio/pages/aws-marketplace-onboarding.tsx (2)
24-27: Avoid type castingbuyerId as string.Same issue as in
AwsMarketplaceLinkExistingOrg.tsx. Validate the router query parameter and gate the query appropriately.Proposed fix
+ const validBuyerId = typeof buyerId === 'string' ? buyerId : undefined + const { data: contractLinkingEligibility, isFetched: isContractLinkingEligibilityFetched } = useCloudMarketplaceContractLinkingEligibilityQuery({ - buyerId: buyerId as string, + buyerId: validBuyerId ?? '', + }, + { + enabled: !!validBuyerId, })
35-46: Consider using early returns to avoid nested ternaries.The nested ternaries are readable due to comments, but could be simplified with early returns for clearer control flow.
Suggested refactor using early returns
const AwsMarketplaceOnboarding: NextPageWithLayout = () => { // ... hooks ... + const renderContent = () => { + if (!isOrganizationsFetched || !isContractLinkingEligibilityFetched) { + return <AwsMarketplaceOnboardingPlaceholder /> + } + + if (!contractLinkingEligibility.eligibility.is_eligible) { + return <AwsMarketplaceContractNotLinkable eligibility={contractLinkingEligibility} /> + } + + if (organizations?.length) { + return <AwsMarketplaceLinkExistingOrg organizations={organizations} /> + } + + return <AwsMarketplaceCreateNewOrg /> + } + return ( <ScaffoldContainer> <ScaffoldHeader> <ScaffoldTitle>AWS Marketplace Setup</ScaffoldTitle> </ScaffoldHeader> <ScaffoldDivider /> - {!isOrganizationsFetched || !isContractLinkingEligibilityFetched ? ( - <AwsMarketplaceOnboardingPlaceholder /> - ) : !contractLinkingEligibility.eligibility.is_eligible ? ( - <AwsMarketplaceContractNotLinkable eligibility={contractLinkingEligibility} /> - ) : organizations?.length ? ( - <AwsMarketplaceLinkExistingOrg organizations={organizations} /> - ) : ( - <AwsMarketplaceCreateNewOrg /> - )} + {renderContent()} </ScaffoldContainer> ) }As per coding guidelines, use early returns for multiple conditions.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.tsapps/studio/components/interfaces/Organization/CloudMarketplace/keys.tsapps/studio/pages/aws-marketplace-onboarding.tsxpackages/api-types/types/platform.d.ts
🧰 Additional context used
📓 Path-based instructions (2)
apps/studio/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.{ts,tsx}: Assign complex conditions to descriptive variables instead of using multiple conditions in a single expression
Use consistent naming conventions for boolean variables:isprefix for state/identity,hasprefix for possession,canprefix for capability/permission,shouldprefix for conditional behavior
Derive boolean state from existing state instead of storing it separately
Use early returns for guard clauses instead of deeply nested conditionals
Extract complex logic into custom hooks when logic becomes reusable or complex
Return objects from custom hooks instead of arrays for better extensibility and clearer API
Use discriminated unions for complex state management instead of multiple independent state fields
Avoid type casting (e.g.,as any,as Type); instead validate values at runtime using zod schemas
Files:
apps/studio/components/interfaces/Organization/CloudMarketplace/keys.tsapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.tsapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
apps/studio/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.tsx: Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Extract repeated JSX patterns into reusable components instead of copying similar JSX blocks
Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Keep state as local as possible and only lift up when needed
Group related state using objects or reducers instead of multiple useState calls, preferring react-hook-form for form state management
Name event handlers consistently: useonprefix for prop callbacks andhandleprefix for internal handlers
Avoid inline arrow functions for expensive operations; use useCallback to maintain stable function references
Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Avoid nested ternaries in JSX; use separate conditions or early returns instead
Use useMemo for expensive computations when the computation is genuinely expensive and the value is passed to memoized children
Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
🧠 Learnings (3)
📚 Learning: 2025-12-12T05:20:17.409Z
Learnt from: joshenlim
Repo: supabase/supabase PR: 41258
File: apps/studio/pages/project/[ref]/storage/vectors/buckets/[bucketId].tsx:9-9
Timestamp: 2025-12-12T05:20:17.409Z
Learning: In apps/studio/**/*.{ts,tsx}, use named imports for DefaultLayout: import { DefaultLayout } from 'components/layouts/DefaultLayout' instead of default import. This is the new practice being adopted across the studio app.
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/keys.tsapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.tsapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : Build forms with react-hook-form and zod for validation
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx
📚 Learning: 2025-12-12T11:27:51.417Z
Learnt from: ignaciodob
Repo: supabase/supabase PR: 41291
File: packages/api-types/types/platform.d.ts:7128-7128
Timestamp: 2025-12-12T11:27:51.417Z
Learning: For changes tied to entitlements (e.g., adding a new entitlement like 'security.questionnaire'), do not merge until backend entitlements are confirmed live. Apply a do-not-merge label on such PRs and ensure UI changes that rely on new entitlements are not merged in isolation. In reviews, verify entitlement availability in backend before approving and, if needed, hold UI-only changes until entitlement is active.
Applied to files:
packages/api-types/types/platform.d.ts
🧬 Code graph analysis (5)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (3)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
CloudMarketplaceContractLinkingEligibility(75-77)packages/ui/src/components/shadcn/ui/card.tsx (1)
CardContent(70-70)apps/studio/components/interfaces/Support/SupportLink.tsx (1)
SupportLink(7-28)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (3)
apps/studio/data/fetchers.ts (1)
handleError(146-184)apps/studio/lib/profile.tsx (1)
useProfile(123-123)apps/studio/components/interfaces/Organization/CloudMarketplace/keys.ts (1)
cloudMarketplaceKeys(1-8)
apps/studio/pages/aws-marketplace-onboarding.tsx (2)
apps/studio/data/organizations/organizations-query.ts (1)
useOrganizationsQuery(52-64)apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx (1)
AwsMarketplaceLinkExistingOrg(47-320)
packages/api-types/types/platform.d.ts (1)
packages/api-types/types/api.d.ts (1)
components(1913-4649)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (1)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
useCloudMarketplaceOnboardingInfoQuery(33-52)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test (1)
- GitHub Check: typecheck
🔇 Additional comments (6)
apps/studio/components/interfaces/Organization/CloudMarketplace/keys.ts (1)
3-7: LGTM!The new
contractLinkingEligibilitykey resolver follows the established pattern and correctly returns a query key array for contract linking eligibility queries.apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (1)
15-15: Import added for new hook-based data fetching.The component now imports
useCloudMarketplaceOnboardingInfoQueryto fetch onboarding data internally instead of receiving it via props. This change aligns with the refactoring to make components self-contained.packages/api-types/types/platform.d.ts (2)
4632-4642: Schema structure aligns with requirements.The response schema correctly represents the eligibility response with optional
aws_agreement_id, a booleanis_eligibleflag, and the three ineligibility reasons. Structure is consistent with the operation definition and matches the API contract from the backend.
11155-11182: Operation definition structure is correct.The operation correctly defines
buyer_idas a path parameter and both response statuses (200 and 500) with appropriate descriptions. However, verify that this operation definition is compatible with the path-level parameter declaration once Hunk 1 is corrected.apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (2)
54-78: LGTM!The new types and fetch function follow the established pattern in this file. Error handling via
handleErroris consistent with the existing implementation.
80-105: LGTM!The hook follows the same pattern as
useCloudMarketplaceOnboardingInfoQuery. The shorterstaleTime(1 minute vs 30 minutes) is appropriate since eligibility status may change more frequently than onboarding info.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (1)
10-18: Add bounds check before accessing array element.Line 14 accesses
eligibility.eligibility.reasons[0]without verifying the array exists or has elements. This will cause a runtime error if thereasonsarray is empty or undefined.🔎 Proposed fix with bounds check and fallback
const AwsMarketplaceContractNotLinkable = ({ eligibility }: Props) => { + const reason = eligibility?.eligibility?.reasons?.[0] + return ( <div className="mt-5 mb-10"> <Card className="p-4"> - <CardContent>{determineCardContent(eligibility.eligibility.reasons[0])}</CardContent> + <CardContent>{determineCardContent(reason)}</CardContent> </Card> </div> ) }Then update
determineCardContentto handleundefined:function determineCardContent( - reason: CloudMarketplaceContractLinkingEligibility['eligibility']['reasons'][0] + reason: CloudMarketplaceContractLinkingEligibility['eligibility']['reasons'][0] | undefined ) { switch (reason) { case 'NO_ACTIVE_CONTRACT_FOUND': // ... existing cases ... + case undefined: default: return ( <p> Unable to determine the reason why AWS Marketplace onboarding is not possible.{' '} <SupportLink className="underline">Contact support.</SupportLink> </p> ) } }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/pages/aws-marketplace-onboarding.tsx
🧰 Additional context used
📓 Path-based instructions (2)
apps/studio/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.{ts,tsx}: Assign complex conditions to descriptive variables instead of using multiple conditions in a single expression
Use consistent naming conventions for boolean variables:isprefix for state/identity,hasprefix for possession,canprefix for capability/permission,shouldprefix for conditional behavior
Derive boolean state from existing state instead of storing it separately
Use early returns for guard clauses instead of deeply nested conditionals
Extract complex logic into custom hooks when logic becomes reusable or complex
Return objects from custom hooks instead of arrays for better extensibility and clearer API
Use discriminated unions for complex state management instead of multiple independent state fields
Avoid type casting (e.g.,as any,as Type); instead validate values at runtime using zod schemas
Files:
apps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
apps/studio/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.tsx: Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Extract repeated JSX patterns into reusable components instead of copying similar JSX blocks
Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Keep state as local as possible and only lift up when needed
Group related state using objects or reducers instead of multiple useState calls, preferring react-hook-form for form state management
Name event handlers consistently: useonprefix for prop callbacks andhandleprefix for internal handlers
Avoid inline arrow functions for expensive operations; use useCallback to maintain stable function references
Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Avoid nested ternaries in JSX; use separate conditions or early returns instead
Use useMemo for expensive computations when the computation is genuinely expensive and the value is passed to memoized children
Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Files:
apps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
🧠 Learnings (9)
📚 Learning: 2025-12-12T05:20:17.409Z
Learnt from: joshenlim
Repo: supabase/supabase PR: 41258
File: apps/studio/pages/project/[ref]/storage/vectors/buckets/[bucketId].tsx:9-9
Timestamp: 2025-12-12T05:20:17.409Z
Learning: In apps/studio/**/*.{ts,tsx}, use named imports for DefaultLayout: import { DefaultLayout } from 'components/layouts/DefaultLayout' instead of default import. This is the new practice being adopted across the studio app.
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : Do not introduce new UI components unless asked to; check packages/ui/index.tsx for available components before composing interfaces
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : Use CardContent for card sections, and CardFooter for actions within cards
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/interfaces/**/*.{ts,tsx} : Create a new component in apps/studio/components/interfaces for the contents of each new page
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Avoid nested ternaries in JSX; use separate conditions or early returns instead
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : When submit button is outside the form, add a formId variable outside the component, set it as id on form element and form prop on the button
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Use _Shadcn_ suffixed components (e.g., Input_Shadcn_, Button_Shadcn_) from the ui package where possible
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
🧬 Code graph analysis (2)
apps/studio/pages/aws-marketplace-onboarding.tsx (1)
apps/studio/data/organizations/organizations-query.ts (1)
useOrganizationsQuery(52-64)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (3)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
CloudMarketplaceContractLinkingEligibility(75-77)packages/ui/src/components/shadcn/ui/card.tsx (1)
CardContent(70-70)apps/studio/components/interfaces/Support/SupportLink.tsx (1)
SupportLink(7-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test
- GitHub Check: test (1)
- GitHub Check: typecheck
🔇 Additional comments (2)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (1)
20-80: Well-structured helper function with clear user messaging.The
determineCardContentfunction handles each eligibility reason appropriately with helpful user-facing messages. The switch statement is clean and each case provides clear guidance on next steps.apps/studio/pages/aws-marketplace-onboarding.tsx (1)
23-35: Good addition of success flags for both queries.Extracting both
isFetchedandisSuccessfrom each query allows proper handling of loading vs. error states. This addresses potential runtime errors from failed queries.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
apps/studio/pages/aws-marketplace-onboarding.tsx (1)
43-62: Refactor nested ternaries to follow coding guidelines.This rendering logic violates the coding guideline: "Avoid nested ternaries in JSX; use separate conditions or early returns instead." The three-level nesting (lines 48-60) makes the logic difficult to follow and maintain. Additionally, there's no explicit error state handling—when queries fail (
isFetchedis true butisSuccessis false), the expression evaluates to falsy and renders nothing, leaving users with a blank screen.Based on coding guidelines: Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions.
🔎 Proposed refactor with sequential conditions and error handling
return ( <ScaffoldContainer> <ScaffoldHeader> <ScaffoldTitle>AWS Marketplace Setup</ScaffoldTitle> </ScaffoldHeader> <ScaffoldDivider /> - {!isOrganizationsFetched || !isContractLinkingEligibilityFetched ? ( + {(() => { + // Loading state + if (!isOrganizationsFetched || !isContractLinkingEligibilityFetched) { + return <AwsMarketplaceOnboardingPlaceholder /> + } + + // Error state + if (!wasOrganizationsRequestSuccessful || !wasEligibilityRequestSuccessful) { + return ( + <div className="mt-5"> + <p className="text-foreground-light"> + Failed to load onboarding information. Please try again later or contact support. + </p> + </div> + ) + } + + // Contract not eligible + if (!contractLinkingEligibility?.eligibility.is_eligible) { + return ( + <AwsMarketplaceContractNotLinkable + reason={contractLinkingEligibility.eligibility.reasons[0]} + /> + ) + } + + // Contract eligible - check organizations + if (organizations?.length) { + return <AwsMarketplaceLinkExistingOrg organizations={organizations} /> + } + + // No organizations + return <AwsMarketplaceCreateNewOrg /> + })()} - <AwsMarketplaceOnboardingPlaceholder /> - ) : ( - wasOrganizationsRequestSuccessful && - wasEligibilityRequestSuccessful && - (contractLinkingEligibility.eligibility.is_eligible ? ( - // If the contract is linkable and there are existing organizations - organizations?.length ? ( - <AwsMarketplaceLinkExistingOrg organizations={organizations} /> - ) : ( - // If the contract is linkable and there are no existing organizations - <AwsMarketplaceCreateNewOrg /> - ) - ) : ( - // If the contract is not eligible for linking - <AwsMarketplaceContractNotLinkable - reason={contractLinkingEligibility.eligibility.reasons[0]} - /> - )) - )} </ScaffoldContainer> )This refactoring:
- Eliminates nested ternaries with sequential conditions
- Adds explicit error state handling
- Uses optional chaining for safety
- Makes the decision tree clear and maintainable
- Follows the consistent loading/error/success pattern guideline
🧹 Nitpick comments (1)
apps/studio/pages/aws-marketplace-onboarding.tsx (1)
46-47: Extract complex boolean condition into descriptive variables.The compound boolean expression spanning lines 46-47 should be assigned to descriptive variables for better readability.
Based on coding guidelines: Assign complex conditions to descriptive variables instead of using multiple conditions in a single expression.
🔎 Example with descriptive variables
+ const isDataReady = wasOrganizationsRequestSuccessful && wasEligibilityRequestSuccessful + const isContractEligible = contractLinkingEligibility?.eligibility.is_eligible + const hasExistingOrganizations = organizations && organizations.length > 0 + return ( <ScaffoldContainer> {/* ... */} - wasOrganizationsRequestSuccessful && - wasEligibilityRequestSuccessful && - (contractLinkingEligibility.eligibility.is_eligible ? ( + isDataReady && ( + isContractEligible ? (Note: This suggestion becomes unnecessary if you apply the essential refactor suggested in the previous comment.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.tsapps/studio/pages/aws-marketplace-onboarding.tsx
🧰 Additional context used
📓 Path-based instructions (2)
apps/studio/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.{ts,tsx}: Assign complex conditions to descriptive variables instead of using multiple conditions in a single expression
Use consistent naming conventions for boolean variables:isprefix for state/identity,hasprefix for possession,canprefix for capability/permission,shouldprefix for conditional behavior
Derive boolean state from existing state instead of storing it separately
Use early returns for guard clauses instead of deeply nested conditionals
Extract complex logic into custom hooks when logic becomes reusable or complex
Return objects from custom hooks instead of arrays for better extensibility and clearer API
Use discriminated unions for complex state management instead of multiple independent state fields
Avoid type casting (e.g.,as any,as Type); instead validate values at runtime using zod schemas
Files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts
apps/studio/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.tsx: Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Extract repeated JSX patterns into reusable components instead of copying similar JSX blocks
Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Keep state as local as possible and only lift up when needed
Group related state using objects or reducers instead of multiple useState calls, preferring react-hook-form for form state management
Name event handlers consistently: useonprefix for prop callbacks andhandleprefix for internal handlers
Avoid inline arrow functions for expensive operations; use useCallback to maintain stable function references
Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Avoid nested ternaries in JSX; use separate conditions or early returns instead
Use useMemo for expensive computations when the computation is genuinely expensive and the value is passed to memoized children
Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/pages/aws-marketplace-onboarding.tsx
🧠 Learnings (13)
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : Do not introduce new UI components unless asked to; check packages/ui/index.tsx for available components before composing interfaces
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Avoid nested ternaries in JSX; use separate conditions or early returns instead
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : When submit button is outside the form, add a formId variable outside the component, set it as id on form element and form prop on the button
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Use _Shadcn_ suffixed components (e.g., Input_Shadcn_, Button_Shadcn_) from the ui package where possible
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-12T05:20:17.409Z
Learnt from: joshenlim
Repo: supabase/supabase PR: 41258
File: apps/studio/pages/project/[ref]/storage/vectors/buckets/[bucketId].tsx:9-9
Timestamp: 2025-12-12T05:20:17.409Z
Learning: In apps/studio/**/*.{ts,tsx}, use named imports for DefaultLayout: import { DefaultLayout } from 'components/layouts/DefaultLayout' instead of default import. This is the new practice being adopted across the studio app.
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsxapps/studio/pages/aws-marketplace-onboarding.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Use early returns for guard clauses instead of deeply nested conditionals
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Extract complex logic into custom hooks when logic becomes reusable or complex
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Extract repeated JSX patterns into reusable components instead of copying similar JSX blocks
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Keep state as local as possible and only lift up when needed
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
🧬 Code graph analysis (3)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (3)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
CloudMarketplaceContractLinkingIneligibilityReason(78-79)packages/ui/src/components/shadcn/ui/card.tsx (1)
CardContent(70-70)apps/studio/components/interfaces/Support/SupportLink.tsx (1)
SupportLink(7-28)
apps/studio/pages/aws-marketplace-onboarding.tsx (1)
apps/studio/data/organizations/organizations-query.ts (1)
useOrganizationsQuery(52-64)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (2)
apps/studio/data/fetchers.ts (1)
handleError(146-184)apps/studio/lib/profile.tsx (1)
useProfile(123-123)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test
- GitHub Check: test (1)
- GitHub Check: typecheck
🔇 Additional comments (4)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceContractNotLinkable.tsx (3)
1-18: Component structure is clean and well-organized.The component correctly receives the
reasonprop (addressing the previous bounds check concern) and delegates content rendering to a helper function. The structure follows coding guidelines with explicit prop typing and no unnecessary complexity.
20-78: Content switching logic handles all known cases appropriately.The
determineCardContentfunction provides clear, user-friendly messaging for each ineligibility reason with appropriate CTAs. The default case provides a safe fallback with support contact, which is good defensive coding.
42-44: No action needed. The hardcoded/org/_/billingpath is the correct and intentional fallback route pattern used throughout the codebase when the organization slug is unavailable. This is confirmed by consistent usage across multiple components (e.g.,UpgradePlanButton.tsxuses${slug ?? '_'}/billing), explicit redirects innext.config.js, and documentation inprompts.ts. The underscore serves as the default segment when the actual organization slug is not accessible.apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
54-108: Well-structured implementation following established patterns.The contract linking eligibility query implementation correctly mirrors the onboarding info query pattern with proper error handling, profile-enabled gating, and type safety. The type extraction on lines 78-79 (
CloudMarketplaceContractLinkingIneligibilityReason) uses the standard TypeScript pattern to derive the array element type from the API response.Note: Line 106 sets
staleTime: 60 * 1000(60 seconds) compared to the onboarding info query's 30 minutes (line 50). This shorter cache duration is appropriate if contract eligibility changes more frequently than onboarding info.
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
apps/studio/pages/aws-marketplace-onboarding.tsx (1)
42-44: Consider a more descriptive error message.The current generic error message doesn't indicate which query failed or provide actionable guidance. Consider distinguishing between organizations query failure and eligibility query failure to help with debugging.
🔎 Example improvement
if (!wasOrganizationsRequestSuccessful || !wasEligibilityRequestSuccessful) { - return <p className="mt-4">Error loading AWS Marketplace setup page. Try again later.</p> + const failedResource = !wasOrganizationsRequestSuccessful + ? 'organizations' + : 'contract eligibility' + return ( + <p className="mt-4"> + Error loading {failedResource}. Please try again later or contact support if the issue persists. + </p> + ) }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/studio/pages/aws-marketplace-onboarding.tsx
🧰 Additional context used
📓 Path-based instructions (2)
apps/studio/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.{ts,tsx}: Assign complex conditions to descriptive variables instead of using multiple conditions in a single expression
Use consistent naming conventions for boolean variables:isprefix for state/identity,hasprefix for possession,canprefix for capability/permission,shouldprefix for conditional behavior
Derive boolean state from existing state instead of storing it separately
Use early returns for guard clauses instead of deeply nested conditionals
Extract complex logic into custom hooks when logic becomes reusable or complex
Return objects from custom hooks instead of arrays for better extensibility and clearer API
Use discriminated unions for complex state management instead of multiple independent state fields
Avoid type casting (e.g.,as any,as Type); instead validate values at runtime using zod schemas
Files:
apps/studio/pages/aws-marketplace-onboarding.tsx
apps/studio/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.tsx: Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Extract repeated JSX patterns into reusable components instead of copying similar JSX blocks
Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Keep state as local as possible and only lift up when needed
Group related state using objects or reducers instead of multiple useState calls, preferring react-hook-form for form state management
Name event handlers consistently: useonprefix for prop callbacks andhandleprefix for internal handlers
Avoid inline arrow functions for expensive operations; use useCallback to maintain stable function references
Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Avoid nested ternaries in JSX; use separate conditions or early returns instead
Use useMemo for expensive computations when the computation is genuinely expensive and the value is passed to memoized children
Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Files:
apps/studio/pages/aws-marketplace-onboarding.tsx
🧠 Learnings (6)
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Avoid nested ternaries in JSX; use separate conditions or early returns instead
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.{ts,tsx} : Use early returns for guard clauses instead of deeply nested conditionals
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
📚 Learning: 2025-12-12T05:20:17.409Z
Learnt from: joshenlim
Repo: supabase/supabase PR: 41258
File: apps/studio/pages/project/[ref]/storage/vectors/buckets/[bucketId].tsx:9-9
Timestamp: 2025-12-12T05:20:17.409Z
Learning: In apps/studio/**/*.{ts,tsx}, use named imports for DefaultLayout: import { DefaultLayout } from 'components/layouts/DefaultLayout' instead of default import. This is the new practice being adopted across the studio app.
Applied to files:
apps/studio/pages/aws-marketplace-onboarding.tsx
🧬 Code graph analysis (1)
apps/studio/pages/aws-marketplace-onboarding.tsx (3)
apps/studio/data/organizations/organizations-query.ts (1)
useOrganizationsQuery(52-64)apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx (1)
AwsMarketplaceLinkExistingOrg(47-320)apps/studio/components/layouts/Scaffold.tsx (1)
ScaffoldContainer(18-45)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test (1)
- GitHub Check: test
- GitHub Check: typecheck
🔇 Additional comments (2)
apps/studio/pages/aws-marketplace-onboarding.tsx (2)
15-16: LGTM: New imports for contract eligibility flow.The new imports are properly structured and necessary for the contract linking eligibility feature.
37-59: Well-structured rendering logic with clear separation.The
renderContenthelper function follows the recommended loading → error → success pattern from the coding guidelines, making the decision tree clear and sequential. This is a significant improvement over nested ternaries.As per coding guidelines: "Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state."
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (1)
46-48: Avoid type casting buyerId in the submit handler.The same type casting issue occurs here:
buyerId as stringis used without validation. Once you implement the validation suggested in the query call (lines 28-31), you should also guard this submit handler to ensure it only executes with a validbuyerId.🔎 Proposed fix
After implementing the validation from the previous suggestion, add an early return or disable the form when
buyerIdis invalid:const onSubmit: SubmitHandler<NewMarketplaceOrgForm> = async (values) => { + if (!isBuyerIdValid) { + toast.error('Invalid buyer ID') + return + } createOrganization({ ...values, buyerId: buyerId as string }) }Alternatively, disable form submission entirely when
buyerIdis invalid by passing a disabled prop to the form/button.As per coding guidelines.
♻️ Duplicate comments (1)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (1)
28-31: Add error handling and validate buyerId before type casting.The query call has several issues that violate coding guidelines:
- Type casting without validation:
buyerId as stringviolates the guideline "Avoid type casting; instead validate values at runtime using zod schemas". ThebuyerIdfrom router query can beundefined, an array, or an invalid string.- Missing error state handling: The query can fail, but
isErroranderrorare not destructured or handled, violating the guideline "handle loading state first with early returns, then error state, then empty state, then render success state".- Query should be conditionally enabled: The query executes unconditionally even with invalid
buyerId.🔎 Proposed fix with validation and error handling
- const { data: onboardingInfo, isPending: isLoadingOnboardingInfo } = - useCloudMarketplaceOnboardingInfoQuery({ - buyerId: buyerId as string, - }) + const isBuyerIdValid = typeof buyerId === 'string' && buyerId.length > 0 + + const { + data: onboardingInfo, + isPending: isLoadingOnboardingInfo, + isError, + error + } = useCloudMarketplaceOnboardingInfoQuery( + { + buyerId: buyerId as string, + }, + { + enabled: isBuyerIdValid, + } + )Then add error state handling after the loading check:
{isLoadingOnboardingInfo ? ( <AwsMarketplaceOnboardingPlaceholder /> + ) : isError ? ( + <div className="p-6"> + <p className="text-foreground-light"> + Failed to load onboarding information. Please try again. + </p> + </div> + ) : !onboardingInfo ? ( + <div className="p-6"> + <p className="text-foreground-light"> + No onboarding information available. + </p> + </div> ) : (As per coding guidelines and retrieved learnings.
🧹 Nitpick comments (1)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx (1)
131-303: Consider restructuring for early return pattern and component size.The component uses a ternary in JSX for loading state handling and is 325 lines, slightly exceeding the recommended 200-300 lines.
As per coding guidelines:
- "Use consistent loading/error/success pattern: handle loading state first with early returns"
- "Components should ideally be under 200-300 lines"
While the current implementation works, restructuring with an early return and extracting the form section into a sub-component would improve maintainability.
💡 Suggested refactoring approach
Option 1: Early return for loading state
Move the loading check higher in the component:
export const AwsMarketplaceLinkExistingOrg = ({ organizations, }: AwsMarketplaceLinkExistingOrgProps) => { // ... router, hooks, etc. if (isLoadingOnboardingInfo) { return <AwsMarketplaceOnboardingPlaceholder /> } return ( <> {onboardingInfo && ...} <ScaffoldSection> {/* main content */} </ScaffoldSection> {/* modals */} </> ) }Option 2: Extract form section to sub-component
Create a new component like
AwsMarketplaceOrgSelectionFormthat handles the form rendering and organization list, reducing the parent component's size.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx
🧰 Additional context used
📓 Path-based instructions (2)
apps/studio/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.{ts,tsx}: Assign complex conditions to descriptive variables instead of using multiple conditions in a single expression
Use consistent naming conventions for boolean variables:isprefix for state/identity,hasprefix for possession,canprefix for capability/permission,shouldprefix for conditional behavior
Derive boolean state from existing state instead of storing it separately
Use early returns for guard clauses instead of deeply nested conditionals
Extract complex logic into custom hooks when logic becomes reusable or complex
Return objects from custom hooks instead of arrays for better extensibility and clearer API
Use discriminated unions for complex state management instead of multiple independent state fields
Avoid type casting (e.g.,as any,as Type); instead validate values at runtime using zod schemas
Files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
apps/studio/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/studio-best-practices.mdc)
apps/studio/**/*.tsx: Components should ideally be under 200-300 lines; break down large components with multiple distinct UI sections, complex conditional rendering, or multiple unrelated useState hooks
Extract repeated JSX patterns into reusable components instead of copying similar JSX blocks
Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Keep state as local as possible and only lift up when needed
Group related state using objects or reducers instead of multiple useState calls, preferring react-hook-form for form state management
Name event handlers consistently: useonprefix for prop callbacks andhandleprefix for internal handlers
Avoid inline arrow functions for expensive operations; use useCallback to maintain stable function references
Use appropriate conditional rendering patterns: && for simple show/hide, ternary for binary choice, early returns or extracted components for multiple conditions
Avoid nested ternaries in JSX; use separate conditions or early returns instead
Use useMemo for expensive computations when the computation is genuinely expensive and the value is passed to memoized children
Define prop interfaces explicitly for React components with proper typing of props and callback handlers
Files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
🧠 Learnings (3)
📚 Learning: 2025-12-12T05:20:17.409Z
Learnt from: joshenlim
Repo: supabase/supabase PR: 41258
File: apps/studio/pages/project/[ref]/storage/vectors/buckets/[bucketId].tsx:9-9
Timestamp: 2025-12-12T05:20:17.409Z
Learning: In apps/studio/**/*.{ts,tsx}, use named imports for DefaultLayout: import { DefaultLayout } from 'components/layouts/DefaultLayout' instead of default import. This is the new practice being adopted across the studio app.
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsxapps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
📚 Learning: 2025-12-11T16:46:18.701Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-best-practices.mdc:0-0
Timestamp: 2025-12-11T16:46:18.701Z
Learning: Applies to apps/studio/**/*.tsx : Use consistent loading/error/success pattern: handle loading state first with early returns, then error state, then empty state, then render success state
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
📚 Learning: 2025-12-11T17:04:40.037Z
Learnt from: CR
Repo: supabase/supabase PR: 0
File: .cursor/rules/studio-ui.mdc:0-0
Timestamp: 2025-12-11T17:04:40.037Z
Learning: Applies to apps/studio/components/**/*.{ts,tsx} : Show loading states on submit buttons using the loading prop
Applied to files:
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
🧬 Code graph analysis (2)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx (5)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
useCloudMarketplaceOnboardingInfoQuery(33-52)apps/studio/components/layouts/Scaffold.tsx (3)
ScaffoldSection(86-101)ScaffoldSectionDetail(135-144)ScaffoldSectionContent(149-159)apps/studio/lib/constants/index.ts (1)
DOCS_URL(48-48)blocks/vue/registry/default/lib/utils.ts (1)
cn(5-7)apps/studio/components/interfaces/Organization/OrganizationCard.tsx (1)
OrganizationCard(11-67)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (3)
apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts (1)
useCloudMarketplaceOnboardingInfoQuery(33-52)apps/studio/components/layouts/Scaffold.tsx (3)
ScaffoldSection(86-101)ScaffoldSectionDetail(135-144)ScaffoldSectionContent(149-159)apps/studio/lib/constants/index.ts (1)
DOCS_URL(48-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test
- GitHub Check: test (1)
- GitHub Check: typecheck
🔇 Additional comments (1)
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx (1)
60-98: Rendering structure looks good, contingent on fixing the state handling.The loading state is now properly handled with the placeholder component, and the main content is well-structured using the Scaffold components. The button correctly shows the mutation loading state (line 89).
Once you implement the error and empty state handling suggested in the earlier comments, this rendering pattern will fully comply with the guideline: "handle loading state first with early returns, then error state, then empty state, then render success state."
Based on learnings.
| const { data: onboardingInfo, isPending: isLoadingOnboardingInfo } = | ||
| useCloudMarketplaceOnboardingInfoQuery({ | ||
| buyerId: buyerId as string, | ||
| }) |
There was a problem hiding this comment.
Validate buyerId at runtime instead of type casting.
The code casts buyerId to string without verifying it exists or is the correct type. Router query parameters can be string | string[] | undefined, so this risks passing invalid values to the query hook, potentially causing API errors.
As per coding guidelines, avoid type casting and validate values at runtime using Zod schemas.
🔎 Proposed fix with runtime validation
Add validation and an early return at the top of the component:
export const AwsMarketplaceLinkExistingOrg = ({
organizations,
}: AwsMarketplaceLinkExistingOrgProps) => {
const router = useRouter()
const {
query: { buyer_id: buyerId },
} = router
+
+ // Validate buyerId before using it
+ if (!buyerId || Array.isArray(buyerId)) {
+ return <div>Invalid buyer ID</div>
+ }
- const { data: onboardingInfo, isPending: isLoadingOnboardingInfo } =
- useCloudMarketplaceOnboardingInfoQuery({
- buyerId: buyerId as string,
- })
+ const { data: onboardingInfo, isPending: isLoadingOnboardingInfo } =
+ useCloudMarketplaceOnboardingInfoQuery({
+ buyerId,
+ })Then remove the other type casts on lines 118 and 316:
- linkOrganization({ slug: values.orgSlug, buyerId: buyerId as string })
+ linkOrganization({ slug: values.orgSlug, buyerId })- buyerId={buyerId as string}
+ buyerId={buyerId}Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx
around lines 56-59 (and also update uses at lines 118 and 316), the code
force-casts router buyerId to string when calling
useCloudMarketplaceOnboardingInfoQuery; validate buyerId at runtime instead: use
a Zod schema or simple runtime check to ensure buyerId is a single non-empty
string, return early (or render a fallback/error) if validation fails, and then
pass the validated string into the query hook; remove the other type casts at
lines 118 and 316 and use the validated value instead.
| onClick={async () => { | ||
| await onSubmit(form.getValues()) | ||
| }} | ||
| loading={isLinkingOrganization} | ||
| disabled={!isDirty || isLinkingOrganization || isLoadingOnboardingInfo} | ||
| tooltip={{ | ||
| content: { | ||
| side: 'top', | ||
| text: !isDirty ? 'No organization selected' : undefined, | ||
| }, |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
Extract complex disabled condition to a descriptive variable.
The button's disabled prop combines three boolean conditions, making it harder to understand the logic at a glance.
As per coding guidelines, assign complex conditions to descriptive variables instead of using multiple conditions in a single expression.
🔎 Proposed refactor
+ const canSubmitLinking = isDirty && !isLinkingOrganization && !isLoadingOnboardingInfo
<ButtonTooltip
size="medium"
htmlType="submit"
type="primary"
onClick={async () => {
await onSubmit(form.getValues())
}}
loading={isLinkingOrganization}
- disabled={!isDirty || isLinkingOrganization || isLoadingOnboardingInfo}
+ disabled={!canSubmitLinking}
tooltip={{
content: {
side: 'top',
text: !isDirty ? 'No organization selected' : undefined,
},
}}
>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| onClick={async () => { | |
| await onSubmit(form.getValues()) | |
| }} | |
| loading={isLinkingOrganization} | |
| disabled={!isDirty || isLinkingOrganization || isLoadingOnboardingInfo} | |
| tooltip={{ | |
| content: { | |
| side: 'top', | |
| text: !isDirty ? 'No organization selected' : undefined, | |
| }, | |
| const canSubmitLinking = isDirty && !isLinkingOrganization && !isLoadingOnboardingInfo | |
| <ButtonTooltip | |
| size="medium" | |
| htmlType="submit" | |
| type="primary" | |
| onClick={async () => { | |
| await onSubmit(form.getValues()) | |
| }} | |
| loading={isLinkingOrganization} | |
| disabled={!canSubmitLinking} | |
| tooltip={{ | |
| content: { | |
| side: 'top', | |
| text: !isDirty ? 'No organization selected' : undefined, | |
| }, |
🤖 Prompt for AI Agents
In
apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx
around lines 286 to 295, the button's disabled prop currently uses a compound
expression (!isDirty || isLinkingOrganization || isLoadingOnboardingInfo);
extract this combined condition into a clearly named boolean variable (e.g.,
const isButtonDisabled = !isDirty || isLinkingOrganization ||
isLoadingOnboardingInfo) declared near the component render so the JSX reads
disabled={isButtonDisabled}; ensure the tooltip logic still references isDirty
(or the appropriate negation) and update any related usages to use the new
variable for clarity and maintainability.
Braintrust eval report
|
Cannot be merged before https://github.com/supabase/platform/pull/28581 is on prod
With this PR we show proper hints on the AWS Marketplace onboarding page in case
Right now, it's possible for the customer to select an organization to link, only to see an error message after sending the request.
Non contract found

AWS Activate Credits Deal

Agreement Based Offer

Summary by CodeRabbit
New Features
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.