Files
supabase/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.tsx
T
Joshen Lim 09a1f431bc Mass update for all lucide icon imports to use the component with Icon suffix (#51659)
## Context

This is largely just a mechanical change here:
Opting to use lucide icons with the `Icon` suffix across all icon
imports within `studio`
- so that it’s clearer which components are icons + reduces the
possibility of name collision with our own components
- e.g <User /> vs <UserIcon />

Also added a eslint rule for this:
<img width="1069" height="167" alt="image"
src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc"
/>

And updated `AGENTS.md` as such:
```
Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced).
```
2026-10-14 12:56:55 +02:00

106 lines
3.7 KiB
TypeScript

import { useParams } from 'common'
import { AlertCircleIcon } from 'lucide-react'
import { parseAsString, useQueryState } from 'nuqs'
import { useEffect, useEffectEvent } from 'react'
import { Alert, AlertTitle } from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
import {
PageSection,
PageSectionAside,
PageSectionContent,
PageSectionDescription,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { getApiEndpoint } from '@/components/interfaces/Integrations/DataApi/DataApi.utils'
import { DatabaseSelector } from '@/components/ui/DatabaseSelector'
import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
import { useLoadBalancersQuery } from '@/data/read-replicas/load-balancers-query'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { useDatabaseSelectorStateSnapshot } from '@/state/database-selector'
export const DataApiProjectUrlCard = () => {
const { isPending: isLoading } = useSelectedProjectQuery()
const { ref: projectRef } = useParams()
const state = useDatabaseSelectorStateSnapshot()
const [querySource, setQuerySource] = useQueryState('source', parseAsString)
const { data: resolvedEndpoint } = useProjectApiUrl({ projectRef })
const {
data: databases,
isError,
isPending: isLoadingDatabases,
} = useReadReplicasQuery({ projectRef })
const { data: loadBalancers } = useLoadBalancersQuery({ projectRef })
const syncSelectedDb = useEffectEvent(() => {
if (querySource && querySource !== state.selectedDatabaseId) {
state.setSelectedDatabaseId(querySource)
}
})
useEffect(() => {
syncSelectedDb()
}, [querySource, projectRef])
const selectedDatabase = databases?.find((db) => db.identifier === state.selectedDatabaseId)
const loadBalancerSelected = state.selectedDatabaseId === 'load-balancer'
const replicaSelected = selectedDatabase?.identifier !== projectRef
const endpoint = getApiEndpoint({
selectedDatabaseId: state.selectedDatabaseId,
projectRef,
resolvedEndpoint,
loadBalancers,
selectedDatabase,
})
return (
<PageSection className="first:pt-0">
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>API URL</PageSectionTitle>
<PageSectionDescription>
{loadBalancerSelected
? 'RESTful endpoint for querying and managing your databases through your load balancer'
: replicaSelected
? 'RESTful endpoint for querying your read replica'
: 'RESTful endpoint for querying and managing your database'}
</PageSectionDescription>
</PageSectionSummary>
<PageSectionAside>
<DatabaseSelector
additionalOptions={
(loadBalancers ?? []).length > 0
? [{ id: 'load-balancer', name: 'API Load Balancer' }]
: []
}
onSelectId={() => {
setQuerySource(null)
}}
/>
</PageSectionAside>
</PageSectionMeta>
<PageSectionContent>
{isLoading || isLoadingDatabases ? (
<div className="space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" delayIndex={1} />
</div>
) : isError ? (
<Alert variant="destructive">
<AlertCircleIcon size={16} />
<AlertTitle>Failed to retrieve project URL</AlertTitle>
</Alert>
) : (
<Input copy readOnly className="font-mono" value={endpoint} />
)}
</PageSectionContent>
</PageSection>
)
}