mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Context
Final clean up of deprecated Scaffold components, just touches
- Account audit logs
- Project home page
- Database -> Column privileges
- Storage -> Analytics bucket details
- Storage -> Vector bucket details
- Settings -> Infrastructure -> Disk management
- Settings -> Infrastructure -> Read replica details
- Integrations -> Wrappers overview (Only for non supported integration
UI)
- Edge functions -> Empty state
- Auth -> Performance
Also replaces usage of `ScaffoldDivider` with just the `Separator`
component
And also adjusts the page container sizes of database pages from large
to default - these only have visual differences on viewport widths
larger than a laptop
Testing just needs a quick sweep of all these surfaces to make sure
nothing looks weird - will do so on my end too once the builds go
through!
For @supabase/security's review - review requirement was triggered as
`Documents.tsx` was updated in the organization settings page. But it
was just to change the Divider component 🙏
273 lines
11 KiB
TypeScript
273 lines
11 KiB
TypeScript
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
|
import { useFlag } from 'common'
|
|
import { ExternalLinkIcon, RefreshCwIcon, SearchIcon, XIcon } from 'lucide-react'
|
|
import { parseAsString, parseAsStringLiteral, useQueryState } from 'nuqs'
|
|
import { useMemo, useRef, type PropsWithChildren } from 'react'
|
|
import { Button, Card, Table, TableBody, TableHead, TableHeader, TableRow } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { Input } from 'ui-patterns/DataInputs/Input'
|
|
import { PageContainer } from 'ui-patterns/PageContainer'
|
|
import {
|
|
PageHeader,
|
|
PageHeaderAside,
|
|
PageHeaderDescription,
|
|
PageHeaderMeta,
|
|
PageHeaderSummary,
|
|
PageHeaderTitle,
|
|
} from 'ui-patterns/PageHeader'
|
|
import { PageSection, PageSectionContent } from 'ui-patterns/PageSection'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { DeployEdgeFunctionButton } from '@/components/interfaces/EdgeFunctions/DeployEdgeFunctionButton'
|
|
import {
|
|
EDGE_FUNCTIONS_SORT_VALUES,
|
|
EdgeFunctionsSort,
|
|
EdgeFunctionsSortColumn,
|
|
EdgeFunctionsSortDropdown,
|
|
EdgeFunctionsSortOrder,
|
|
} from '@/components/interfaces/EdgeFunctions/EdgeFunctionsSortDropdown'
|
|
import { EdgeFunctionsListItem } from '@/components/interfaces/Functions/EdgeFunctionsListItem'
|
|
import { FunctionsEmptyState } from '@/components/interfaces/Functions/FunctionsEmptyState'
|
|
import { TerminalInstructionsDialog } from '@/components/interfaces/Functions/TerminalInstructionsDialog'
|
|
import { useFunctionsListShortcuts } from '@/components/interfaces/Functions/useFunctionsListShortcuts'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { DocsButton } from '@/components/ui/DocsButton'
|
|
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
|
|
import { TableRowNoResults } from '@/components/ui/TableRowNoResults'
|
|
import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query'
|
|
import { useIsProjectActive } from '@/hooks/misc/useSelectedProject'
|
|
import { DOCS_URL, IS_PLATFORM } from '@/lib/constants'
|
|
import { onSearchInputEscape } from '@/lib/keyboard'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
|
|
export const Route = createFileRoute('/project/$ref/functions/')({
|
|
component: FunctionsIndexRoute,
|
|
staticData: {
|
|
functionsLayoutTitle: 'Edge Functions',
|
|
},
|
|
})
|
|
|
|
function FunctionsIndexRoute() {
|
|
return (
|
|
<EdgeFunctionsIndexPageWrapper>
|
|
<EdgeFunctionsPage />
|
|
</EdgeFunctionsIndexPageWrapper>
|
|
)
|
|
}
|
|
|
|
function EdgeFunctionsPage() {
|
|
const navigate = useNavigate()
|
|
const { ref } = Route.useParams()
|
|
const showLastHourStats = useFlag('edgeFunctionsRequestMetrics')
|
|
const isProjectActive = useIsProjectActive()
|
|
|
|
const searchInputRef = useRef<HTMLInputElement>(null)
|
|
|
|
const [search, setSearch] = useQueryState('search', parseAsString.withDefault(''))
|
|
const [sort, setSortQueryParam] = useQueryState(
|
|
'sort',
|
|
parseAsStringLiteral<EdgeFunctionsSort>(EDGE_FUNCTIONS_SORT_VALUES).withDefault('name:asc')
|
|
)
|
|
|
|
const {
|
|
data: functions,
|
|
error,
|
|
isPending: isLoading,
|
|
isError,
|
|
isSuccess,
|
|
isFetching,
|
|
refetch,
|
|
} = useEdgeFunctionsQuery({ projectRef: ref })
|
|
|
|
useFunctionsListShortcuts({
|
|
searchInputRef,
|
|
setSearch,
|
|
sort,
|
|
setSort: setSortQueryParam,
|
|
canCreateNew: isProjectActive,
|
|
onCreateNew: () => void navigate({ to: '/project/$ref/functions/new', params: { ref } }),
|
|
onRefresh: () => {
|
|
refetch()
|
|
},
|
|
})
|
|
|
|
const filteredFunctions = useMemo(() => {
|
|
const temp = (functions ?? []).filter((x) =>
|
|
x.name.toLowerCase().includes(search.toLowerCase())
|
|
)
|
|
const [sortCol, sortOrder] = sort.split(':') as [
|
|
EdgeFunctionsSortColumn,
|
|
EdgeFunctionsSortOrder,
|
|
]
|
|
const orderMultiplier = sortOrder === 'asc' ? 1 : -1
|
|
|
|
return temp.sort((a, b) => {
|
|
if (sortCol === 'name') {
|
|
return a.name.localeCompare(b.name) * orderMultiplier
|
|
}
|
|
if (sortCol === 'created_at') {
|
|
return (a.created_at - b.created_at) * orderMultiplier
|
|
}
|
|
if (sortCol === 'updated_at') {
|
|
return (a.updated_at - b.updated_at) * orderMultiplier
|
|
}
|
|
return 0
|
|
})
|
|
}, [functions, search, sort])
|
|
|
|
const hasFunctions = (functions ?? []).length > 0
|
|
|
|
return (
|
|
<PageContainer size="default">
|
|
<PageSection>
|
|
<PageSectionContent>
|
|
<div className="flex flex-col gap-6">
|
|
{isLoading && <GenericSkeletonLoader />}
|
|
{isError &&
|
|
(IS_PLATFORM ? (
|
|
<AlertError error={error} subject="Failed to retrieve edge functions" />
|
|
) : (
|
|
<Admonition type="warning" title="Failed to retrieve edge functions">
|
|
<p className="prose [&>code]:text-xs text-sm">
|
|
Edge functions could not be read from disk. The functions directory may be
|
|
missing, not mounted into Studio, or unreadable.
|
|
</p>
|
|
</Admonition>
|
|
))}
|
|
{isSuccess && (
|
|
<>
|
|
{hasFunctions ? (
|
|
<div className="space-y-4">
|
|
<div className="flex items-center gap-2">
|
|
<div className="flex items-center gap-2">
|
|
<div className="relative">
|
|
<ShortcutTooltip
|
|
shortcutId={SHORTCUT_IDS.LIST_PAGE_FOCUS_SEARCH}
|
|
label="Search functions"
|
|
side="bottom"
|
|
>
|
|
<Input
|
|
ref={searchInputRef}
|
|
placeholder="Search function names"
|
|
icon={<SearchIcon />}
|
|
size="tiny"
|
|
className="w-32 md:w-64"
|
|
value={search}
|
|
onChange={(event) => setSearch(event.target.value)}
|
|
onKeyDown={onSearchInputEscape(search, setSearch)}
|
|
actions={[
|
|
search && (
|
|
<Button
|
|
aria-label="Clear search"
|
|
key="clear"
|
|
size="tiny"
|
|
variant="text"
|
|
icon={<XIcon />}
|
|
onClick={() => setSearch('')}
|
|
className="p-0 h-5 w-5"
|
|
/>
|
|
),
|
|
]}
|
|
/>
|
|
</ShortcutTooltip>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<EdgeFunctionsSortDropdown value={sort} onChange={setSortQueryParam} />
|
|
</div>
|
|
<ShortcutTooltip
|
|
shortcutId={SHORTCUT_IDS.FUNCTIONS_LIST_REFRESH}
|
|
side="bottom"
|
|
>
|
|
<Button
|
|
icon={<RefreshCwIcon />}
|
|
loading={isFetching}
|
|
onClick={() => refetch()}
|
|
>
|
|
Refresh
|
|
</Button>
|
|
</ShortcutTooltip>
|
|
<span className="border-l border-default pl-2 text-xs text-foreground-light">
|
|
{search && filteredFunctions.length !== functions.length
|
|
? `Viewing ${filteredFunctions.length} of ${functions.length} functions in total`
|
|
: `Viewing ${functions.length} ${functions.length === 1 ? 'function' : 'functions'} in total`}
|
|
</span>
|
|
</div>
|
|
<Card>
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Name</TableHead>
|
|
<TableHead>URL</TableHead>
|
|
<TableHead className="hidden 2xl:table-cell">Created</TableHead>
|
|
<TableHead className="lg:table-cell">Updated</TableHead>
|
|
{showLastHourStats && (
|
|
<>
|
|
<TableHead className="lg:table-cell">Total requests (1h)</TableHead>
|
|
<TableHead className="lg:table-cell">5xx error rate (1h)</TableHead>
|
|
</>
|
|
)}
|
|
<TableHead className="hidden 2xl:table-cell">Deployments</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
|
|
<TableBody>
|
|
<>
|
|
{filteredFunctions.length > 0 ? (
|
|
filteredFunctions.map((item) => (
|
|
<EdgeFunctionsListItem key={item.id} function={item} />
|
|
))
|
|
) : (
|
|
<TableRowNoResults
|
|
colSpan={showLastHourStats ? 8 : 6}
|
|
search={search}
|
|
/>
|
|
)}
|
|
</>
|
|
</TableBody>
|
|
</Table>
|
|
</Card>
|
|
</div>
|
|
) : (
|
|
<FunctionsEmptyState />
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
</PageContainer>
|
|
)
|
|
}
|
|
|
|
const EdgeFunctionsIndexPageWrapper = ({ children }: PropsWithChildren) => (
|
|
<>
|
|
<div className="w-full min-h-full flex flex-col items-stretch">
|
|
<PageHeader size="default">
|
|
<PageHeaderMeta>
|
|
<PageHeaderSummary>
|
|
<PageHeaderTitle>Edge Functions</PageHeaderTitle>
|
|
<PageHeaderDescription>Run server-side logic close to your users</PageHeaderDescription>
|
|
</PageHeaderSummary>
|
|
<PageHeaderAside>
|
|
<DocsButton href={`${DOCS_URL}/guides/functions`} />
|
|
<Button asChild icon={<ExternalLinkIcon />}>
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
href="https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions"
|
|
>
|
|
Examples
|
|
</a>
|
|
</Button>
|
|
{IS_PLATFORM && <DeployEdgeFunctionButton />}
|
|
</PageHeaderAside>
|
|
</PageHeaderMeta>
|
|
</PageHeader>
|
|
|
|
{children}
|
|
</div>
|
|
<TerminalInstructionsDialog />
|
|
</>
|
|
)
|