The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore(studio): use the shared createNavigationHandler (#41628)
Danny White196aa05924af
diff --git a/apps/design-system/content/docs/components/table.mdx b/apps/design-system/content/docs/components/table.mdxindex c57ad66170c..2de803e5266 100644--- a/apps/design-system/content/docs/components/table.mdx+++ b/apps/design-system/content/docs/components/table.mdx@@ -199,11 +199,13 @@ Avoid adding other actions when using row-level navigation, as multiple interact<ComponentPreview name="table-row-link" />-When implementing row-level navigation, pay close attention to [Accessibility](/accessibility#focus-management) requirements. The row must be keyboard accessible with proper focus management, including:+When implementing row-level navigation, pay close attention to [Accessibility](/accessibility#focus-management) requirements. The row must be keyboard accessible with proper focus management. Also consider these affordances:-- Handling `Enter` and `Space` key presses for activation-- Providing visual focus indicators using classes like `inset-focus`-- Supporting modifier keys (`Ctrl`/`Cmd`) for opening links in new tabs+- Handle `Enter` and `Space` key presses for activation+- Provide visual focus indicators using classes like `inset-focus`+- Support modifier keys (`Ctrl`/`Cmd`, middle-click) for opening links in new tabs+ - Consider using the shared `createNavigationHandler` function to handle modifier keys+- Avoid bubbling up action events from _within_ the row#### Row navigation with actionsdiff --git a/apps/design-system/registry/default/example/table-row-link-actions.tsx b/apps/design-system/registry/default/example/table-row-link-actions.tsxindex ee82a507b7e..6acf355d8a2 100644--- a/apps/design-system/registry/default/example/table-row-link-actions.tsx+++ b/apps/design-system/registry/default/example/table-row-link-actions.tsx@@ -22,11 +22,13 @@ const policies = [},]+// Studio: See also createNavigationHandler in apps/studio/lib/navigation.ts+// It handles all of the below, plus modifier clicks and middle mouse button clicks.const handlePolicyNavigation = (- bucketId: string,+ policyId: string,event: React.MouseEvent | React.KeyboardEvent) => {- const url = `/${bucketId}`+ const url = `/${policyId}`if (event.metaKey || event.ctrlKey) {// window.open(`${url}`, '_blank') Disabled for demo purposes} else {diff --git a/apps/design-system/registry/default/example/table-row-link.tsx b/apps/design-system/registry/default/example/table-row-link.tsxindex 2ea3ec14436..be4716eff24 100644--- a/apps/design-system/registry/default/example/table-row-link.tsx+++ b/apps/design-system/registry/default/example/table-row-link.tsx@@ -20,6 +20,8 @@ const buckets = [},]+// Studio: See also createNavigationHandler in apps/studio/lib/navigation.ts+// It handles all of the below, plus modifier clicks and middle mouse button clicks.const handleBucketNavigation = (bucketId: string,event: React.MouseEvent | React.KeyboardEventdiff --git a/apps/studio/components/interfaces/Home/ProjectList/ProjectTableRow.tsx b/apps/studio/components/interfaces/Home/ProjectList/ProjectTableRow.tsxindex b3c2e4723d9..2c158b0d638 100644--- a/apps/studio/components/interfaces/Home/ProjectList/ProjectTableRow.tsx+++ b/apps/studio/components/interfaces/Home/ProjectList/ProjectTableRow.tsx@@ -7,6 +7,7 @@ import type { IntegrationProjectConnection } from 'data/integrations/integrationimport { getComputeSize, OrgProject } from 'data/projects/org-projects-infinite-query'import type { ResourceWarning } from 'data/usage/resource-warnings-query'import { BASE_PATH } from 'lib/constants'+import { createNavigationHandler } from 'lib/navigation'import type { Organization } from 'types'import { TableCell, TableRow } from 'ui'import { TimestampInfo } from 'ui-patterns'@@ -41,16 +42,15 @@ export const ProjectTableRow = ({const infraInformation = project.databases.find((x) => x.identifier === project.ref)+ const handleNavigation = createNavigationHandler(url, router)+return (<TableRow- className="cursor-pointer hover:bg-surface-200"- onClick={(event) => {- if (event.metaKey) {- window.open(`${BASE_PATH}/${url}`, '_blank')- } else {- router.push(url)- }- }}+ className="cursor-pointer hover:bg-surface-200 inset-focus"+ onClick={handleNavigation}+ onAuxClick={handleNavigation}+ onKeyDown={handleNavigation}+ tabIndex={0}><TableCell><div className="flex flex-col gap-y-2">diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsxindex 2c3f32eff4d..510f877a0af 100644--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsx+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/index.tsx@@ -9,7 +9,7 @@ import { AlphaNotice } from 'components/ui/AlphaNotice'import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'import { useAnalyticsBucketsQuery } from 'data/storage/analytics-buckets-query'import { AnalyticsBucket as AnalyticsBucketIcon } from 'icons'-import { BASE_PATH } from 'lib/constants'+import { createNavigationHandler } from 'lib/navigation'import {Card,Table,@@ -62,18 +62,6 @@ export const AnalyticsBuckets = () => {)const hasNoBuckets = buckets.length === 0- const handleBucketNavigation = (- bucketId: string,- event: React.MouseEvent | React.KeyboardEvent- ) => {- const url = `/project/${ref}/storage/analytics/buckets/${encodeURIComponent(bucketId)}`- if (event.metaKey || event.ctrlKey) {- window.open(`${BASE_PATH}${url}`, '_blank')- } else {- router.push(url)- }- }-return (<><PageContainer>@@ -157,47 +145,53 @@ export const AnalyticsBuckets = () => {</TableCell></TableRow>)}- {analyticsBuckets.map((bucket) => (- <TableRow- key={bucket.name}- className="relative cursor-pointer h-16 inset-focus"- onClick={(event) => handleBucketNavigation(bucket.name, event)}- onKeyDown={(event) => {- if (event.key === 'Enter' || event.key === ' ') {- event.preventDefault()- handleBucketNavigation(bucket.name, event)- }- }}- tabIndex={0}- >- <TableCell className="w-2 pr-1">- <AnalyticsBucketIcon- size={16}- className="text-foreground-muted"- />- </TableCell>- <TableCell>- <p className="whitespace-nowrap max-w-[512px] truncate">- {bucket.name}- </p>- </TableCell>+ {analyticsBuckets.map((bucket) => {+ const handleBucketNavigation = createNavigationHandler(+ `/project/${ref}/storage/analytics/buckets/${encodeURIComponent(bucket.name)}`,+ router+ )- <TableCell>- <p className="text-foreground-light">- <TimestampInfo- utcTimestamp={bucket.created_at}- className="text-sm text-foreground-light"+ return (+ <TableRow+ key={bucket.name}+ className="relative cursor-pointer h-16 inset-focus"+ onClick={handleBucketNavigation}+ onAuxClick={handleBucketNavigation}+ onKeyDown={handleBucketNavigation}+ tabIndex={0}+ >+ <TableCell className="w-2 pr-1">+ <AnalyticsBucketIcon+ size={16}+ className="text-foreground-muted"/>- </p>- </TableCell>+ </TableCell>+ <TableCell>+ <p className="whitespace-nowrap max-w-[512px] truncate">+ {bucket.name}+ </p>+ </TableCell>- <TableCell>- <div className="flex justify-end items-center h-full">- <ChevronRight size={14} className="text-foreground-muted/60" />- </div>- </TableCell>- </TableRow>- ))}+ <TableCell>+ <p className="text-foreground-light">+ <TimestampInfo+ utcTimestamp={bucket.created_at}+ className="text-sm text-foreground-light"+ />+ </p>+ </TableCell>++ <TableCell>+ <div className="flex justify-end items-center h-full">+ <ChevronRight+ size={14}+ className="text-foreground-muted/60"+ />+ </div>+ </TableCell>+ </TableRow>+ )+ })}</TableBody></Table></Card>diff --git a/apps/studio/components/interfaces/Storage/VectorBuckets/index.tsx b/apps/studio/components/interfaces/Storage/VectorBuckets/index.tsxindex 85c98c0aa9a..e759e7729e2 100644--- a/apps/studio/components/interfaces/Storage/VectorBuckets/index.tsx+++ b/apps/studio/components/interfaces/Storage/VectorBuckets/index.tsx@@ -1,14 +1,14 @@import { ChevronRight, Search } from 'lucide-react'import { useRouter } from 'next/navigation'import { parseAsBoolean, useQueryState } from 'nuqs'-import { useState, type KeyboardEvent, type MouseEvent } from 'react'+import { useState } from 'react'import { useParams } from 'common'import AlertError from 'components/ui/AlertError'import { AlphaNotice } from 'components/ui/AlphaNotice'import { useVectorBucketsQuery } from 'data/storage/vector-buckets-query'import { VectorBucket as VectorBucketIcon } from 'icons'-import { BASE_PATH } from 'lib/constants'+import { createNavigationHandler } from 'lib/navigation'import { Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'import { Input } from 'ui-patterns/DataInputs/Input'import { PageContainer } from 'ui-patterns/PageContainer'@@ -50,15 +50,6 @@ export const VectorsBuckets = () => {bucket.vectorBucketName.toLowerCase().includes(filterString.toLowerCase()))- const handleBucketNavigation = (bucketName: string, event: MouseEvent | KeyboardEvent) => {- const url = `/project/${projectRef}/storage/vectors/buckets/${encodeURIComponent(bucketName)}`- if (event.metaKey || event.ctrlKey) {- window.open(`${BASE_PATH}${url}`, '_blank')- } else {- router.push(url)- }- }-return (<><PageContainer>@@ -133,17 +124,18 @@ export const VectorsBuckets = () => {// the creation time is in seconds, convert it to millisecondsconst created = +bucket.creationTime * 1000+ const handleBucketNavigation = createNavigationHandler(+ `/project/${projectRef}/storage/vectors/buckets/${encodeURIComponent(name)}`,+ router+ )+return (<TableRowkey={id}className="relative cursor-pointer h-16 inset-focus"- onClick={(event) => handleBucketNavigation(name, event)}- onKeyDown={(event) => {- if (event.key === 'Enter' || event.key === ' ') {- event.preventDefault()- handleBucketNavigation(name, event)- }- }}+ onClick={handleBucketNavigation}+ onAuxClick={handleBucketNavigation}+ onKeyDown={handleBucketNavigation}tabIndex={0}><TableCell className="w-2 pr-1">