mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 02:45:07 +03:00
## Problem The `_Shadcn_` suffix isn't needed anymore on `Select` components ## Solution Remove it. No other changes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Updated internal component architecture to standardize and simplify the codebase. These changes improve code maintainability and consistency across the application without affecting existing functionality or user experience. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45988) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
109 lines
3.4 KiB
TypeScript
109 lines
3.4 KiB
TypeScript
'use client'
|
|
|
|
import { ReferenceContentInitiallyScrolledContext } from '~/features/docs/Reference.navigation.client'
|
|
import { safeHistoryReplaceState } from '~/lib/historyUtils'
|
|
import type { HTMLAttributes, PropsWithChildren } from 'react'
|
|
import { useContext, useEffect, useRef, useState } from 'react'
|
|
import { useInView } from 'react-intersection-observer'
|
|
import { cn, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from 'ui'
|
|
|
|
import { type IApiEndPoint } from './Reference.api.utils'
|
|
import { API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES } from './Reference.ui.shared'
|
|
|
|
/**
|
|
* Wrap a reference section with client-side functionality:
|
|
*
|
|
* - Intersection observer to auto-update the URL when the user scrolls the page
|
|
* - An ID to scroll to programmatically. This is on the entire section rather
|
|
* than the heading to avoid problems with scroll-to position when the heading
|
|
* is sticky.
|
|
*/
|
|
export function ReferenceSectionWrapper({
|
|
id,
|
|
link,
|
|
children,
|
|
className,
|
|
}: PropsWithChildren<{ id: string; link: string; className?: string }> &
|
|
HTMLAttributes<HTMLElement>) {
|
|
const initialScrollHappened = useContext(ReferenceContentInitiallyScrolledContext)
|
|
|
|
const { ref } = useInView({
|
|
threshold: 0,
|
|
rootMargin: '-10% 0% -50% 0%',
|
|
onChange: (inView) => {
|
|
if (
|
|
inView &&
|
|
initialScrollHappened &&
|
|
window.scrollY > 0 /* Don't update on first navigation to introduction */
|
|
) {
|
|
safeHistoryReplaceState(link)
|
|
}
|
|
},
|
|
})
|
|
|
|
return (
|
|
<section
|
|
ref={ref}
|
|
id={id}
|
|
className={cn('scroll-mt-[calc(var(--header-height)+4rem)]', className)}
|
|
>
|
|
{children}
|
|
</section>
|
|
)
|
|
}
|
|
|
|
export function ApiOperationBodySchemeSelector({
|
|
requestBody,
|
|
className,
|
|
}: {
|
|
requestBody: IApiEndPoint['requestBody']
|
|
className?: string
|
|
}) {
|
|
const availableSchemes = Object.keys(requestBody?.content || {}) as Array<
|
|
'application/json' | 'application/x-www-form-urlencoded'
|
|
>
|
|
const [selectedScheme, setSelectedScheme] = useState(availableSchemes[0])
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
const allSchemeDetails = useRef<HTMLUListElement[]>([])
|
|
useEffect(() => {
|
|
const elements = containerRef.current?.querySelectorAll(
|
|
`[${API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES.KEY}]`
|
|
)
|
|
allSchemeDetails.current = elements ? (Array.from(elements) as HTMLUListElement[]) : []
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
allSchemeDetails.current?.forEach((schemeDetails) => {
|
|
schemeDetails.hidden =
|
|
schemeDetails.getAttribute(API_REFERENCE_REQUEST_BODY_SCHEMA_DATA_ATTRIBUTES.KEY) !==
|
|
selectedScheme
|
|
})
|
|
}, [selectedScheme])
|
|
|
|
return (
|
|
<div ref={containerRef} className={cn('flex items-center justify-between gap-2', className)}>
|
|
<h3 className="text-base text-foreground">Body</h3>
|
|
<Select
|
|
value={selectedScheme}
|
|
onValueChange={(value) =>
|
|
setSelectedScheme(value as 'application/json' | 'application/x-www-form-urlencoded')
|
|
}
|
|
>
|
|
<SelectTrigger className="w-48 [&>span]:w-full [&>span]:truncate">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectGroup>
|
|
{availableSchemes.map((scheme) => (
|
|
<SelectItem key={scheme} value={scheme}>
|
|
{scheme}
|
|
</SelectItem>
|
|
))}
|
|
</SelectGroup>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
)
|
|
}
|