mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
## Problem The homepage usage section had two implementations gated by the `newHomepageUsageV2` ConfigCat flag, with the legacy V1 as the fallback. That flag has been at 100% in production for months, so V1 is dead code and the flag branch is unnecessary. ## Fix - Make V2 the default by removing the `newHomepageUsageV2` flag check in `Home.tsx`. - Delete the V1 section (`Home/ProjectUsageSection.tsx`), its chart (`Home/ProjectUsage.tsx`), and the now-orphaned `project-log-requests-count-query` plus its query key. - Shared code (`useProjectLogStatsQuery`, `UsageApiCounts`, `ProjectLogStatsVariables`) is kept since V2 and other modules still use it. The `newHomepageUsageV2` flag can be removed from ConfigCat after this merges. ## How to test - Open a project homepage on platform. - Confirm the usage section still renders (the V2 layout) with no flag dependency. - Verify no console errors and no broken imports. - Expected result: identical homepage usage section to what production shows today. ## Notes - This is independent of the in-flight service-health usage charts work (PR #46373), which is behind its own `newHomepageUsageDeltas` flag. Whichever merges second will resolve a small conflict on the `UsageSection` selection in `Home.tsx`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Removed project usage statistics section from the home page. * Simplified the home page experience by consolidating feature flag variants into a standardized implementation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
153 lines
6.0 KiB
TypeScript
153 lines
6.0 KiB
TypeScript
import { DndContext, DragEndEvent, PointerSensor, useSensor, useSensors } from '@dnd-kit/core'
|
|
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'
|
|
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { useEffect, useRef } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
import { AdvisorSection } from './AdvisorSection'
|
|
import { ConnectSection } from './ConnectSection'
|
|
import { CustomReportSection } from './CustomReportSection'
|
|
import { DEFAULT_SECTION_ORDER, mergeSectionOrder } from './Home.utils'
|
|
import { ProjectUsageSection } from './ProjectUsageSection'
|
|
import { SortableSection } from '@/components/interfaces/ProjectHome/SortableSection'
|
|
import { TopSection } from '@/components/interfaces/ProjectHome/TopSection'
|
|
import { ProjectNeedsSecuring } from '@/components/layouts/ProjectNeedsSecuring/ProjectNeedsSecuring'
|
|
import { ScaffoldContainer, ScaffoldSection } from '@/components/layouts/Scaffold'
|
|
import { useLocalStorage } from '@/hooks/misc/useLocalStorage'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export const ProjectHome = () => {
|
|
const { enableBranching } = useParams()
|
|
const snap = useAppStateSnapshot()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const track = useTrack()
|
|
|
|
const isMatureProject = dayjs(project?.inserted_at).isBefore(dayjs().subtract(10, 'day'))
|
|
|
|
const hasShownEnableBranchingModalRef = useRef(false)
|
|
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
|
|
const isComingUp = project?.status === PROJECT_STATUS.COMING_UP
|
|
|
|
const [sectionOrder, setSectionOrder] = useLocalStorage<string[]>(
|
|
`home-section-order-${project?.ref || 'default'}`,
|
|
DEFAULT_SECTION_ORDER
|
|
)
|
|
|
|
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 8 } }))
|
|
|
|
const handleDragEnd = (event: DragEndEvent) => {
|
|
const { active, over } = event
|
|
if (!over || active.id === over.id) return
|
|
setSectionOrder((items) => {
|
|
const oldIndex = items.indexOf(String(active.id))
|
|
const newIndex = items.indexOf(String(over.id))
|
|
if (oldIndex === -1 || newIndex === -1) return items
|
|
|
|
track('home_section_rows_moved', {
|
|
section_moved: String(active.id),
|
|
old_position: oldIndex,
|
|
new_position: newIndex,
|
|
})
|
|
|
|
return arrayMove(items, oldIndex, newIndex)
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (enableBranching && !hasShownEnableBranchingModalRef.current) {
|
|
hasShownEnableBranchingModalRef.current = true
|
|
snap.setShowCreateBranchModal(true)
|
|
}
|
|
}, [enableBranching, snap])
|
|
|
|
useEffect(() => {
|
|
setSectionOrder(mergeSectionOrder)
|
|
}, [setSectionOrder])
|
|
|
|
// On self-hosted the project's `inserted_at` is hard-coded to a past date
|
|
// (so it always looks "mature"), and the home page is otherwise sparse —
|
|
// always surface the Get Connected pane there. Platform keeps the
|
|
// maturity gate so long-running projects don't see it forever.
|
|
const showConnectSection = !!project && (!IS_PLATFORM || !isMatureProject)
|
|
|
|
const renderOrder = mergeSectionOrder(sectionOrder).filter((id) => {
|
|
if (id === 'connect') return showConnectSection
|
|
if (id === 'usage' || id === 'custom-report') return IS_PLATFORM
|
|
return true
|
|
})
|
|
|
|
return (
|
|
<ProjectNeedsSecuring>
|
|
<div className="w-full h-full">
|
|
<ScaffoldContainer size="large" className={cn(isPaused && 'h-full')}>
|
|
<ScaffoldSection
|
|
isFullWidth
|
|
className={cn(isPaused ? 'h-full flex justify-center p-0!' : 'pb-0')}
|
|
>
|
|
<TopSection />
|
|
</ScaffoldSection>
|
|
</ScaffoldContainer>
|
|
{!isPaused && (
|
|
<ScaffoldContainer size="large">
|
|
<ScaffoldSection isFullWidth className="gap-12 pb-32">
|
|
<DndContext sensors={sensors} onDragEnd={handleDragEnd}>
|
|
<SortableContext items={renderOrder} strategy={verticalListSortingStrategy}>
|
|
{renderOrder.map((id) => {
|
|
if (IS_PLATFORM && id === 'usage') {
|
|
return (
|
|
<div
|
|
key={id}
|
|
className={cn(isComingUp && 'opacity-60 pointer-events-none')}
|
|
>
|
|
<SortableSection id={id}>
|
|
<ProjectUsageSection />
|
|
</SortableSection>
|
|
</div>
|
|
)
|
|
}
|
|
if (id === 'connect' && showConnectSection) {
|
|
return (
|
|
<SortableSection key={id} id={id}>
|
|
<ConnectSection />
|
|
</SortableSection>
|
|
)
|
|
}
|
|
if (id === 'advisor') {
|
|
return (
|
|
<div
|
|
key={id}
|
|
className={cn(isComingUp && 'opacity-60 pointer-events-none')}
|
|
>
|
|
<SortableSection id={id}>
|
|
<AdvisorSection showEmptyState={isComingUp} />
|
|
</SortableSection>
|
|
</div>
|
|
)
|
|
}
|
|
if (IS_PLATFORM && id === 'custom-report') {
|
|
return (
|
|
<div
|
|
key={id}
|
|
className={cn(isComingUp && 'opacity-60 pointer-events-none')}
|
|
>
|
|
<SortableSection id={id}>
|
|
<CustomReportSection />
|
|
</SortableSection>
|
|
</div>
|
|
)
|
|
}
|
|
})}
|
|
</SortableContext>
|
|
</DndContext>
|
|
</ScaffoldSection>
|
|
</ScaffoldContainer>
|
|
)}
|
|
</div>
|
|
</ProjectNeedsSecuring>
|
|
)
|
|
}
|