Repository navigation
Add read replicas details page from database replication - #41784
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
WalkthroughThis PR introduces a new read replica detail view with dedicated page and component, refactors read replica status handling into utility functions, converts a confirmation modal to named export, updates multiple log pages with identifier-based filtering, and makes minor cleanup changes across database replication UI. Changes
Sequence DiagramsequenceDiagram
participant User
participant Page as [replicaId] Page
participant ReplicaDetailsComp as ReadReplicaDetails
participant Query as useReadReplicas<br/>Queries
participant Modal as Confirmation<br/>Modals
User->>Page: Navigate to replica detail
Page->>Query: Fetch read replicas & statuses
Query-->>Page: Return replica data
Page->>Page: Compute status & polling strategy
Page->>ReplicaDetailsComp: Render with replica data
ReplicaDetailsComp->>ReplicaDetailsComp: Fetch lag & load balancer data
ReplicaDetailsComp-->>User: Display lag chart + metadata
User->>Page: Click restart/drop action
Page->>Modal: Open confirmation modal
Modal->>User: Request confirmation
User->>Modal: Confirm action
Modal->>Page: Trigger mutation & navigate
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In
@apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx:
- Around line 92-96: lagDuration can be undefined when the lag query is
disabled, causing ChartMetric to render "undefineds"; update the ChartMetric
value expression (where ChartMetric is rendered alongside
isLoading={isLoadingLag || isFetchingInfraMonitoring}) to render a safe
placeholder when lagDuration is null/undefined (e.g., lagDuration != null ?
`${lagDuration}s` : '—' or 'N/A') so the unit is only appended for numeric
values and a clear placeholder is shown when unavailable.
In @apps/studio/hooks/analytics/useLogsPreview.tsx:
- Line 82: Remove the debug console.log call that prints mergedFilters from the
useLogsPreview hook; locate the console.log({ mergedFilters }) inside the
useLogsPreview.tsx file (where mergedFilters is computed) and delete that
statement so the hook no longer logs to the browser console on re-renders.
In
@apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx:
- Around line 146-152: The href construction in the Button/Link block produces a
double question mark because it uses `?${!!identifier ? \`?db=\${identifier}\` :
''}`; update the Link href to only include a single `?` when identifier exists
(e.g., `href={\`/project/\${ref}/logs/postgres-logs\${identifier ?
\`?db=\${identifier}\` : ''}\`}`) or build query via URLSearchParams; adjust the
code around the Button, Link, identifier and ref usage so the final URL is
`/project/{ref}/logs/postgres-logs` or
`/project/{ref}/logs/postgres-logs?db={identifier}` without `??`.
🧹 Nitpick comments (9)
apps/studio/pages/project/[ref]/logs/edge-logs.tsx (1)
4-4: Use named import for DefaultLayout.Based on learnings, DefaultLayout should use a named import instead of a default import to align with the new practice being adopted across the studio app.
♻️ Proposed fix
-import DefaultLayout from 'components/layouts/DefaultLayout' +import { DefaultLayout } from 'components/layouts/DefaultLayout'apps/studio/pages/project/[ref]/logs/postgres-logs.tsx (1)
6-6: Use named import for DefaultLayout.Based on learnings, DefaultLayout should use a named import instead of a default import to align with the new practice being adopted across the studio app.
♻️ Proposed fix
-import DefaultLayout from 'components/layouts/DefaultLayout' +import { DefaultLayout } from 'components/layouts/DefaultLayout'apps/studio/pages/project/[ref]/logs/pooler-logs.tsx (1)
6-6: Use named import for DefaultLayout.Based on learnings, DefaultLayout should use a named import instead of a default import to align with the new practice being adopted across the studio app.
♻️ Proposed fix
-import DefaultLayout from 'components/layouts/DefaultLayout' +import { DefaultLayout } from 'components/layouts/DefaultLayout'apps/studio/pages/project/[ref]/logs/postgrest-logs.tsx (1)
7-7: Use named import for DefaultLayout.Based on learnings, DefaultLayout should use a named import instead of a default import to align with the new practice being adopted across the studio app.
♻️ Proposed fix
-import DefaultLayout from 'components/layouts/DefaultLayout' +import { DefaultLayout } from 'components/layouts/DefaultLayout'apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.ts (1)
11-22: Consider avoiding the type cast.Per coding guidelines, type casting (e.g.,
as string[]) should be avoided. You could define the array outside with explicit typing or use a const assertion to preserve the type.♻️ Suggested refactor
+const TRANSITION_STATUSES = [ + REPLICA_STATUS.UNKNOWN, + REPLICA_STATUS.COMING_UP, + REPLICA_STATUS.GOING_DOWN, + REPLICA_STATUS.RESTORING, + REPLICA_STATUS.RESTARTING, + REPLICA_STATUS.RESIZING, + REPLICA_STATUS.INIT_READ_REPLICA, +] as const + export const getIsInTransition = ({ initStatus, status, }: { initStatus?: string status?: string }) => { return ( - ( - [ - REPLICA_STATUS.UNKNOWN, - REPLICA_STATUS.COMING_UP, - REPLICA_STATUS.GOING_DOWN, - REPLICA_STATUS.RESTORING, - REPLICA_STATUS.RESTARTING, - REPLICA_STATUS.RESIZING, - REPLICA_STATUS.INIT_READ_REPLICA, - ] as string[] - ).includes(status ?? '') || initStatus === ReplicaInitializationStatus.InProgress + TRANSITION_STATUSES.includes(status as typeof TRANSITION_STATUSES[number]) || + initStatus === ReplicaInitializationStatus.InProgress ) }apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx (1)
45-47: Variable shadowing reduces readability.The inner callback parameter
xshadows the outerx, making the code harder to follow. Consider using distinct names.♻️ Suggested fix
- const loadBalancer = loadBalancers.find((x) => - x.databases.some((x) => x.identifier === identifier) + const loadBalancer = loadBalancers.find((lb) => + lb.databases.some((db) => db.identifier === identifier) )apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx (1)
153-160: UseREPLICA_STATUSconstants instead of string literals.For consistency and maintainability, use the imported
REPLICA_STATUS.ACTIVE_HEALTHYconstant instead of the string literal'ACTIVE_HEALTHY'.♻️ Suggested fix
<Button key="drop" type="default" - disabled={status !== 'ACTIVE_HEALTHY'} + disabled={status !== REPLICA_STATUS.ACTIVE_HEALTHY} onClick={() => setShowConfirmRestart(true)} > Restart replica </Button>,apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.tsx (2)
114-118: UseREPLICA_STATUS.GOING_DOWNconstant instead of string literal.For consistency with the imported constants, use
REPLICA_STATUS.GOING_DOWNinstead of the string literal'GOING_DOWN'.♻️ Suggested fix
- <Button asChild type="default" className="relative" disabled={status === 'GOING_DOWN'}> + <Button asChild type="default" className="relative" disabled={status === REPLICA_STATUS.GOING_DOWN}> <Link href={`/project/${ref}/database/replication/replica/${replica.identifier}`}> View replication </Link> </Button>
124-140: UseREPLICA_STATUSconstants for consistency.Replace string literals with the imported
REPLICA_STATUSconstants for both the restart and drop menu item disabled conditions.♻️ Suggested fix
<DropdownMenuItem className="gap-x-2" - disabled={status !== 'ACTIVE_HEALTHY'} + disabled={status !== REPLICA_STATUS.ACTIVE_HEALTHY} onClick={() => setShowConfirmRestart(true)} > <RotateCcw size={14} /> <span>Restart replica</span> </DropdownMenuItem> <DropdownMenuSeparator /> <DropdownMenuItem className="gap-x-2" - disabled={status === 'GOING_DOWN'} + disabled={status === REPLICA_STATUS.GOING_DOWN} onClick={() => setShowConfirmDrop(true)} >
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
apps/studio/components/interfaces/Database/Replication/Destinations.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.tsapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsxapps/studio/components/interfaces/Settings/Logs/Logs.utils.tsapps/studio/components/interfaces/Support/SupportFormPage.tsxapps/studio/components/layouts/PageLayout/PageHeader.tsxapps/studio/data/analytics/infra-monitoring-query.tsapps/studio/hooks/analytics/useLogsPreview.tsxapps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/pages/project/[ref]/logs/edge-logs.tsxapps/studio/pages/project/[ref]/logs/pooler-logs.tsxapps/studio/pages/project/[ref]/logs/postgres-logs.tsxapps/studio/pages/project/[ref]/logs/postgrest-logs.tsxapps/studio/pages/project/[ref]/observability/database.tsxpackages/ui-patterns/index.tsx
💤 Files with no reviewable changes (3)
- apps/studio/components/interfaces/Database/Replication/Destinations.tsx
- apps/studio/components/interfaces/Support/SupportFormPage.tsx
- apps/studio/pages/project/[ref]/observability/database.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/Settings/Logs/Logs.utils.tsapps/studio/hooks/analytics/useLogsPreview.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsxapps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/pages/project/[ref]/logs/edge-logs.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsxapps/studio/components/layouts/PageLayout/PageHeader.tsxapps/studio/pages/project/[ref]/logs/postgrest-logs.tsxapps/studio/data/analytics/infra-monitoring-query.tsapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsxapps/studio/pages/project/[ref]/logs/pooler-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.tsapps/studio/pages/project/[ref]/logs/postgres-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.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/hooks/analytics/useLogsPreview.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsxapps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/pages/project/[ref]/logs/edge-logs.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsxapps/studio/components/layouts/PageLayout/PageHeader.tsxapps/studio/pages/project/[ref]/logs/postgrest-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsxapps/studio/pages/project/[ref]/logs/pooler-logs.tsxapps/studio/pages/project/[ref]/logs/postgres-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.tsx
🧠 Learnings (15)
📚 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/Settings/Logs/Logs.utils.tsapps/studio/hooks/analytics/useLogsPreview.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsxapps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/pages/project/[ref]/logs/edge-logs.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsxapps/studio/components/layouts/PageLayout/PageHeader.tsxapps/studio/pages/project/[ref]/logs/postgrest-logs.tsxapps/studio/data/analytics/infra-monitoring-query.tsapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsxapps/studio/pages/project/[ref]/logs/pooler-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.tsapps/studio/pages/project/[ref]/logs/postgres-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.tsx
📚 Learning: 2026-01-02T05:58:55.226Z
Learnt from: meGauravJain
Repo: supabase/supabase PR: 41658
File: apps/studio/components/interfaces/Connect/content/prisma/content.tsx:70-85
Timestamp: 2026-01-02T05:58:55.226Z
Learning: In Prisma configuration or related connection setup code, prefer the environment variable name DIRECT_URL for direct/non-pooled database connections instead of DATABASE_URL_UNPOOLED, per Prisma documentation. Update code that reads database connection strings to use DIRECT_URL where applicable, and document why this is preferred (explicit, documented behavior). Ensure your environment provides DIRECT_URL when using direct connections and fallback handling if needed.
Applied to files:
apps/studio/components/interfaces/Settings/Logs/Logs.utils.tsapps/studio/hooks/analytics/useLogsPreview.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsxapps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/pages/project/[ref]/logs/edge-logs.tsxapps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsxapps/studio/components/layouts/PageLayout/PageHeader.tsxapps/studio/pages/project/[ref]/logs/postgrest-logs.tsxapps/studio/data/analytics/infra-monitoring-query.tsapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsxapps/studio/pages/project/[ref]/logs/pooler-logs.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.tsapps/studio/pages/project/[ref]/logs/postgres-logs.tsxpackages/ui-patterns/index.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.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} : Import primitive UI components from packages/ui package for use across apps, not from individual component files
Applied to files:
apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsxpackages/ui-patterns/index.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/pages/project/[ref]/database/replication/replica/[replicaId].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/pages/**/*.{ts,tsx} : When creating a new page, use the PageLayout component with appropriate props (title, subtitle, icon, breadcrumbs, primaryActions, secondaryActions, navigationItems, className, size, isCompact)
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/layouts/PageLayout/PageHeader.tsxapps/studio/pages/project/[ref]/logs/postgrest-logs.tsxapps/studio/pages/project/[ref]/logs/pooler-logs.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/pages/**/*.{ts,tsx} : Add table actions to primary and secondary actions of PageLayout if table is main content of a page without search or filters
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/layouts/PageLayout/PageHeader.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/pages/**/*.{ts,tsx} : Place pages in apps/studio/pages directory, with project-related pages in apps/studio/pages/projects/[ref] and organization-related pages in apps/studio/pages/org/[slug]
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].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/pages/**/*.{ts,tsx} : Use related layout components (e.g., AuthLayout) for pages within existing sections
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/layouts/PageLayout/PageHeader.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 ScaffoldSection, ScaffoldSectionTitle, and ScaffoldSectionDescription for pages with multiple sections
Applied to files:
apps/studio/components/layouts/PageLayout/PageHeader.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} : Place Admonition at the top of page contents (below page title) or at the top of the related ScaffoldSection below ScaffoldTitle
Applied to files:
apps/studio/components/layouts/PageLayout/PageHeader.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 SheetHeader, SheetTitle, SheetSection, and SheetFooter for consistent sheet structure
Applied to files:
apps/studio/components/layouts/PageLayout/PageHeader.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} : Only use CardHeader and CardTitle if card content has not been described by surrounding content, or when using multiple cards to group related pieces of content
Applied to files:
apps/studio/components/layouts/PageLayout/PageHeader.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} : Add table actions to the right of ScaffoldSectionTitle if table is main content of a page section without search or filters
Applied to files:
apps/studio/components/layouts/PageLayout/PageHeader.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 ScaffoldContainer for center-aligned page content in a container
Applied to files:
apps/studio/components/layouts/PageLayout/PageHeader.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} : Contain tables within a card
Applied to files:
apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
🧬 Code graph analysis (3)
apps/studio/pages/project/[ref]/logs/edge-logs.tsx (2)
apps/studio/pages/project/[ref]/logs/pooler-logs.tsx (1)
LogPage(12-29)apps/studio/pages/project/[ref]/logs/postgres-logs.tsx (1)
LogPage(10-23)
apps/studio/components/layouts/PageLayout/PageHeader.tsx (1)
apps/studio/components/layouts/Scaffold.tsx (2)
ScaffoldTitle(67-71)ScaffoldDescription(79-84)
apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.tsx (1)
apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.ts (2)
getIsInTransition(4-24)getStatusLabel(26-63)
⏰ 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). (1)
- GitHub Check: test
🔇 Additional comments (16)
apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts (1)
80-80: LGTM - Formatting improvement.The added whitespace improves readability by visually separating the variable declaration from the function definition below.
packages/ui-patterns/index.tsx (1)
11-11: LGTM - Public API expansion.The Chart export follows the established pattern of making ui-patterns components available for import. This supports the new read replica details page that displays replication lag graphs.
apps/studio/components/layouts/PageLayout/PageHeader.tsx (1)
114-123: LGTM - Enhanced flexibility for custom title/subtitle rendering.The conditional rendering based on type checks maintains backward compatibility for string titles/subtitles while enabling custom ReactNode content. This provides consumers with greater control over title and subtitle presentation when needed.
apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsx (1)
18-18: LGTM - Export pattern aligns with codebase standards.The switch from default to named export is consistent with the studio app's adoption of named exports for better refactorability and IDE support.
Based on learnings, named exports are the preferred pattern being adopted across the studio app.
apps/studio/data/analytics/infra-monitoring-query.ts (1)
4-4: LGTM! Infrastructure for read replicas monitoring.The addition of
UseCustomQueryOptionsimport and the newphysical_replication_lag_physical_replica_lag_secondsattribute properly support the read replicas replication lag monitoring feature introduced in this PR.Also applies to: 26-26
apps/studio/pages/project/[ref]/logs/edge-logs.tsx (1)
10-11: LGTM! Consistent identifier-based filtering.The implementation correctly extracts the database identifier from the query string and applies it as a filter override. This pattern is consistent across all log pages in this PR and enables filtering logs by specific database instances (e.g., read replicas).
Also applies to: 19-19
apps/studio/pages/project/[ref]/logs/postgres-logs.tsx (1)
11-12: LGTM! Consistent identifier-based filtering.The implementation correctly uses
useParamsanduseQueryStateto extract the database identifier and applies it as a filter override, enabling database-specific log filtering for features like read replicas.Also applies to: 20-20
apps/studio/pages/project/[ref]/logs/pooler-logs.tsx (1)
14-14: LGTM! Consistent identifier-based filtering.The identifier extraction and filterOverride implementation follows the same pattern as other log pages. The existing isLoading guard ensures the component waits for configuration before rendering with potential filters.
Also applies to: 26-26
apps/studio/pages/project/[ref]/logs/postgrest-logs.tsx (1)
12-13: LGTM! Consistent identifier-based filtering.The implementation correctly extracts the database identifier from the query string and applies it as a filter override. This enables filtering PostgREST logs by specific database instances, consistent with the pattern applied across all log pages in this PR.
Also applies to: 27-27
apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx (1)
39-39: LGTM!The import change to use named export aligns with the updated export pattern in
DropReplicaConfirmationModal.tsxand follows the project convention for named imports. Based on learnings, this is the new practice being adopted across the studio app.apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.ts (1)
26-63: LGTM!The
getStatusLabelfunction has clear priority-based logic with early returns for initialization states and a comprehensive switch statement for other statuses. Good fallback to 'Unhealthy' for edge cases.apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx (1)
76-88: Acknowledged: Mock data placeholder.The hardcoded chart data is documented with a Linear issue reference. Ensure the TODO is tracked for cleanup once the infra-monitoring endpoint is fixed.
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx (2)
61-85: LGTM!The polling logic appropriately stops refetching when all replicas reach a stable state. The pattern is consistent with
InstanceConfiguration.tsx.
180-184: LGTM!The layout composition follows project conventions with named import for
DefaultLayout. Based on learnings, this aligns with the new practice being adopted across the studio app.apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaRow.tsx (2)
61-65: LGTM!Good refactoring to use the shared utility functions. The
useMemousage ensures consistent computation when status changes.
1-27: LGTM!Import changes are clean: named export for
DropReplicaConfirmationModalaligns with project conventions, and the new utility imports support the refactored status logic.
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › sql-editor.spec.ts › SQL Editor › should check if SQL editor is working as expected Skipped testsFeatures › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (7)
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx (4)
45-52: Potential mismatch when replica is not found.When
replicais undefined (e.g., during initial load or if the replica doesn't exist),identifierwill be undefined. Thefindon line 50 will then search for a status withidentifier === undefined, which could lead to unexpected behavior.Consider using
replicaIddirectly for consistency:Suggested improvement
- const replicaStatus = statuses.find((x) => x.identifier === identifier) + const replicaStatus = statuses.find((x) => x.identifier === replicaId)
61-85: Unnecessary async function.The
pollReplicasfunction is declared asasyncbut contains noawaitexpressions. This adds unnecessary overhead.Simplify by removing async
useEffect(() => { if (!isSuccessReplicasStatuses) return - const pollReplicas = async () => { + const pollReplicas = () => { const fixedStatuses = [ REPLICA_STATUS.ACTIVE_HEALTHY, REPLICA_STATUS.ACTIVE_UNHEALTHY, REPLICA_STATUS.INIT_READ_REPLICA_FAILED, ] const replicasInTransition = statuses.filter((db) => { const { status } = db.replicaInitializationStatus || {} return ( !fixedStatuses.includes(db.status) || status === ReplicaInitializationStatus.InProgress ) }) const hasTransientStatus = replicasInTransition.length > 0 // If all replicas are active healthy, stop fetching statuses if (!hasTransientStatus && statuses.length === databases.length) { setStatusRefetchInterval(false) } } pollReplicas() }, [databases.length, isSuccessReplicasStatuses, statuses])
94-104: Consider extracting badge variant logic.Per coding guidelines, nested ternaries in JSX should be avoided. Extract the variant computation to a descriptive variable for clarity.
Extract to descriptive variable
+ const badgeVariant = statusLabel === 'Healthy' + ? 'success' + : statusLabel === 'Failed' + ? 'destructive' + : 'default' + // Then in JSX: <Badge - variant={ - statusLabel === 'Healthy' - ? 'success' - : statusLabel === 'Failed' - ? 'destructive' - : 'default' - } + variant={badgeVariant} >
153-160: Misleading key and inconsistent status check.
- The
key="drop"is misleading since this is the restart button.- The status comparison uses a string literal instead of the
REPLICA_STATUSconstant that's already imported and used elsewhere in this file.Fix key and use constant
<Button - key="drop" + key="restart" type="default" - disabled={status !== 'ACTIVE_HEALTHY'} + disabled={status !== REPLICA_STATUS.ACTIVE_HEALTHY} onClick={() => setShowConfirmRestart(true)} > Restart replica </Button>,apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx (3)
44-47: Shadowed variable name in nested callback.The variable
xis used in both the outer and inner callbacks, which can be confusing.Use distinct variable names
- const loadBalancer = loadBalancers.find((x) => - x.databases.some((x) => x.identifier === identifier) + const loadBalancer = loadBalancers.find((lb) => + lb.databases.some((db) => db.identifier === identifier) )
76-88: Temporary mock data is documented and tracked.The hardcoded random data is acknowledged in comments with a Linear ticket reference (INDATA-325). The
useMemowith empty dependencies ensures stable data per mount.Consider adding a
TODOcomment to make it more discoverable in code searches:Add TODO marker
- // [Joshen] Temporarily hardcoding the data as the query to retrieve replication lag doesn't seem to be working + // TODO: [Joshen] Temporarily hardcoding the data as the query to retrieve replication lag doesn't seem to be working // https://linear.app/supabase/issue/INDATA-325/investigate-infra-monitoring-for-physical-replication-lag-physical
31-42: Consider adding error state handling.The component handles loading states but doesn't explicitly handle error states from the queries. While the UI gracefully degrades with undefined values, consider adding explicit error handling for better UX.
For example, you could destructure
isErrorfrom the primary query and show an error message:const { data = [], isPending: isLoadingDatabases, isError } = useReadReplicasQuery({ projectRef }) // Then early return or conditional render for error state if (isError) { return <AlertError subject="Failed to load replica details" /> }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/studio/components/interfaces/Database/Replication/Destinations.tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsxapps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx
💤 Files with no reviewable changes (1)
- apps/studio/components/interfaces/Database/Replication/Destinations.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/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.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/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
🧠 Learnings (5)
📚 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/pages/project/[ref]/database/replication/replica/[replicaId].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/pages/**/*.{ts,tsx} : Add table actions to primary and secondary actions of PageLayout if table is main content of a page without search or filters
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].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/pages/**/*.{ts,tsx} : When creating a new page, use the PageLayout component with appropriate props (title, subtitle, icon, breadcrumbs, primaryActions, secondaryActions, navigationItems, className, size, isCompact)
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].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/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
📚 Learning: 2026-01-02T05:58:55.226Z
Learnt from: meGauravJain
Repo: supabase/supabase PR: 41658
File: apps/studio/components/interfaces/Connect/content/prisma/content.tsx:70-85
Timestamp: 2026-01-02T05:58:55.226Z
Learning: In Prisma configuration or related connection setup code, prefer the environment variable name DIRECT_URL for direct/non-pooled database connections instead of DATABASE_URL_UNPOOLED, per Prisma documentation. Update code that reads database connection strings to use DIRECT_URL where applicable, and document why this is preferred (explicit, documented behavior). Ensure your environment provides DIRECT_URL when using direct connections and fallback handling if needed.
Applied to files:
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsxapps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
🧬 Code graph analysis (1)
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx (6)
apps/studio/data/read-replicas/replicas-status-query.ts (1)
useReadReplicasStatusesQuery(44-57)apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicas.utils.ts (2)
getStatusLabel(26-63)getIsInTransition(4-24)apps/studio/components/layouts/Scaffold.tsx (2)
ScaffoldTitle(67-71)ScaffoldDescription(79-84)apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx (1)
ReadReplicaDetails(31-180)apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropReplicaConfirmationModal.tsx (1)
DropReplicaConfirmationModal(18-85)apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/RestartReplicaConfirmationModal.tsx (1)
RestartReplicaConfirmationModal(18-93)
⏰ 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: typecheck
- GitHub Check: test
- GitHub Check: test (1)
🔇 Additional comments (7)
apps/studio/pages/project/[ref]/database/replication/replica/[replicaId].tsx (4)
1-30: LGTM on imports!Good use of named imports for
DefaultLayoutas per the project convention. The imports are well-organized and follow the established patterns.
36-38: LGTM!State management is appropriately scoped. The modal visibility states are simple booleans, and the refetch interval state correctly controls polling behavior.
165-175: LGTM!Modal integration follows the established pattern. The visibility control via
selectedReplicaprop and the success/cancel handlers are correctly implemented.
180-186: LGTM!Layout setup follows project conventions with proper nesting of
DefaultLayoutandDatabaseLayout. The named import forDefaultLayoutaligns with established practices.apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx (3)
1-29: LGTM on imports!Imports are well-organized and follow project conventions.
92-123: LGTM!Chart implementation is well-structured with proper loading and empty states. The current mock data will always have 46 items, but once real data is integrated, the empty state handling will function correctly.
130-174: LGTM!Good implementation of the loading/success pattern with
GenericSkeletonLoader. The form layout is clean and consistent. Input values correctly handle potential undefined values gracefully.
Braintrust eval report
|
* Add read replicas details page from database replication * Clean * Address 🐰 --------- Co-authored-by: Alaister Young <[email protected]>
Context
Part of unifying replication interfaces in the dashboard into database replication page
Adds a details page for Read Replicas when clicking "View replication"
NOTE: There's something potentially wrong with the infra-monitoring data for replication lag as the endpoint does not seem to return any data for both staging and prod. I've got a ticket to investigate this separately here but am otherwise temporarily hard coding some random numbers to render the graph
Summary by CodeRabbit
Release Notes
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.