mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
187 lines
6.9 KiB
TypeScript
187 lines
6.9 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useDebounce } from '@uidotdev/usehooks'
|
|
import { LOCAL_STORAGE_KEYS, useFlag, useParams } from 'common'
|
|
import { FilePlus, FolderPlus, Plus, ScrollText, X } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import {
|
|
InnerSideBarFilters,
|
|
InnerSideBarFilterSearchInput,
|
|
InnerSideBarFilterSortDropdown,
|
|
InnerSideBarFilterSortDropdownItem,
|
|
} from 'ui-patterns/InnerSideMenu'
|
|
|
|
import { SearchList } from './SQLEditorNavV2/SearchList'
|
|
import { SQLEditorNav } from './SQLEditorNavV2/SQLEditorNav'
|
|
import { type SqlSnippetSource } from '@/components/interfaces/SQLEditor/querySource'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useLocalStorage } from '@/hooks/misc/useLocalStorage'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { getErrorMessage } from '@/lib/get-error-message'
|
|
import { useProfile } from '@/lib/profile'
|
|
import { useSqlEditorV2StateSnapshot } from '@/state/sql-editor/sql-editor-state'
|
|
|
|
export const SQLEditorMenu = () => {
|
|
const router = useRouter()
|
|
const { ref } = useParams()
|
|
const { profile } = useProfile()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const snapV2 = useSqlEditorV2StateSnapshot()
|
|
|
|
const sqlEditorLogsSource = useFlag('sqlEditorLogsSource')
|
|
const otelLegacyLogs = useFlag('otelLegacyLogs')
|
|
const canCreateLogsSnippet = sqlEditorLogsSource && otelLegacyLogs
|
|
|
|
const [search, setSearch] = useState('')
|
|
const [showSearch, setShowSearch] = useState(false)
|
|
const [sort, setSort] = useLocalStorage<'name' | 'inserted_at'>(
|
|
LOCAL_STORAGE_KEYS.SQL_EDITOR_SORT(ref ?? ''),
|
|
'inserted_at'
|
|
)
|
|
|
|
const debouncedSearch = useDebounce(search, 500)
|
|
|
|
const { can: canCreateSQLSnippet } = useAsyncCheckPermissions(
|
|
PermissionAction.CREATE,
|
|
'user_content',
|
|
{
|
|
resource: { type: 'sql', owner_id: profile?.id },
|
|
subject: { id: profile?.id },
|
|
}
|
|
)
|
|
|
|
const createNewFolder = () => {
|
|
if (!ref) return console.error('Project ref is required')
|
|
setSearch('')
|
|
setShowSearch(false)
|
|
snapV2.addNewFolder({ projectRef: ref })
|
|
}
|
|
|
|
const handleNewQuery = async (source: SqlSnippetSource = 'database') => {
|
|
if (!ref) return console.error('Project ref is required')
|
|
if (!project) return console.error('Project is required')
|
|
if (!profile) return console.error('Profile is required')
|
|
if (!canCreateSQLSnippet) {
|
|
return toast('Your queries will not be saved as you do not have sufficient permissions')
|
|
}
|
|
try {
|
|
const suffix = source === 'logs' ? '&source=logs' : ''
|
|
router.push(`/project/${ref}/sql/new?skip=true${suffix}`)
|
|
setSearch('')
|
|
setShowSearch(false)
|
|
} catch (error) {
|
|
toast.error(`Failed to create new query: ${getErrorMessage(error)}`)
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
setShowSearch(debouncedSearch.length > 0)
|
|
}, [debouncedSearch])
|
|
|
|
return (
|
|
<div className="h-full flex flex-col justify-between">
|
|
<div className="flex flex-col gap-y-4 grow">
|
|
<div className="mt-4 mx-4 flex items-center justify-between gap-x-2">
|
|
<InnerSideBarFilters className="w-full p-0 gap-0">
|
|
<InnerSideBarFilterSearchInput
|
|
name="search-queries"
|
|
placeholder="Search queries..."
|
|
aria-labelledby="Search queries"
|
|
value={search}
|
|
onChange={(e) => {
|
|
const value = e.target.value
|
|
setSearch(value)
|
|
if (value.length === 0) setShowSearch(false)
|
|
}}
|
|
onKeyDown={(e) => {
|
|
if (e.code === 'Escape') {
|
|
setSearch('')
|
|
setShowSearch(false)
|
|
}
|
|
}}
|
|
>
|
|
{showSearch ? (
|
|
<Tooltip>
|
|
<TooltipTrigger
|
|
className="absolute right-1 top-[.4rem] md:top-[.3rem] transition-colors text-foreground-light hover:text-foreground"
|
|
onClick={() => {
|
|
setSearch('')
|
|
setShowSearch(false)
|
|
}}
|
|
>
|
|
<X size={18} />
|
|
</TooltipTrigger>
|
|
<TooltipContent>Clear search</TooltipContent>
|
|
</Tooltip>
|
|
) : (
|
|
<InnerSideBarFilterSortDropdown
|
|
value={sort}
|
|
onValueChange={(value) => setSort(value as 'name' | 'inserted_at')}
|
|
>
|
|
<InnerSideBarFilterSortDropdownItem key="name" value="name">
|
|
Alphabetical
|
|
</InnerSideBarFilterSortDropdownItem>
|
|
<InnerSideBarFilterSortDropdownItem key="inserted_at" value="inserted_at">
|
|
Created At
|
|
</InnerSideBarFilterSortDropdownItem>
|
|
</InnerSideBarFilterSortDropdown>
|
|
)}
|
|
</InnerSideBarFilterSearchInput>
|
|
</InnerSideBarFilters>
|
|
<DropdownMenu>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
data-testid="sql-editor-new-query-button"
|
|
icon={<Plus className="text-foreground" />}
|
|
className="w-[26px]"
|
|
aria-label="Create a new query"
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">Create a new query</TooltipContent>
|
|
</Tooltip>
|
|
<DropdownMenuContent align="end" side="bottom" className="w-48">
|
|
<DropdownMenuItem className="gap-x-2" onClick={() => handleNewQuery()}>
|
|
<FilePlus size={14} />
|
|
Create a new snippet
|
|
</DropdownMenuItem>
|
|
{canCreateLogsSnippet && (
|
|
<DropdownMenuItem className="gap-x-2" onClick={() => handleNewQuery('logs')}>
|
|
<ScrollText size={14} />
|
|
Create a new logs query
|
|
</DropdownMenuItem>
|
|
)}
|
|
<DropdownMenuItem className="gap-x-2" onClick={() => createNewFolder()}>
|
|
<FolderPlus size={14} />
|
|
Create a new folder
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
|
|
{showSearch ? <SearchList search={debouncedSearch} /> : <SQLEditorNav sort={sort} />}
|
|
</div>
|
|
|
|
<div className="p-4 border-t sticky bottom-0 bg-studio">
|
|
<Button asChild block>
|
|
<Link href={`/project/${ref}/observability/connections`}>View running queries</Link>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|