mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## What kind of change does this PR introduce? Refactor. Follow-up to #49871. ## What is the current behavior? Branded (green) text still uses the `text-brand` classname while the colour comes from `--primary`. ## What is the new behavior? **Rename-only:** `text-brand` → `text-primary` across callsites and docs. Leftover `bg-brand` / `border-brand` alias to `brand-default`. No intentional colour changes in this PR. This better matches how we treat our green in other components and props, like `variant="primary"` for green buttons. ## To test On light mode: smoke-test that branded text still looks like #49871 (readable green, not the bright fill). - [Homepage](https://zone-www-dot-com-git-dnywh-depr-316-text-brand-de2380-supabase.vercel.app/): “Scale to millions” uses `text-primary` - [Docs homepage](https://docs-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/docs): branded links like “More on self-hosting” are still readable - [Typography docs](https://design-system-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/design-system/docs/typography): documents `text-primary` - [Colour usage](https://design-system-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/design-system/docs/color-usage): `text-primary` is visibly darker than `bg-brand-default` _on light mode_ - [Studio auth providers](https://studio-staging-git-dnywh-depr-316-text-brand-to-60fa6c-supabase.vercel.app/dashboard/project/_/auth/providers): enabled provider badge text readable; status dot stays bright green <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Style** * Updated branded text, link hover states, icons, badges, indicators, and highlighted content across the Design System, Docs, Studio, Learn, UI Library, and marketing experiences to use the primary theme color. * Updated syntax highlighting and table-of-contents styling for consistent primary-color presentation. * Refined brand color fallback behavior for bright fills and borders. * **Documentation** * Updated color-usage and typography guidance to recommend the primary text utility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
206 lines
7.1 KiB
TypeScript
206 lines
7.1 KiB
TypeScript
import { type Hotkey } from '@tanstack/react-hotkeys'
|
|
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
|
|
import { AlignLeft, Check, Keyboard, Loader2, MoreVertical, SquareCode } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
import { useCallback, useContext, useEffect, useRef, useState } from 'react'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
KeyboardShortcut,
|
|
} from 'ui'
|
|
|
|
import { ExplorerToolbarAction } from './ExplorerToolbar'
|
|
import { QueryEditor, type ExplorerQueryModel, type QueryEditorHandle } from './QueryEditor'
|
|
import { SaveQueryDropdown } from './SaveQueryDropdown'
|
|
import { type QueryDisplay, type QueryResult } from './types'
|
|
import { toQuerySourceBinding } from '@/data/query-sources/query-source-registry'
|
|
import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
|
|
import { explorerQueryState, useExplorerQueryStateSnapshot } from '@/state/explorer-query'
|
|
import { useControlledRoleImpersonationState } from '@/state/role-impersonation-state'
|
|
import { hotkeyToKeys } from '@/state/shortcuts/formatShortcut'
|
|
import { SHORTCUT_DEFINITIONS, SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { createTabId, TabsStateContext } from '@/state/tabs'
|
|
|
|
/** Query-tab lifecycle adapter around the shared QueryEditor. */
|
|
export const ExplorerQueryTab = () => {
|
|
const router = useRouter()
|
|
const { id, ref } = useParams()
|
|
const tabs = useContext(TabsStateContext)
|
|
const querySnap = useExplorerQueryStateSnapshot()
|
|
|
|
const [isIntellisenseEnabled, setIsIntellisenseEnabled] = useLocalStorageQuery(
|
|
LOCAL_STORAGE_KEYS.SQL_EDITOR_INTELLISENSE,
|
|
true
|
|
)
|
|
|
|
const queryEditorRef = useRef<QueryEditorHandle>(null)
|
|
|
|
const hotkeySequnece: Hotkey | undefined =
|
|
SHORTCUT_DEFINITIONS[SHORTCUT_IDS.SQL_EDITOR_FORMAT].sequence[0]
|
|
const formatKeys = hotkeySequnece ? hotkeyToKeys(hotkeySequnece) : undefined
|
|
|
|
const [restoredQueryKey, setRestoredQueryKey] = useState<string>()
|
|
const [showQuery, setShowQuery] = useState(true)
|
|
|
|
const stateDraft = id ? querySnap.drafts[id] : undefined
|
|
const draft = stateDraft?.projectRef === ref ? stateDraft : undefined
|
|
const result = draft && id ? querySnap.results[id] : undefined
|
|
const queryKey = id && ref ? `${ref}:${id}` : undefined
|
|
const isDraftReady = !!queryKey && restoredQueryKey === queryKey
|
|
|
|
const roleImpersonationState = useControlledRoleImpersonationState(
|
|
draft?._tag === 'database' ? draft.role : undefined,
|
|
useCallback(
|
|
(role) => {
|
|
if (id) explorerQueryState.setRole({ id, role })
|
|
},
|
|
[id]
|
|
)
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (!id || !ref) return
|
|
|
|
setShowQuery(true)
|
|
explorerQueryState.restoreDraft({ id, projectRef: ref })
|
|
setRestoredQueryKey(`${ref}:${id}`)
|
|
}, [id, ref])
|
|
|
|
useEffect(() => {
|
|
if (!id || !isDraftReady || !draft?.pendingAutoRun) return
|
|
|
|
queryEditorRef.current?.run()
|
|
explorerQueryState.clearPendingAutoRun({ id })
|
|
}, [id, isDraftReady, draft?.pendingAutoRun])
|
|
|
|
if (!queryKey || restoredQueryKey !== queryKey) {
|
|
return (
|
|
<div
|
|
role="status"
|
|
aria-label="Loading query"
|
|
className="flex h-full items-center justify-center bg-surface-100"
|
|
>
|
|
<Loader2 className="animate-spin text-foreground-muted" size={18} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!id || !draft) {
|
|
return (
|
|
<div className="flex h-full flex-col items-center justify-center gap-3 bg-surface-100">
|
|
<SquareCode className="text-foreground-muted" size={24} />
|
|
<div className="text-center">
|
|
<p className="text-sm font-medium">Query draft not found</p>
|
|
<p className="text-sm text-foreground-lighter">
|
|
This local draft may have been closed or cleared from this browser.
|
|
</p>
|
|
</div>
|
|
<Button variant="primary" onClick={() => router.push(`/project/${ref}/explorer`)}>
|
|
Back to Explorer
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const display: QueryDisplay = {
|
|
view: draft.view,
|
|
chart: draft.chart ? { ...draft.chart, y_series: [...draft.chart.y_series] } : undefined,
|
|
}
|
|
|
|
const query: ExplorerQueryModel =
|
|
draft._tag === 'logs'
|
|
? { ...toQuerySourceBinding(draft), uncheckedSql: draft.uncheckedSql }
|
|
: {
|
|
...toQuerySourceBinding(draft),
|
|
uncheckedSql: draft.uncheckedSql,
|
|
rowLimit: draft.rowLimit,
|
|
}
|
|
|
|
const persistTab = () => tabs.makeTabPermanent(createTabId('query', { id }))
|
|
|
|
const handleResultChange = (nextResult: QueryResult) => {
|
|
explorerQueryState.setResult({
|
|
id,
|
|
result: { ...nextResult, executedAt: Date.now() },
|
|
})
|
|
}
|
|
|
|
return (
|
|
<QueryEditor
|
|
ref={queryEditorRef}
|
|
id={id}
|
|
variant="viewport"
|
|
title={draft.name}
|
|
query={query}
|
|
result={result}
|
|
display={display}
|
|
showQuery={showQuery}
|
|
onShowQueryChange={setShowQuery}
|
|
roleImpersonationState={roleImpersonationState}
|
|
onTitleChange={(value) => {
|
|
persistTab()
|
|
const name = value.trim() || 'Run SQL'
|
|
explorerQueryState.updateDraft({ id, name })
|
|
tabs.updateTab(createTabId('query', { id }), { label: name })
|
|
}}
|
|
onSqlChange={(sql) => {
|
|
persistTab()
|
|
explorerQueryState.updateDraft({ id, sql })
|
|
}}
|
|
onSourceChange={(source) => {
|
|
persistTab()
|
|
explorerQueryState.updateDraft({ id, source })
|
|
}}
|
|
onRowLimitChange={(rowLimit) => {
|
|
persistTab()
|
|
explorerQueryState.updateDraft({ id, rowLimit })
|
|
}}
|
|
onResultChange={handleResultChange}
|
|
onDisplayChange={(display) => {
|
|
persistTab()
|
|
explorerQueryState.setDisplay({ id, display })
|
|
}}
|
|
toolbarActions={
|
|
<>
|
|
<SaveQueryDropdown
|
|
query={{ title: draft.name, sql: draft.uncheckedSql }}
|
|
source={toQuerySourceBinding(draft)}
|
|
/>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<ExplorerToolbarAction icon={<MoreVertical size={16} strokeWidth={2} />} />
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent className="w-48" align="end">
|
|
<DropdownMenuItem
|
|
className="justify-between"
|
|
onClick={() => setIsIntellisenseEnabled(!isIntellisenseEnabled)}
|
|
>
|
|
<div className="flex items-center gap-x-2">
|
|
<Keyboard size={14} />
|
|
<span>Intellisense enabled</span>
|
|
</div>
|
|
{isIntellisenseEnabled && <Check className="text-primary" size={16} />}
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="justify-between"
|
|
onClick={() => queryEditorRef.current?.prettify()}
|
|
>
|
|
<span className="flex items-center gap-x-2">
|
|
<AlignLeft size={14} />
|
|
Prettify SQL
|
|
</span>
|
|
{formatKeys && <KeyboardShortcut keys={formatKeys} />}
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</>
|
|
}
|
|
/>
|
|
)
|
|
}
|