mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## What The surface that shows you how to deploy a worker from the CLI, plus the product rename and the alpha framing. - **Compute → Workers.** `PRODUCT_NAME` and `CLI_NAME` now say `Workers` / `workers`, so the sidebar, page title, command menu, and every generated snippet match the CLI. One name, not two. - **`DeployWorkerDialog`** — scaffold / configure / push, with copyable `supabase workers` and `config.toml` snippets - **`WorkersEmptyState`** — an `EmptyStatePresentational` with a permission-gated deploy action - **`AlphaNotice`** on the list page, and a **New** badge on the sidebar entry (`Route.isNew`) - **`WorkerSnippetTabs`** — CLI, `config.toml`, and curl/JS/Python calls built from one worker shape. Reused by #49195. Snippet URLs resolve from the project's `app_config.endpoint` (`https://<project>/workers/v1/<name>`, the same shape as `/functions/v1/`), and fall back to `[YOUR WORKER URL]` before settings load rather than printing a wrong host. ## How to test Only on the **Mockamaster** project in staging — it is the one project in the alpha allow-list. 1. Staging dashboard → Mockamaster → **Workers** (the sidebar entry carries a **New** badge) 2. **Deploy a worker** → step through the tabs; every snippet should name the real worker URL, not a placeholder 3. Copy the cURL snippet and run it: expect `401`. Reaching a deployed worker needs a second allow-list (`WORKERS_ALLOWED_PROJECTS` in api-gateway `customer-router/wrangler.toml`), separate from the flag that unlocks the dashboard. 4. Open a project with no workers to see the empty state ## Tests `workerSnippets.test.ts` covers the generated output users copy: worker URL in all three call snippets, the `[YOUR WORKER URL]` fallback, anon vs service-role placeholder, empty-name fallback and trimming, runtime default, and every `config.toml` field. ## Unverified copy The dialog steps and the `supabase workers <sub>` subcommands come from the original POC spec, not from the shipped CLI. Same for "Dockerfile, Node.js and Deno supported" in the empty state — only Deno is confirmed end to end. Worth a check by someone who knows the CLI surface. Closes FE-4191 --------- Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { FeatureFlagContext, useFlag, useParams } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { useContext, useEffect, useMemo, type PropsWithChildren } from 'react'
|
|
import { Badge } from 'ui'
|
|
|
|
import { ProjectLayout } from '../ProjectLayout'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import { ProductMenu } from '@/components/ui/ProductMenu'
|
|
import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { withAuth } from '@/hooks/misc/withAuth'
|
|
import { PRODUCT_NAME } from '@/lib/constants/workers'
|
|
|
|
const useGenerateWorkersMenu = (): ProductMenuGroup[] => {
|
|
const { ref: projectRef = 'default' } = useParams()
|
|
return useMemo(
|
|
() => [
|
|
{
|
|
title: 'Manage',
|
|
items: [
|
|
{
|
|
name: PRODUCT_NAME,
|
|
key: 'main',
|
|
pages: ['', '[name]'],
|
|
url: `/project/${projectRef}/workers`,
|
|
items: [],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
[projectRef]
|
|
)
|
|
}
|
|
|
|
export const WorkersProductMenu = () => {
|
|
const router = useRouter()
|
|
const page = router.pathname.split('/')[4]
|
|
const menu = useGenerateWorkersMenu()
|
|
return <ProductMenu page={page} menu={menu} />
|
|
}
|
|
|
|
interface WorkersLayoutProps {
|
|
title?: string
|
|
}
|
|
|
|
const WorkersLayoutContent = ({ children, title }: PropsWithChildren<WorkersLayoutProps>) => {
|
|
const router = useRouter()
|
|
const { ref: projectRef } = useParams()
|
|
const { hasLoaded } = useContext(FeatureFlagContext)
|
|
const workersEnabled = useFlag('workers')
|
|
// The v2 workers routes require the FGA workers_read permission, which shared-types does not
|
|
// expose yet; they reuse the Edge Functions OAuth scope, so gate on the same product here.
|
|
const { isLoading: isLoadingPermissions, can: canReadWorkers } = useAsyncCheckPermissions(
|
|
PermissionAction.FUNCTIONS_READ,
|
|
'*'
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (hasLoaded && !workersEnabled) {
|
|
router.replace(`/project/${projectRef}`)
|
|
}
|
|
}, [router, hasLoaded, workersEnabled, projectRef])
|
|
|
|
if (!workersEnabled) return null
|
|
|
|
if (isLoadingPermissions) {
|
|
return (
|
|
<ProjectLayout
|
|
isLoading
|
|
product={PRODUCT_NAME}
|
|
browserTitle={{ entity: PRODUCT_NAME, section: title }}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ProjectLayout
|
|
product={PRODUCT_NAME}
|
|
productMenuBadge={<Badge variant="warning">Private Alpha</Badge>}
|
|
productMenu={<WorkersProductMenu />}
|
|
isBlocking={false}
|
|
browserTitle={{ entity: PRODUCT_NAME, section: title }}
|
|
>
|
|
{canReadWorkers ? (
|
|
children
|
|
) : (
|
|
<NoPermission isFullPage resourceText="view this project's workers" />
|
|
)}
|
|
</ProjectLayout>
|
|
)
|
|
}
|
|
|
|
export const WorkersLayout = withAuth(WorkersLayoutContent)
|