mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Removes the remaining Next.js dependencies, compatibility shims, test
mocks, ESLint/TypeScript presets, and webpack/Next workarounds from
Studio following the TanStack Start migration.
Addresses FE-3107.
**Removed:**
- `next` and `next-router-mock` from `apps/studio/package.json` (and
updated `pnpm-lock.yaml`)
- Orphaned `apps/studio/compat/next/script.tsx` shim, `script.test.tsx`,
`compat/**` knip entry, and `nextCompat()` / `ssr.noExternal` `/^next/`
plumbing from `apps/studio/vite.config.ts`
- `apps/studio/tests/lib/route-mock.ts` and all `next-router-mock`
setup/imports across `tests/vitestSetup.ts`,
`tests/lib/custom-render.tsx`, and 12 test files
- `apps/studio/tests/pages/` directory (moved the 3 remaining tests to
`components/interfaces/Organization/Organization.utils.test.ts` and
`apps/studio/tests/routes/`)
- Unused `'use client'` directives across 23 Studio files
- Next.js/webpack workarounds: `graphiqlViteWorkers()` in
`vite.config.ts`, webpack `import.meta.glob` `try/catch` fallback in
`ConnectStepsSection.tsx`, shell `NODE_ENV=test` override in
`vite.config.ts` / root `package.json` / `studio-e2e-test.yml`, Next
`getPathMatch` and `_next` passthrough in `redirects.shared.*`,
`window.next?.router` check in `monaco-graphiql-coexistence.spec.ts`,
and unused `ANALYZE` env var in `apps/studio/turbo.jsonc`
- Next-only Sentry/chunk-load filters (`NEXT_NOT_FOUND`,
`NEXT_REDIRECT`, Next `/org/[slug]/` regex, `/app:\/\//`, dead
`includeThirdPartyErrorFilter` plumbing, webpack chunk error regex) and
stale Next/Pages Router comments, docs, and `#__next` CSS selector
**Changed:**
- `apps/studio/eslint.config.cjs`: switched from
`eslint-config-supabase/next` to the new `eslint-config-supabase/react`
preset (dropping `@next/next/no-img-element: off`, keeping `.next` /
`next-env.d.ts` ignored for local checkouts with stale pre-migration
build artifacts)
- `apps/studio/tsconfig.json`: extends `tsconfig/base.json` directly
instead of `tsconfig/nextjs.json` (identical resolved compiler options)
- `apps/studio/.github/eslint-rule-baselines.json`: pruned 33 stale
`pages/...` and `types/next.ts` entries without changing any rule
thresholds
- `apps/studio/tests/lib/custom-render.tsx`: backed
`TestFrameworkProvider` with TanStack Router instead of
`next-router-mock`
-
`apps/studio/components/interfaces/Integrations/GraphQL/GraphiQLTab.tsx`:
imports `graphiql/setup-workers/vite` directly
- `apps/studio/styles/globals.css`: replaced `@source
'../pages/**/*.{js,ts,jsx,tsx}'` with `@source
'../routes/**/*.{js,ts,jsx,tsx}'`
- `apps/studio/turbo.jsonc`: declared `"NEXT_PUBLIC_*"` in
`tasks.build.env` now that Turborepo infers `nitro` instead of `nextjs`
-
`apps/studio/components/interfaces/Organization/Organization.utils.ts`:
narrowed `buildOrgUrl`'s `slug` parameter to `string[] | undefined`
**Added:**
- `packages/eslint-config-supabase/shared.js` and
`packages/eslint-config-supabase/react.js` (plus `presets.test.ts`),
decoupling non-Next React apps from `eslint-config-next` with verified
zero non-`@next/*` rule drift while keeping
`eslint-config-supabase/next` unchanged for the Next.js apps
## To test
- Run `pnpm --filter eslint-config-supabase run test` and confirm preset
parity tests pass
- Run `pnpm --filter studio run lint`, `pnpm --filter studio run
lint:ratchet`, `pnpm --filter studio run typecheck`, `pnpm knip
--workspace apps/studio`, and `pnpm --filter studio run test`
- Run `pnpm --filter studio run build` and verify the production build,
prerendered routes, chunk-cycle check, and GraphiQL web workers succeed
- Smoke-test Studio locally (`pnpm dev:studio`): verify GraphiQL loads
cleanly, ConnectSheet framework steps render, and Tailwind styles on
route pages are intact
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
469 lines
14 KiB
TypeScript
469 lines
14 KiB
TypeScript
import { IS_PLATFORM } from 'common'
|
|
import { AnalyticsBucket, EdgeFunctions, FilesBucket, VectorBucket } from 'icons'
|
|
import {
|
|
Clock5Icon,
|
|
Code2Icon,
|
|
KeyRoundIcon,
|
|
LayersIcon,
|
|
ListChecksIcon,
|
|
LockIcon,
|
|
LockKeyholeIcon,
|
|
MailIcon,
|
|
MessageCircleIcon,
|
|
PlusIcon,
|
|
RowsIcon,
|
|
ShieldPlusIcon,
|
|
Table2Icon,
|
|
TelescopeIcon,
|
|
UserCogIcon,
|
|
UserPlusIcon,
|
|
VaultIcon,
|
|
WebhookIcon,
|
|
ZapIcon,
|
|
} from 'lucide-react'
|
|
import { useMemo } from 'react'
|
|
import { AiIconAnimation, Badge } from 'ui'
|
|
import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu'
|
|
import {
|
|
PageType,
|
|
useRegisterCommands,
|
|
useRegisterPage,
|
|
useSetCommandMenuOpen,
|
|
} from 'ui-patterns/CommandMenu'
|
|
|
|
import { COMMAND_MENU_SECTIONS } from './CommandMenu.utils'
|
|
import {
|
|
getIntegrationCommandName,
|
|
getIntegrationRoute,
|
|
useCreateCommandsConfig,
|
|
} from './CreateCommands.utils'
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
|
|
const CREATE_STUDIO_ENTITY = 'Create Studio Entity'
|
|
|
|
export function useCreateCommands(options?: CommandOptions) {
|
|
const setIsOpen = useSetCommandMenuOpen()
|
|
const {
|
|
ref,
|
|
setPage,
|
|
openSidebar,
|
|
snap,
|
|
authEnabled,
|
|
edgeFunctionsEnabled,
|
|
storageEnabled,
|
|
sendSmsHook,
|
|
sendEmailHook,
|
|
customAccessTokenHook,
|
|
mfaVerificationHook,
|
|
mfaVerificationHookEnabled,
|
|
passwordVerificationHook,
|
|
passwordVerificationHookEnabled,
|
|
beforeUserCreatedHook,
|
|
isVectorBucketsEnabled,
|
|
isAnalyticsBucketsEnabled,
|
|
installedIntegrationIds,
|
|
allIntegrations,
|
|
reportsEnabled,
|
|
} = useCreateCommandsConfig()
|
|
|
|
const databaseCommands = useMemo(
|
|
() =>
|
|
[
|
|
{
|
|
id: 'create-db-table',
|
|
name: 'Create Table',
|
|
route: `/project/${ref}/editor?create=table`,
|
|
icon: () => <Table2Icon />,
|
|
},
|
|
{
|
|
id: 'create-db-index',
|
|
name: 'Create Index',
|
|
route: `/project/${ref}/database/indexes?new=true`,
|
|
icon: () => <RowsIcon />,
|
|
},
|
|
{
|
|
id: 'create-db-function',
|
|
name: 'Create Database Function',
|
|
route: `/project/${ref}/database/functions?new=true`,
|
|
icon: () => <Code2Icon />,
|
|
},
|
|
{
|
|
id: 'create-db-enum',
|
|
name: 'Create Enumerated Type',
|
|
route: `/project/${ref}/database/types?new=true`,
|
|
icon: () => <ListChecksIcon />,
|
|
},
|
|
{
|
|
id: 'create-db-trigger',
|
|
name: 'Create Database Trigger',
|
|
route: `/project/${ref}/database/triggers?new=true`,
|
|
icon: () => <ZapIcon />,
|
|
},
|
|
{
|
|
id: 'create-db-role',
|
|
name: 'Create Database Role',
|
|
route: `/project/${ref}/database/roles?new=true`,
|
|
icon: () => <UserCogIcon />,
|
|
},
|
|
].filter(Boolean) as ICommand[],
|
|
[ref]
|
|
)
|
|
|
|
const authCommands = useMemo(
|
|
() =>
|
|
authEnabled
|
|
? ([
|
|
{
|
|
id: 'create-auth-user',
|
|
name: 'Create Auth User',
|
|
route: `/project/${ref}/auth/users?new=true`,
|
|
icon: () => <UserPlusIcon />,
|
|
},
|
|
{
|
|
id: 'create-rls-policy',
|
|
name: 'Create RLS Policy',
|
|
route: `/project/${ref}/database/policies?new=true`,
|
|
icon: () => <ShieldPlusIcon />,
|
|
},
|
|
...(IS_PLATFORM
|
|
? [
|
|
{
|
|
id: 'create-auth-hook-sms',
|
|
name: 'Create Auth Hook (SMS)',
|
|
route: `/project/${ref}/auth/hooks?hook=${sendSmsHook?.id}`,
|
|
icon: () => <MessageCircleIcon />,
|
|
},
|
|
{
|
|
id: 'create-auth-hook-email',
|
|
name: 'Create Auth Hook (Email)',
|
|
route: `/project/${ref}/auth/hooks?hook=${sendEmailHook?.id}`,
|
|
icon: () => <MailIcon />,
|
|
},
|
|
{
|
|
id: 'create-auth-hook-custom-access-token',
|
|
name: 'Create Auth Hook (Custom Access Token)',
|
|
route: `/project/${ref}/auth/hooks?hook=${customAccessTokenHook?.id}`,
|
|
icon: () => <KeyRoundIcon />,
|
|
},
|
|
{
|
|
id: 'create-auth-hook-mfa-verification',
|
|
name: 'Create Auth Hook (MFA Verification Attempt)',
|
|
route: `/project/${ref}/auth/hooks?hook=${mfaVerificationHook?.id}`,
|
|
icon: () => <ShieldPlusIcon />,
|
|
badge: () => (mfaVerificationHookEnabled ? <Badge>Team</Badge> : null),
|
|
className: mfaVerificationHookEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
},
|
|
{
|
|
id: 'create-auth-hook-password-verification',
|
|
name: 'Create Auth Hook (Password Verification Attempt)',
|
|
route: `/project/${ref}/auth/hooks?hook=${passwordVerificationHook?.id}`,
|
|
icon: () => <LockIcon />,
|
|
badge: () => (passwordVerificationHookEnabled ? <Badge>Team</Badge> : null),
|
|
className: passwordVerificationHookEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
},
|
|
{
|
|
id: 'create-auth-hook-before-user-created',
|
|
name: 'Create Auth Hook (Before User Created)',
|
|
route: `/project/${ref}/auth/hooks?hook=${beforeUserCreatedHook?.id}`,
|
|
icon: () => <KeyRoundIcon />,
|
|
},
|
|
]
|
|
: []),
|
|
...(IS_PLATFORM
|
|
? [
|
|
{
|
|
id: 'create-oauth-app',
|
|
name: 'Create OAuth App',
|
|
route: `/project/${ref}/auth/oauth-apps?new=true`,
|
|
icon: () => <KeyRoundIcon />,
|
|
},
|
|
]
|
|
: []),
|
|
].filter(Boolean) as ICommand[])
|
|
: [],
|
|
[
|
|
ref,
|
|
authEnabled,
|
|
sendSmsHook,
|
|
sendEmailHook,
|
|
customAccessTokenHook,
|
|
mfaVerificationHook,
|
|
mfaVerificationHookEnabled,
|
|
passwordVerificationHook,
|
|
passwordVerificationHookEnabled,
|
|
beforeUserCreatedHook,
|
|
]
|
|
)
|
|
|
|
const edgeFunctionsCommands = useMemo(
|
|
() =>
|
|
edgeFunctionsEnabled
|
|
? ([
|
|
{
|
|
id: 'create-edge-function-editor',
|
|
name: 'Create Edge Function via Editor',
|
|
route: `/project/${ref}/functions/new`,
|
|
icon: () => <EdgeFunctions />,
|
|
},
|
|
{
|
|
id: 'create-edge-function-cli',
|
|
name: 'Create Edge Function via CLI',
|
|
route: `/project/${ref}/functions?create=cli`,
|
|
icon: () => <EdgeFunctions />,
|
|
},
|
|
{
|
|
id: 'create-edge-function-ai',
|
|
name: 'Create Edge Function via AI',
|
|
action: () => {
|
|
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
snap.newChat({
|
|
name: 'Create new edge function',
|
|
initialInput: `Create a new edge function that ...`,
|
|
suggestions: {
|
|
title:
|
|
'I can help you create a new edge function. Here are a few example prompts to get you started:',
|
|
prompts: [
|
|
{
|
|
label: 'Stripe Payments',
|
|
description:
|
|
'Create a new edge function that processes payments with Stripe',
|
|
},
|
|
{
|
|
label: 'Email with Resend',
|
|
description: 'Create a new edge function that sends emails with Resend',
|
|
},
|
|
{
|
|
label: 'PDF Generator',
|
|
description:
|
|
'Create a new edge function that generates PDFs from HTML templates',
|
|
},
|
|
],
|
|
},
|
|
})
|
|
setIsOpen(false)
|
|
},
|
|
icon: () => (
|
|
<AiIconAnimation
|
|
allowHoverEffect={false}
|
|
size={20}
|
|
className="text-foreground-light"
|
|
/>
|
|
),
|
|
},
|
|
{
|
|
id: 'create-edge-function-secret',
|
|
name: 'Create Edge Function Secret',
|
|
route: `/project/${ref}/functions/secrets`,
|
|
icon: () => <LockKeyholeIcon />,
|
|
},
|
|
].filter(Boolean) as ICommand[])
|
|
: [],
|
|
[ref, edgeFunctionsEnabled, openSidebar, snap, setIsOpen]
|
|
)
|
|
|
|
const storageCommands = useMemo(
|
|
() =>
|
|
storageEnabled
|
|
? ([
|
|
{
|
|
id: 'create-storage-bucket-files',
|
|
name: 'Create Storage Bucket (Files)',
|
|
route: `/project/${ref}/storage/files?new=true`,
|
|
icon: () => <FilesBucket />,
|
|
},
|
|
{
|
|
id: 'create-storage-bucket-analytics',
|
|
name: 'Create Storage Bucket (Analytics)',
|
|
route: `/project/${ref}/storage/analytics?new=true`,
|
|
icon: () => <AnalyticsBucket />,
|
|
badge: () => <Badge variant="success">New</Badge>,
|
|
className: !isAnalyticsBucketsEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
enabled: isAnalyticsBucketsEnabled,
|
|
},
|
|
{
|
|
id: 'create-storage-bucket-vectors',
|
|
name: 'Create Storage Bucket (Vectors)',
|
|
route: `/project/${ref}/storage/vectors?new=true`,
|
|
icon: () => <VectorBucket />,
|
|
badge: () => <Badge variant="success">New</Badge>,
|
|
className: !isVectorBucketsEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
enabled: isVectorBucketsEnabled,
|
|
},
|
|
].filter(Boolean) as ICommand[])
|
|
: [],
|
|
[ref, storageEnabled, isAnalyticsBucketsEnabled, isVectorBucketsEnabled]
|
|
)
|
|
|
|
const integrationsCommands = useMemo(() => {
|
|
// Sort integrations: Postgres modules (non-wrappers) first, then wrappers
|
|
const sortedIntegrations = [...allIntegrations].sort((a, b) => {
|
|
const aIsWrapper = a.type === 'wrapper' ? 1 : 0
|
|
const bIsWrapper = b.type === 'wrapper' ? 1 : 0
|
|
return aIsWrapper - bIsWrapper
|
|
})
|
|
|
|
return sortedIntegrations
|
|
.map((integration) => {
|
|
const route = getIntegrationRoute(integration, ref, installedIntegrationIds)
|
|
if (!route) return null
|
|
|
|
const isWrapper = integration.type === 'wrapper'
|
|
|
|
// For wrappers, use the integration icon with wrapper styling
|
|
// For Postgres modules, use plain icons
|
|
const getIcon = () => {
|
|
if (isWrapper) {
|
|
return (
|
|
<div className="w-6 h-6 relative bg-white border rounded-md flex items-center justify-center [&>img]:p-1! [&>svg]:p-1!">
|
|
{integration.icon()}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// Use plain icons for Postgres modules
|
|
switch (integration.id) {
|
|
case 'vault':
|
|
return <VaultIcon />
|
|
case 'cron':
|
|
return <Clock5Icon />
|
|
case 'webhooks':
|
|
return <WebhookIcon />
|
|
case 'queues':
|
|
return <LayersIcon />
|
|
default:
|
|
// Fallback to integration icon for other Postgres modules
|
|
return integration.icon()
|
|
}
|
|
}
|
|
|
|
return {
|
|
id: `create-integration-${integration.id}`,
|
|
name: getIntegrationCommandName(integration),
|
|
route,
|
|
icon: getIcon,
|
|
}
|
|
})
|
|
.filter(Boolean) as ICommand[]
|
|
}, [ref, allIntegrations, installedIntegrationIds])
|
|
|
|
// Observability commands are only available on the platform, not for self-hosted/CLI
|
|
const observabilityCommands = useMemo(
|
|
() => [
|
|
...(IS_PLATFORM
|
|
? reportsEnabled
|
|
? ([
|
|
{
|
|
id: 'create-observability-report',
|
|
name: 'Create Custom Report',
|
|
route: `/project/${ref}/observability/api-overview?newReport=true`,
|
|
icon: () => <TelescopeIcon />,
|
|
},
|
|
].filter(Boolean) as ICommand[])
|
|
: []
|
|
: []),
|
|
],
|
|
[ref, reportsEnabled]
|
|
)
|
|
|
|
const sections = useMemo(
|
|
() => [
|
|
{
|
|
id: 'create-database',
|
|
name: 'Database',
|
|
commands: databaseCommands,
|
|
},
|
|
...(authCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-auth',
|
|
name: 'Auth',
|
|
commands: authCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(edgeFunctionsCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-edge-functions',
|
|
name: 'Edge Functions',
|
|
commands: edgeFunctionsCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(storageCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-storage',
|
|
name: 'Storage',
|
|
commands: storageCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(observabilityCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-observability',
|
|
name: 'Observability',
|
|
commands: observabilityCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(integrationsCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-integrations',
|
|
name: 'Integrations',
|
|
commands: integrationsCommands,
|
|
},
|
|
]
|
|
: []),
|
|
],
|
|
[
|
|
databaseCommands,
|
|
authCommands,
|
|
edgeFunctionsCommands,
|
|
storageCommands,
|
|
integrationsCommands,
|
|
observabilityCommands,
|
|
]
|
|
)
|
|
|
|
useRegisterPage(
|
|
CREATE_STUDIO_ENTITY,
|
|
{
|
|
type: PageType.Commands,
|
|
sections,
|
|
},
|
|
{
|
|
deps: [sections],
|
|
enabled: true,
|
|
}
|
|
)
|
|
|
|
useRegisterCommands(
|
|
COMMAND_MENU_SECTIONS.ACTIONS,
|
|
[
|
|
{
|
|
id: 'create-studio-entity',
|
|
name: 'Create...',
|
|
action: () => setPage(CREATE_STUDIO_ENTITY),
|
|
icon: () => <PlusIcon />,
|
|
},
|
|
],
|
|
{
|
|
...options,
|
|
orderSection: (sections) => sections,
|
|
sectionMeta: { priority: 3 },
|
|
enabled: true,
|
|
}
|
|
)
|
|
}
|