import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useState } from 'react'; import { Button } from '#/components/atoms/button.jsx'; import { Input } from '#/components/atoms/input.jsx'; import { Label } from '#/components/atoms/label.jsx'; import { Textarea } from '#/components/atoms/textarea.jsx'; import { OptionRow } from '#/components/molecules/option-row.jsx'; import { PageNotice } from '#/components/molecules/page-notice.jsx'; import { RefSelect } from '#/components/molecules/ref-select.jsx'; import { Screen } from '#/components/molecules/screen.jsx'; import { SettingsPanel } from '#/components/molecules/settings-panel.jsx'; import { account, branchRefs, defaultRef, loadRepos, repoRecord, shortRef, } from '#/lib/git.js'; import { resolveIdentity } from '#/lib/identity.js'; import { useNavigate } from '#/lib/navigation.jsx'; import { useSession } from '#/lib/session.jsx'; import { deleteRepo, packageKey, publishedPackages, renameRepo, updateSettings, } from '#/lib/settings.js'; /** How each registry reads beside a package name. */ const REGISTRY_LABELS = { npm: 'npm package', oci: 'container image' }; /** The branch names one repository record holds. */ const branchesOf = (record) => branchRefs(record).map((ref) => shortRef(ref.name)); /** * What the repository is, and which branch a visitor lands on. Both are * fields of the repository record, which every push rewrites, so the server * reads the record and patches the two rather than replacing it. */ function GeneralPanel({ record, write }) { const branches = branchesOf(record); // The branch a visitor lands on today: the one the record names, or main // where it names none. A repository whose named branch is gone falls back // to the first it has, so the picker never shows a branch that is not // there. const landing = branches.includes(defaultRef(record)) ? defaultRef(record) : (branches[0] ?? ''); const [description, setDescription] = useState(record.description ?? ''); const [defaultBranch, setDefaultBranch] = useState(landing); const save = () => write({ description: description.trim(), // An empty repository has no branch to name, and sending an empty one // would clear the branch a first push is about to create. ...(branches.length > 0 ? { defaultBranch } : {}), }); return (