mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Small and medium form controls and related text grow from 14px to 16px below a viewport breakpoint, making them larger than surrounding dashboard text. ## Solution Keep these sizes at 14px across breakpoints in shared controls and form layouts, plus Studio search fields and assistant textareas. Explicit large and extra-large variants keep their existing sizes. The shared sizing change also applies to buttons. ```diff - text-base md:text-sm + text-sm ``` This accepts iOS Safari’s automatic zoom when focusing smaller editable fields. User zoom remains available. Validation: Prettier, scoped Studio ESLint, and whitespace checks pass. Browser checks and a full build have not been run. ## Review instructions 1. Open a project’s **Settings > General**. Resize across 768px and check that field text, labels, helper text, and buttons keep the same font size. 2. Open the organisation/project selector and resize across 640px. Its search text should stay at 14px. 3. Open the assistant and check that its textarea text stays the same size across 768px. 4. On an iPhone, focus an editable field and check that the accepted focus zoom behaviour remains usable. ## Checklist - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
136 lines
4.8 KiB
TypeScript
136 lines
4.8 KiB
TypeScript
import { keepPreviousData } from '@tanstack/react-query'
|
|
import { useDebounce, useIntersectionObserver } from '@uidotdev/usehooks'
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
import { Command, CommandGroup, CommandInput, CommandItem, CommandList } from 'ui'
|
|
import type { CustomOptionProps } from 'ui-patterns/FilterBar'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { useOrgProjectsInfiniteQuery } from '@/data/projects/org-projects-infinite-query'
|
|
import { useProjectsInfiniteQuery } from '@/data/projects/projects-infinite-query'
|
|
|
|
type AuditLogsProject = { ref: string; name: string }
|
|
|
|
interface AuditLogsProjectOptionProps extends CustomOptionProps {
|
|
// Scopes the list to an organization's projects, otherwise lists all of the user's projects
|
|
slug?: string
|
|
onSelectProject: (project: AuditLogsProject) => void
|
|
}
|
|
|
|
// Select-only project list for the FilterBar. The stored value is the project ref, while the
|
|
// chip shows the name through the property's `formatValue`.
|
|
export const AuditLogsProjectOption = ({
|
|
slug,
|
|
onChange,
|
|
onSelectProject,
|
|
}: AuditLogsProjectOptionProps) => {
|
|
const [search, setSearch] = useState('')
|
|
const debouncedSearch = useDebounce(search, 500)
|
|
|
|
const [sentinelRef, entry] = useIntersectionObserver({ threshold: 0, rootMargin: '0px' })
|
|
|
|
const isOrgScoped = !!slug
|
|
const variables = { search: search.length === 0 ? search : debouncedSearch }
|
|
const accountQuery = useProjectsInfiniteQuery(variables, {
|
|
placeholderData: keepPreviousData,
|
|
enabled: !isOrgScoped,
|
|
})
|
|
const orgQuery = useOrgProjectsInfiniteQuery(
|
|
{ slug, ...variables },
|
|
{ placeholderData: keepPreviousData, enabled: isOrgScoped }
|
|
)
|
|
const {
|
|
error,
|
|
isLoading,
|
|
isError,
|
|
isSuccess,
|
|
isFetching,
|
|
isFetchingNextPage,
|
|
hasNextPage,
|
|
fetchNextPage,
|
|
} = isOrgScoped ? orgQuery : accountQuery
|
|
const accountProjects = useMemo(
|
|
() => accountQuery.data?.pages.flatMap((page) => page.projects) ?? [],
|
|
[accountQuery.data?.pages]
|
|
)
|
|
const orgProjects = useMemo(
|
|
() => orgQuery.data?.pages.flatMap((page) => page.projects) ?? [],
|
|
[orgQuery.data?.pages]
|
|
)
|
|
const projects: AuditLogsProject[] = isOrgScoped ? orgProjects : accountProjects
|
|
|
|
useEffect(() => {
|
|
if (entry?.isIntersecting && hasNextPage && !isFetching && !isFetchingNextPage) {
|
|
fetchNextPage()
|
|
}
|
|
}, [entry?.isIntersecting, hasNextPage, isFetching, isFetchingNextPage, fetchNextPage])
|
|
|
|
const handleSelect = (project: AuditLogsProject) => {
|
|
onSelectProject(project)
|
|
onChange(project.ref)
|
|
}
|
|
|
|
return (
|
|
<Command shouldFilter={false}>
|
|
<CommandInput
|
|
showResetIcon
|
|
value={search}
|
|
onValueChange={setSearch}
|
|
placeholder="Find project..."
|
|
handleReset={() => setSearch('')}
|
|
className="text-sm"
|
|
// FilterBar keeps focus on the chip's input, so move it here for cmdk's arrow/enter keys
|
|
autoFocus
|
|
/>
|
|
<CommandList className="max-h-[300px] overflow-y-auto overflow-x-hidden">
|
|
<CommandGroup>
|
|
{isLoading && (
|
|
<div className="px-2 py-1">
|
|
<ShimmeringLoader className="py-2" />
|
|
</div>
|
|
)}
|
|
{isError && (
|
|
<p className="text-xs text-center text-foreground-lighter py-3">
|
|
Failed to retrieve projects: {error.message}
|
|
</p>
|
|
)}
|
|
{isSuccess && projects.length === 0 && (
|
|
<p className="text-xs text-center text-foreground-lighter py-3">
|
|
{search.length > 0 ? 'No projects found based on your search' : 'No projects found'}
|
|
</p>
|
|
)}
|
|
{isSuccess &&
|
|
projects.map((project) => (
|
|
<CommandItem
|
|
key={project.ref}
|
|
value={`${project.name.replaceAll('"', '')}-${project.ref}`}
|
|
className="cursor-pointer w-full"
|
|
onSelect={() => handleSelect(project)}
|
|
>
|
|
{project.name}
|
|
</CommandItem>
|
|
))}
|
|
<div ref={sentinelRef} className="h-1 -mt-1" />
|
|
{hasNextPage && (
|
|
<div className="px-2 py-1">
|
|
<ShimmeringLoader className="py-2" />
|
|
</div>
|
|
)}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
)
|
|
}
|
|
|
|
// FilterBar invokes `component(props)` as a plain function, so this factory returns that function
|
|
// with `onSelectProject` (and optionally `slug`) bound, keeping the component itself defined at
|
|
// module level.
|
|
export const createAuditLogsProjectOption = (
|
|
onSelectProject: AuditLogsProjectOptionProps['onSelectProject'],
|
|
slug?: string
|
|
) => {
|
|
const renderProjectOption = (props: CustomOptionProps) => (
|
|
<AuditLogsProjectOption {...props} slug={slug} onSelectProject={onSelectProject} />
|
|
)
|
|
return renderProjectOption
|
|
}
|