mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 4 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | **4** | **#54307 ← this PR** | **Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute** | | 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.) | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates `components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
295 lines
12 KiB
TypeScript
295 lines
12 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { LockIcon, PaintbrushIcon, PlusCircleIcon, Trash2Icon } from 'lucide-react'
|
|
import { parseAsBoolean, useQueryState } from 'nuqs'
|
|
import { useMemo, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Button, cn, LoadingLine, Popover, PopoverContent, PopoverTrigger, Separator } from 'ui'
|
|
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { pgmqQueueTable } from './Queues.utils'
|
|
import { DeleteQueue } from '@/components/interfaces/Integrations/Queues/SingleQueue/DeleteQueue'
|
|
import { PurgeQueue } from '@/components/interfaces/Integrations/Queues/SingleQueue/PurgeQueue'
|
|
import { QUEUE_MESSAGE_TYPE } from '@/components/interfaces/Integrations/Queues/SingleQueue/Queue.utils'
|
|
import { QueueMessagesDataGrid } from '@/components/interfaces/Integrations/Queues/SingleQueue/QueueDataGrid'
|
|
import { QueueFilters } from '@/components/interfaces/Integrations/Queues/SingleQueue/QueueFilters'
|
|
import { QueueSettings } from '@/components/interfaces/Integrations/Queues/SingleQueue/QueueSettings'
|
|
import { SendMessageModal } from '@/components/interfaces/Integrations/Queues/SingleQueue/SendMessageModal'
|
|
import { Markdown } from '@/components/interfaces/Markdown'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useDatabasePoliciesQuery } from '@/data/database-policies/database-policies-query'
|
|
import { useQueueMessagesInfiniteQuery } from '@/data/database-queues/database-queue-messages-infinite-query'
|
|
import { useQueuesExposePostgrestStatusQuery } from '@/data/database-queues/database-queues-expose-postgrest-status-query'
|
|
import { useTableUpdateMutation } from '@/data/tables/table-update-mutation'
|
|
import { useTablesQuery } from '@/data/tables/tables-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
export const QueueTab = () => {
|
|
const { childId: queueName, ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const [openRlsPopover, setOpenRlsPopover] = useState(false)
|
|
const [rlsConfirmModalOpen, setRlsConfirmModalOpen] = useState(false)
|
|
const [sendMessageModalShown, setSendMessageModalShown] = useQueryState(
|
|
'new-message',
|
|
parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true })
|
|
)
|
|
const [purgeQueueModalShown, setPurgeQueueModalShown] = useState(false)
|
|
const [deleteQueueModalShown, setDeleteQueueModalShown] = useState(false)
|
|
const [selectedTypes, setSelectedTypes] = useState<QUEUE_MESSAGE_TYPE[]>([])
|
|
|
|
const { data: tables, isPending: isLoadingTables } = useTablesQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
schema: 'pgmq',
|
|
})
|
|
const queueRelname = queueName ? pgmqQueueTable(queueName) : undefined
|
|
const queueTable = tables?.find((x) => x.name === queueRelname)
|
|
const isRlsEnabled = queueTable?.rls_enabled ?? false
|
|
|
|
const { data: policies } = useDatabasePoliciesQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
schemas: ['pgmq'],
|
|
})
|
|
const queuePolicies = (policies ?? []).filter((policy) => policy.table === queueRelname)
|
|
|
|
const { data: isExposed } = useQueuesExposePostgrestStatusQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const {
|
|
data,
|
|
error,
|
|
isPending: isLoading,
|
|
fetchNextPage,
|
|
isFetching,
|
|
} = useQueueMessagesInfiniteQuery(
|
|
{
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
queueName: queueName!,
|
|
// when no types are selected, include all types of messages
|
|
status: selectedTypes.length === 0 ? ['archived', 'available', 'scheduled'] : selectedTypes,
|
|
},
|
|
{ staleTime: 30 }
|
|
)
|
|
const messages = useMemo(() => data?.pages.flatMap((p) => p), [data?.pages])
|
|
|
|
const { mutate: updateTable, isPending: isUpdatingTable } = useTableUpdateMutation({
|
|
onSettled: () => {
|
|
toast.success(`Successfully enabled RLS for ${queueName}`)
|
|
setRlsConfirmModalOpen(false)
|
|
},
|
|
})
|
|
|
|
const onToggleRLS = async () => {
|
|
if (!project) return console.error('Project is required')
|
|
if (!queueTable) return toast.error('Unable to toggle RLS: Queue table not found')
|
|
const payload = {
|
|
id: queueTable.id,
|
|
rls_enabled: true,
|
|
}
|
|
updateTable({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
id: queueTable.id,
|
|
name: queueTable.name,
|
|
schema: 'pgmq',
|
|
payload: payload,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<div className="h-full flex flex-col">
|
|
<div className="flex items-center justify-between gap-x-4 py-1.5 px-10 mb-0 bg-surface-200">
|
|
<QueueFilters selectedTypes={selectedTypes} setSelectedTypes={setSelectedTypes} />
|
|
<div className="flex gap-x-2">
|
|
<QueueSettings />
|
|
|
|
<ButtonTooltip
|
|
variant="text"
|
|
className="px-1.5"
|
|
onClick={() => setPurgeQueueModalShown(true)}
|
|
icon={<PaintbrushIcon />}
|
|
title="Purge messages"
|
|
aria-label="Purge messages"
|
|
tooltip={{ content: { side: 'bottom', text: 'Purge messages' } }}
|
|
/>
|
|
|
|
<ButtonTooltip
|
|
variant="text"
|
|
className="px-1.5"
|
|
onClick={() => setDeleteQueueModalShown(true)}
|
|
icon={<Trash2Icon />}
|
|
title="Delete queue"
|
|
aria-label="Delete queue"
|
|
tooltip={{ content: { side: 'bottom', text: 'Delete queue' } }}
|
|
/>
|
|
|
|
<Separator orientation="vertical" className="h-[26px]" />
|
|
|
|
{isLoadingTables ? (
|
|
<ShimmeringLoader className="w-[123px]" />
|
|
) : isRlsEnabled ? (
|
|
<>
|
|
{queuePolicies.length === 0 ? (
|
|
<ButtonTooltip
|
|
asChild
|
|
className="group"
|
|
icon={<PlusCircleIcon strokeWidth={1.5} className="text-foreground-muted" />}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
className: 'w-[280px]',
|
|
text: 'RLS is enabled for this queue, but no policies are set. Queue will not be accessible.',
|
|
},
|
|
}}
|
|
>
|
|
<Link
|
|
to="/project/$ref/database/policies"
|
|
params={{ ref: ref ?? '_' }}
|
|
search={{
|
|
search: queueTable?.id !== undefined ? String(queueTable.id) : undefined,
|
|
schema: 'pgmq',
|
|
}}
|
|
>
|
|
Add RLS policy
|
|
</Link>
|
|
</ButtonTooltip>
|
|
) : (
|
|
<Button
|
|
asChild
|
|
className="group"
|
|
icon={
|
|
<div
|
|
className={cn(
|
|
'flex items-center justify-center rounded-full bg-border-stronger h-[16px]',
|
|
queuePolicies.length > 9 ? ' px-1' : 'w-[16px]'
|
|
)}
|
|
>
|
|
<span className="text-[11px] text-foreground font-mono text-center">
|
|
{queuePolicies.length}
|
|
</span>
|
|
</div>
|
|
}
|
|
>
|
|
<Link
|
|
to="/project/$ref/database/policies"
|
|
params={{ ref: ref ?? '_' }}
|
|
search={{
|
|
search: queueTable?.id !== undefined ? String(queueTable.id) : undefined,
|
|
schema: 'pgmq',
|
|
}}
|
|
>
|
|
Auth {queuePolicies.length > 1 ? <span>policies</span> : <span>policy</span>}
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</>
|
|
) : (
|
|
<Popover
|
|
modal={false}
|
|
open={openRlsPopover}
|
|
onOpenChange={() => setOpenRlsPopover(!openRlsPopover)}
|
|
>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
variant={isExposed ? 'warning' : 'default'}
|
|
icon={<LockIcon strokeWidth={1.5} />}
|
|
>
|
|
RLS disabled
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-80 text-sm" align="end">
|
|
<h3 className="text-xs flex items-center gap-x-2">
|
|
<LockIcon size={14} /> Row Level Security (RLS)
|
|
</h3>
|
|
<div className="grid gap-2 mt-2 text-foreground-light text-xs">
|
|
{isExposed ? (
|
|
<>
|
|
<p>
|
|
You can restrict and control who can manage this queue using Row Level
|
|
Security.
|
|
</p>
|
|
<p>With RLS enabled, anonymous users will not have access to this queue.</p>
|
|
<Button
|
|
className="w-min"
|
|
onClick={() => setRlsConfirmModalOpen(!rlsConfirmModalOpen)}
|
|
>
|
|
Enable RLS for this queue
|
|
</Button>
|
|
</>
|
|
) : (
|
|
<>
|
|
<Markdown
|
|
className="[&>p]:leading-normal! text-xs [&>p]:m-0! flex flex-col gap-y-2"
|
|
content={`
|
|
RLS for queues is only relevant if exposure through PostgREST has been enabled, in which you can restrict and control who can manage this queue using Row Level Security.
|
|
|
|
You may opt to manage your queues via any Supabase client libraries or PostgREST endpoints by enabling this in the [queues settings](/project/${project?.ref}/integrations/queues/settings).`}
|
|
/>
|
|
<Button
|
|
className="w-min"
|
|
onClick={() => setRlsConfirmModalOpen(!rlsConfirmModalOpen)}
|
|
>
|
|
Enable RLS for this queue
|
|
</Button>
|
|
</>
|
|
)}
|
|
</div>
|
|
</PopoverContent>
|
|
</Popover>
|
|
)}
|
|
|
|
<Button variant="primary" onClick={() => setSendMessageModalShown(true)}>
|
|
Add message
|
|
</Button>
|
|
|
|
{/* <DocsButton href={docsUrl} />} */}
|
|
</div>
|
|
</div>
|
|
|
|
<LoadingLine loading={isFetching} />
|
|
|
|
<QueueMessagesDataGrid
|
|
error={error}
|
|
messages={messages || []}
|
|
isLoading={isLoading}
|
|
showMessageModal={() => setSendMessageModalShown(true)}
|
|
fetchNextPage={fetchNextPage}
|
|
/>
|
|
<SendMessageModal
|
|
visible={sendMessageModalShown}
|
|
onClose={() => setSendMessageModalShown(false)}
|
|
/>
|
|
<DeleteQueue
|
|
queueName={queueName!}
|
|
visible={deleteQueueModalShown}
|
|
onClose={() => setDeleteQueueModalShown(false)}
|
|
/>
|
|
<PurgeQueue
|
|
queueName={queueName!}
|
|
visible={purgeQueueModalShown}
|
|
onClose={() => setPurgeQueueModalShown(false)}
|
|
/>
|
|
|
|
<ConfirmationModal
|
|
visible={rlsConfirmModalOpen}
|
|
title="Enable Row Level Security"
|
|
confirmLabel="Enable RLS"
|
|
confirmLabelLoading="Enabling RLS"
|
|
loading={isUpdatingTable}
|
|
onCancel={() => setRlsConfirmModalOpen(false)}
|
|
onConfirm={() => onToggleRLS()}
|
|
>
|
|
<p className="text-sm text-foreground-light">
|
|
Are you sure you want to enable Row Level Security for the queue "{queueName}"?
|
|
</p>
|
|
</ConfirmationModal>
|
|
</div>
|
|
)
|
|
}
|