Files
supabase/apps/studio/components/interfaces/EdgeFunctions
Drew McLellan b74d799c3d fix(studio): sort edge function files by name and select the entrypoint by default (#51796)
## Problem

The file list in an Edge Function's code view is shown in the order the
Management API returns it (roughly `created_at` order), not sorted by
name. Users expect name order, as in VS Code.

Resolves FE-2799

## Solution

- `formatFunctionBodyToFiles` now sorts files by their displayed name
before assigning ids, using a case-insensitive numeric comparison
(`file2` before `file10`). The list is flat, so there is no folder
grouping.
- Sorting would have changed which file opens first, so the code page
now selects the function's entrypoint file by default.
`getDefaultSelectedFileId` matches the entrypoint's basename, then falls
back to `index.ts`, then to the first file. The entrypoint isn't always
`index.ts`: the docs allow any `.ts`, `.js`, `.tsx`, `.jsx` or `.mjs`
file.
- The shared `FileExplorerAndEditor` and the new-function page are
unchanged. The code page passes the selection through the explorer's
existing `selectedFileId` / `setSelectedFileId` props.
- Files added or renamed in the editor keep their position until the
next load.

Before:
<img width="259" height="370" alt="Screenshot 2026-10-15 at 16 44 50"
src="https://github.com/user-attachments/assets/611fe2b9-5676-496a-85a9-e50032708c7a"
/>

After:
<img width="259" height="371" alt="Screenshot 2026-10-15 at 16 35 19"
src="https://github.com/user-attachments/assets/7f433661-ef34-4e3f-9143-afc67be1b30a"
/>


## Review instructions

1. Open an Edge Function's Code tab for a function with several files,
for example `utils.ts`, `index.ts`, `deno.json`.
2. Confirm the files are listed alphabetically and that `index.ts` is
selected on load.
3. For a function with a custom entrypoint (for example `main.ts`),
confirm that file is selected on load.
4. Run `pnpm test:studio -- components/interfaces/EdgeFunctions`.
2026-10-16 13:28:59 +08:00
..