Files
supabase/apps/studio/components/interfaces/Explorer/QueryEditor/QuerySourceMenu.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

151 lines
5.4 KiB
TypeScript

import { useFlag, useParams } from 'common'
import { CheckIcon, ChevronDownIcon } from 'lucide-react'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from 'ui'
import { RowLimitSubMenu } from '../../SQLEditor/UtilityPanel/QuerySourceMenu/RowLimitSubMenu'
import { RunAsSubMenu } from '../../SQLEditor/UtilityPanel/QuerySourceMenu/RunAsSubMenu'
import { ExplorerToolbarAction } from '../ExplorerToolbar'
import { DatabaseParametersSubMenu } from '@/components/interfaces/QuerySources/DatabaseParametersSubMenu'
import { LogsCustomRangeDialog } from '@/components/interfaces/QuerySources/LogsCustomRangeDialog'
import { LogsTimeRangeSubMenu } from '@/components/interfaces/QuerySources/LogsTimeRangeSubMenu'
import { QuerySourceIcon } from '@/components/interfaces/QuerySources/QuerySourceIcon'
import { useLogsCustomRange } from '@/components/interfaces/QuerySources/useLogsCustomRange'
import UpgradePrompt from '@/components/interfaces/Settings/Logs/UpgradePrompt'
import {
createDefaultSourceBinding,
QUERY_SOURCE_LABELS,
QUERY_SOURCES,
type QuerySourceBinding,
} from '@/data/query-sources/query-source-registry'
import { type RoleImpersonationController } from '@/state/role-impersonation-state'
export type QuerySourceMenuProps = {
disabled?: boolean
rowLimit?: number
onRowLimitChange?: (val: number) => void
roleImpersonationState?: RoleImpersonationController
source: QuerySourceBinding
onSourceChange: (source: QuerySourceBinding) => void
}
/**
* Source binding and parameter controls shared by standalone Explorer queries
* and notebook query-cell toolbars. The consumer owns the binding; this menu
* only emits complete, validated-by-construction `QuerySourceBinding` values.
*
* Selecting a different backend emits that backend's default binding — deciding
* what happens to the query body is the consumer's call, since a notebook cell
* has SQL to preserve or discard and a fresh draft does not.
*/
export const QuerySourceMenu = ({
disabled = false,
rowLimit = 100,
onRowLimitChange,
roleImpersonationState,
source,
onSourceChange,
}: QuerySourceMenuProps) => {
const { ref } = useParams()
const isLogsSourceEnabled = useFlag('sqlEditorLogsSource')
const isOtelLogsEnabled = useFlag('otelLegacyLogs')
const {
isCustomRangeOpen,
setIsCustomRangeOpen,
showUpgradePrompt,
setShowUpgradePrompt,
handleApplyCustomRange,
} = useLogsCustomRange({
onRangeChange: (time_range) => onSourceChange({ _tag: 'logs', time_range }),
})
const availableSources = QUERY_SOURCES.filter(
(candidate) =>
candidate._tag !== 'logs' ||
(isLogsSourceEnabled && isOtelLogsEnabled) ||
source._tag === 'logs'
)
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<ExplorerToolbarAction
disabled={disabled}
aria-label={`Query source: ${QUERY_SOURCE_LABELS[source._tag]}`}
icon={<QuerySourceIcon source={source._tag} />}
iconRight={<ChevronDownIcon size={16} strokeWidth={2} />}
>
{QUERY_SOURCE_LABELS[source._tag]}
</ExplorerToolbarAction>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-60">
{availableSources.map((candidate) => (
<DropdownMenuItem
key={candidate._tag}
className="justify-between"
onSelect={(event) => {
event.preventDefault()
if (candidate._tag !== source._tag) {
onSourceChange(createDefaultSourceBinding(candidate._tag))
}
}}
>
<span className="flex items-center gap-x-2">
<QuerySourceIcon source={candidate._tag} className="text-foreground-light" />
{QUERY_SOURCE_LABELS[candidate._tag]}
</span>
{source._tag === candidate._tag && <CheckIcon size={14} />}
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
{source._tag === 'database' ? (
<>
<DatabaseParametersSubMenu
identifier={source.database_identifier ?? ref}
onIdentifierChange={(database_identifier) =>
onSourceChange({ _tag: 'database', database_identifier })
}
/>
{roleImpersonationState !== undefined && (
<RunAsSubMenu controlled state={roleImpersonationState} />
)}
{onRowLimitChange !== undefined && (
<RowLimitSubMenu
value={rowLimit}
onValueChange={(val) => onRowLimitChange(Number(val))}
/>
)}
</>
) : (
<LogsTimeRangeSubMenu
range={source.time_range}
onRangeChange={(time_range) => onSourceChange({ _tag: 'logs', time_range })}
onOpenCustomRange={() => setIsCustomRangeOpen(true)}
onShowUpgrade={() => setShowUpgradePrompt(true)}
/>
)}
</DropdownMenuContent>
</DropdownMenu>
{source._tag === 'logs' && (
<>
<LogsCustomRangeDialog
open={isCustomRangeOpen}
onOpenChange={setIsCustomRangeOpen}
onApply={handleApplyCustomRange}
/>
<UpgradePrompt show={showUpgradePrompt} setShowUpgradePrompt={setShowUpgradePrompt} />
</>
)}
</>
)
}