Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

refactor(ui): one repo-picker contract; give Modal a form mode

Juan Denisdf8f8eaafdc4
diff --git a/frontend/scripts/I18N_LITERAL_CEILING b/frontend/scripts/I18N_LITERAL_CEILING
index f4f7d043..a7c026f0 100644
--- a/frontend/scripts/I18N_LITERAL_CEILING
+++ b/frontend/scripts/I18N_LITERAL_CEILING
@@ -1 +1 @@
-8132
+8087
diff --git a/frontend/src/components/Modal.jsx b/frontend/src/components/Modal.jsx
index 4ea69d6d..6ea568ec 100644
--- a/frontend/src/components/Modal.jsx
+++ b/frontend/src/components/Modal.jsx
@@ -4,15 +4,35 @@ import { cn } from '@/lib/utils';
// Generic modal built on the Radix Dialog primitive. SCSS owns all geometry
// (styles/components/_ui.scss → .sk-modal*). `size` picks a max-width on
// >=sm screens; mobile is always near full-width.
+//
+// Form mode (plan 79 G2 / plan 76 F2): pass `onSubmit` and the body AND footer
+// are wrapped in one <form>. This exists because a submit button must live
+// inside the form it submits — without it, every modal with a form had to
+// bypass `footer` and hand-roll its own footer row inside the body, which is
+// why 28 files stopped using this prop. Form mode also gets Enter-to-submit
+// for free, which the hand-rolled footers did not have.
export default function Modal({
open,
onClose,
title,
children,
footer,
+ onSubmit,
className = '',
size = 'md',
}) {
+ const body = (
+ <>
+ <div className="sk-modal__body">{children}</div>
+ {footer && <div className="sk-modal__footer">{footer}</div>}
+ </>
+ );
+
+ const handleSubmit = (event) => {
+ event.preventDefault();
+ onSubmit(event);
+ };
+
return (
<Dialog open={open} onOpenChange={(v) => !v && onClose()}>
<DialogContent className={cn('sk-modal', `sk-modal--${size}`, className)}>
@@ -22,9 +42,9 @@ export default function Modal({
</div>
)}
- <div className="sk-modal__body">{children}</div>
-
- {footer && <div className="sk-modal__footer">{footer}</div>}
+ {onSubmit
+ ? <form className="sk-modal__form" onSubmit={handleSubmit} noValidate>{body}</form>
+ : body}
</DialogContent>
</Dialog>
);
diff --git a/frontend/src/components/git/BitbucketRepoPicker.jsx b/frontend/src/components/git/BitbucketRepoPicker.jsx
index 8b87f018..864abb1f 100644
--- a/frontend/src/components/git/BitbucketRepoPicker.jsx
+++ b/frontend/src/components/git/BitbucketRepoPicker.jsx
@@ -1,171 +1,11 @@
-import { useState, useEffect, useCallback } from 'react';
-import { SiBitbucket } from 'react-icons/si';
-import { Search, RefreshCw, Check } from 'lucide-react';
-import { Link } from 'react-router-dom';
-import api from '../../services/api';
-import { Button } from '@/components/ui/button';
-import { Input } from '@/components/ui/input';
-
-// One-click "Connect with Bitbucket" repo picker — mirrors the GitHub/GitLab
-// pickers. The backend payload already includes clone_url.
-function cloneUrl(repo) {
- return repo.clone_url || `https://bitbucket.org/${repo.full_name}.git`;
-}
-
-const BitbucketRepoPicker = ({ onPick }) => {
- const [status, setStatus] = useState(null); // { configured, connection }
- const [loading, setLoading] = useState(true);
- const [repos, setRepos] = useState([]);
- const [reposLoading, setReposLoading] = useState(false);
- const [search, setSearch] = useState('');
- const [selected, setSelected] = useState(null);
- const [branches, setBranches] = useState([]);
- const [branch, setBranch] = useState('');
-
- const connection = status?.connection;
- const configured = status?.configured;
-
- const loadStatus = useCallback(async () => {
- setLoading(true);
- try {
- setStatus(await api.getBitbucketSourceStatus());
- } catch {
- setStatus(null);
- } finally {
- setLoading(false);
- }
- }, []);
-
- useEffect(() => { loadStatus(); }, [loadStatus]);
-
- const loadRepos = useCallback(async (q = '') => {
- setReposLoading(true);
- try {
- const data = await api.listBitbucketRepositories({ search: q, perPage: 80 });
- setRepos(data.repos || []);
- } catch {
- setRepos([]);
- } finally {
- setReposLoading(false);
- }
- }, []);
-
- useEffect(() => { if (connection) loadRepos(); }, [connection, loadRepos]);
-
- useEffect(() => {
- if (!selected) return undefined;
- const b = selected.default_branch || 'main';
- setBranch(b);
- onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- let cancelled = false;
- api.listBitbucketBranches(selected.full_name)
- .then((data) => { if (!cancelled) setBranches(data.branches || []); })
- .catch(() => { if (!cancelled) setBranches([]); });
- return () => { cancelled = true; };
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selected]);
-
- function pickBranch(b) {
- setBranch(b);
- if (selected) onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- }
-
- async function connectBitbucket() {
- try {
- const redirectUri = `${window.location.origin}/connections/callback/bitbucket`;
- sessionStorage.setItem('sourceConnectionReturnTo', window.location.pathname + window.location.search);
- const { auth_url } = await api.startSourceConnection('bitbucket', redirectUri);
- window.location.href = auth_url;
- } catch {
- /* a retry surfaces the host's toast; nothing to do here */
- }
- }
-
- if (loading) return null;
-
- if (!configured) {
- return (
- <div className="git-connect__gh git-connect__gh--hint">
- <SiBitbucket size={15} aria-hidden="true" />
- <span>
- Set up the Bitbucket connection in <Link to="/settings/connections">Settings</Link> to
- pick a repo in one click instead of pasting a URL.
- </span>
- </div>
- );
- }
-
- if (!connection) {
- return (
- <div className="git-connect__gh git-connect__gh--connect">
- <SiBitbucket size={18} aria-hidden="true" />
- <div className="git-connect__gh-text">
- <strong>Connect with Bitbucket</strong>
- <span>Authorize once, then choose a repository instead of pasting a URL.</span>
- </div>
- <Button type="button" onClick={connectBitbucket}>
- <SiBitbucket size={15} /> Connect Bitbucket
- </Button>
- </div>
- );
- }
-
- return (
- <div className="git-connect__gh git-connect__gh--picker">
- <div className="git-connect__gh-account">
- {connection.avatar_url && <img src={connection.avatar_url} alt="" />}
- <span className="git-connect__gh-account-name">
- <strong>{connection.display_name || connection.provider_username}</strong>
- <small>@{connection.provider_username}</small>
- </span>
- <Button type="button" variant="outline" size="sm" onClick={() => loadRepos(search)}>
- <RefreshCw size={14} className={reposLoading ? 'spinning' : ''} /> Refresh
- </Button>
- </div>
-
- <div className="git-connect__gh-search">
- <Search size={15} aria-hidden="true" />
- <Input
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- placeholder="Search your repositories"
- onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); loadRepos(search); } }}
- />
- </div>
-
- <div className="git-connect__gh-list">
- {reposLoading && <div className="git-connect__gh-state">Loading repositories…</div>}
- {!reposLoading && repos.length === 0 && <div className="git-connect__gh-state">No repositories found.</div>}
- {!reposLoading && repos.map((repo) => (
- <button
- type="button"
- key={repo.id}
- className={`git-connect__gh-repo${selected?.id === repo.id ? ' is-active' : ''}`}
- onClick={() => setSelected(repo)}
- >
- <span className="git-connect__gh-repo-main">
- <strong>{repo.full_name}</strong>
- <small>{repo.description || 'No description'}</small>
- </span>
- <span className="git-connect__gh-repo-vis">{repo.private ? 'Private' : 'Public'}</span>
- {selected?.id === repo.id && <Check size={15} />}
- </button>
- ))}
- </div>
-
- {selected && branches.length > 0 && (
- <div className="git-connect__gh-branch">
- <label htmlFor="bb-branch">Branch</label>
- <select id="bb-branch" value={branch} onChange={(e) => pickBranch(e.target.value)}>
- {branches.map((b) => {
- const name = typeof b === 'string' ? b : b.name;
- return <option key={name} value={name}>{name}</option>;
- })}
- </select>
- </div>
- )}
- </div>
- );
-};
+import RepoPicker from './RepoPicker';
+import { bitbucketProvider } from './repoProviders';
+
+// Thin binding over the shared picker contract (plan 79 G1). The four
+// provider pickers were near-identical copies; the shape they shared now
+// lives in RepoPicker and the differences in repoProviders.
+const BitbucketRepoPicker = ({ onPick }) => (
+ <RepoPicker provider={bitbucketProvider} onPick={onPick} />
+);
export default BitbucketRepoPicker;
diff --git a/frontend/src/components/git/GiteaRepoPicker.jsx b/frontend/src/components/git/GiteaRepoPicker.jsx
index 3d491692..1d52db06 100644
--- a/frontend/src/components/git/GiteaRepoPicker.jsx
+++ b/frontend/src/components/git/GiteaRepoPicker.jsx
@@ -1,172 +1,11 @@
-import { useState, useEffect, useCallback } from 'react';
-import { SiGitea } from 'react-icons/si';
-import { Search, RefreshCw, Check, Server } from 'lucide-react';
-import { Link } from 'react-router-dom';
-import api from '../../services/api';
-import { Button } from '@/components/ui/button';
-import { Input } from '@/components/ui/input';
-
-// Local Gitea repo picker. Uses the ServerKit-managed Gitea instance when it is
-// installed and running. The backend's formatted repo payload already includes
-// clone_url, so we emit that directly.
-function cloneUrl(repo) {
- return repo.clone_url || repo.html_url || repo.ssh_url || '';
-}
-
-function splitFullName(fullName) {
- const parts = (fullName || '').split('/');
- return parts.length >= 2 ? [parts[0], parts.slice(1).join('/')] : [null, null];
-}
-
-const GiteaRepoPicker = ({ onPick }) => {
- const [status, setStatus] = useState(null);
- const [loading, setLoading] = useState(true);
- const [repos, setRepos] = useState([]);
- const [reposLoading, setReposLoading] = useState(false);
- const [search, setSearch] = useState('');
- const [selected, setSelected] = useState(null);
- const [branches, setBranches] = useState([]);
- const [branch, setBranch] = useState('');
-
- const installed = status?.installed;
- const running = status?.running;
-
- const loadStatus = useCallback(async () => {
- setLoading(true);
- try {
- const data = await api.getGiteaStatus();
- setStatus(data);
- } catch {
- setStatus(null);
- } finally {
- setLoading(false);
- }
- }, []);
-
- useEffect(() => { loadStatus(); }, [loadStatus]);
-
- const loadRepos = useCallback(async (q = '') => {
- setReposLoading(true);
- try {
- const data = await api.getGiteaRepositories(200);
- let list = data.repositories || data.repos || [];
- if (q.trim()) {
- const lower = q.trim().toLowerCase();
- list = list.filter((r) =>
- (r.full_name || r.name || '').toLowerCase().includes(lower)
- );
- }
- setRepos(list);
- } catch {
- setRepos([]);
- } finally {
- setReposLoading(false);
- }
- }, []);
-
- useEffect(() => { if (installed && running) loadRepos(); }, [installed, running, loadRepos]);
-
- useEffect(() => {
- if (!selected) return undefined;
- const [owner, repo] = splitFullName(selected.full_name);
- const b = selected.default_branch || 'main';
- setBranch(b);
- onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- let cancelled = false;
- if (owner && repo) {
- api.getGiteaBranches(owner, repo)
- .then((data) => { if (!cancelled) setBranches(data.branches || []); })
- .catch(() => { if (!cancelled) setBranches([]); });
- }
- return () => { cancelled = true; };
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selected]);
-
- function pickBranch(b) {
- setBranch(b);
- if (selected) onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- }
-
- if (loading) return null;
-
- if (!installed) {
- return (
- <div className="git-connect__gh git-connect__gh--hint">
- <SiGitea size={15} aria-hidden="true" />
- <span>
- Install the ServerKit Git server in <Link to="/git">Git</Link> to
- pick a local repository instead of pasting a URL.
- </span>
- </div>
- );
- }
-
- if (!running) {
- return (
- <div className="git-connect__gh git-connect__gh--hint">
- <Server size={15} aria-hidden="true" />
- <span>
- Your Gitea server is installed but not running. Start it from <Link to="/git">Git</Link>.
- </span>
- </div>
- );
- }
-
- return (
- <div className="git-connect__gh git-connect__gh--picker">
- <div className="git-connect__gh-account">
- <span className="git-connect__gh-account-name">
- <strong>Local Gitea</strong>
- <small>Repositories on this ServerKit instance</small>
- </span>
- <Button type="button" variant="outline" size="sm" onClick={() => loadRepos(search)}>
- <RefreshCw size={14} className={reposLoading ? 'spinning' : ''} /> Refresh
- </Button>
- </div>
-
- <div className="git-connect__gh-search">
- <Search size={15} aria-hidden="true" />
- <Input
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- placeholder="Search local repositories"
- onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); loadRepos(search); } }}
- />
- </div>
-
- <div className="git-connect__gh-list">
- {reposLoading && <div className="git-connect__gh-state">Loading repositories…</div>}
- {!reposLoading && repos.length === 0 && <div className="git-connect__gh-state">No local repositories found.</div>}
- {!reposLoading && repos.map((repo) => (
- <button
- type="button"
- key={repo.id}
- className={`git-connect__gh-repo${selected?.id === repo.id ? ' is-active' : ''}`}
- onClick={() => setSelected(repo)}
- >
- <span className="git-connect__gh-repo-main">
- <strong>{repo.full_name}</strong>
- <small>{repo.description || 'No description'}</small>
- </span>
- <span className="git-connect__gh-repo-vis">{repo.private ? 'Private' : 'Public'}</span>
- {selected?.id === repo.id && <Check size={15} />}
- </button>
- ))}
- </div>
-
- {selected && branches.length > 0 && (
- <div className="git-connect__gh-branch">
- <label htmlFor="gt-branch">Branch</label>
- <select id="gt-branch" value={branch} onChange={(e) => pickBranch(e.target.value)}>
- {branches.map((b) => {
- const name = typeof b === 'string' ? b : b.name;
- return <option key={name} value={name}>{name}</option>;
- })}
- </select>
- </div>
- )}
- </div>
- );
-};
+import RepoPicker from './RepoPicker';
+import { giteaProvider } from './repoProviders';
+
+// Thin binding over the shared picker contract (plan 79 G1). The four
+// provider pickers were near-identical copies; the shape they shared now
+// lives in RepoPicker and the differences in repoProviders.
+const GiteaRepoPicker = ({ onPick }) => (
+ <RepoPicker provider={giteaProvider} onPick={onPick} />
+);
export default GiteaRepoPicker;
diff --git a/frontend/src/components/git/GithubRepoPicker.jsx b/frontend/src/components/git/GithubRepoPicker.jsx
index 544d378c..e6e552d9 100644
--- a/frontend/src/components/git/GithubRepoPicker.jsx
+++ b/frontend/src/components/git/GithubRepoPicker.jsx
@@ -1,178 +1,11 @@
-import { useState, useEffect, useCallback } from 'react';
-import { SiGithub } from 'react-icons/si';
-import { Search, RefreshCw, Check } from 'lucide-react';
-import { Link } from 'react-router-dom';
-import api from '../../services/api';
-import { Button } from '@/components/ui/button';
-import { Input } from '@/components/ui/input';
-
-// One-click "Connect with GitHub" repo picker — the easy alternative to pasting a
-// clone URL. It reuses the SAME GitHub source-connection OAuth that the New
-// Service page already uses (no new backend), so any connect surface can offer
-// "authorize once, then pick a repo". It is purely a selection helper: it calls
-// onPick({ repoUrl, fullName, branch }) as the user chooses, and the host form
-// turns that into its own connect request.
-function cloneUrl(repo) {
- return repo.clone_url || `https://github.com/${repo.full_name}.git`;
-}
-
-const GithubRepoPicker = ({ onPick }) => {
- const [status, setStatus] = useState(null); // { configured, connection }
- const [loading, setLoading] = useState(true);
- const [repos, setRepos] = useState([]);
- const [reposLoading, setReposLoading] = useState(false);
- const [search, setSearch] = useState('');
- const [selected, setSelected] = useState(null);
- const [branches, setBranches] = useState([]);
- const [branch, setBranch] = useState('');
-
- const connection = status?.connection;
- const configured = status?.configured;
-
- const loadStatus = useCallback(async () => {
- setLoading(true);
- try {
- setStatus(await api.getGithubSourceStatus());
- } catch {
- setStatus(null);
- } finally {
- setLoading(false);
- }
- }, []);
-
- useEffect(() => { loadStatus(); }, [loadStatus]);
-
- const loadRepos = useCallback(async (q = '') => {
- setReposLoading(true);
- try {
- const data = await api.listGithubRepositories({ search: q, perPage: 80 });
- setRepos(data.repos || []);
- } catch {
- setRepos([]);
- } finally {
- setReposLoading(false);
- }
- }, []);
-
- useEffect(() => { if (connection) loadRepos(); }, [connection, loadRepos]);
-
- // Picking a repo defaults the branch, loads its branch list, and emits.
- useEffect(() => {
- if (!selected) return undefined;
- const b = selected.default_branch || 'main';
- setBranch(b);
- onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- let cancelled = false;
- api.listGithubBranches(selected.full_name)
- .then((data) => { if (!cancelled) setBranches(data.branches || []); })
- .catch(() => { if (!cancelled) setBranches([]); });
- return () => { cancelled = true; };
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selected]);
-
- function pickBranch(b) {
- setBranch(b);
- if (selected) onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- }
-
- async function connectGithub() {
- try {
- const redirectUri = `${window.location.origin}/connections/callback/github`;
- sessionStorage.setItem('sourceConnectionReturnTo', window.location.pathname + window.location.search);
- const { auth_url } = await api.startSourceConnection('github', redirectUri);
- window.location.href = auth_url;
- } catch {
- /* a retry surfaces the host's toast; nothing to do here */
- }
- }
-
- if (loading) return null;
-
- // No OAuth app configured — nudge to Settings, but never block the paste-URL
- // path the host form still renders below this.
- if (!configured) {
- return (
- <div className="git-connect__gh git-connect__gh--hint">
- <SiGithub size={15} aria-hidden="true" />
- <span>
- Set up the GitHub connection in <Link to="/settings/connections">Settings</Link> to
- pick a repo in one click instead of pasting a URL.
- </span>
- </div>
- );
- }
-
- if (!connection) {
- return (
- <div className="git-connect__gh git-connect__gh--connect">
- <SiGithub size={18} aria-hidden="true" />
- <div className="git-connect__gh-text">
- <strong>Connect with GitHub</strong>
- <span>Authorize once, then choose a repository instead of pasting a URL.</span>
- </div>
- <Button type="button" onClick={connectGithub}>
- <SiGithub size={15} /> Connect GitHub
- </Button>
- </div>
- );
- }
-
- return (
- <div className="git-connect__gh git-connect__gh--picker">
- <div className="git-connect__gh-account">
- {connection.avatar_url && <img src={connection.avatar_url} alt="" />}
- <span className="git-connect__gh-account-name">
- <strong>{connection.display_name || connection.provider_username}</strong>
- <small>@{connection.provider_username}</small>
- </span>
- <Button type="button" variant="outline" size="sm" onClick={() => loadRepos(search)}>
- <RefreshCw size={14} className={reposLoading ? 'spinning' : ''} /> Refresh
- </Button>
- </div>
-
- <div className="git-connect__gh-search">
- <Search size={15} aria-hidden="true" />
- <Input
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- placeholder="Search your repositories"
- onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); loadRepos(search); } }}
- />
- </div>
-
- <div className="git-connect__gh-list">
- {reposLoading && <div className="git-connect__gh-state">Loading repositories…</div>}
- {!reposLoading && repos.length === 0 && <div className="git-connect__gh-state">No repositories found.</div>}
- {!reposLoading && repos.map((repo) => (
- <button
- type="button"
- key={repo.id}
- className={`git-connect__gh-repo${selected?.id === repo.id ? ' is-active' : ''}`}
- onClick={() => setSelected(repo)}
- >
- <span className="git-connect__gh-repo-main">
- <strong>{repo.full_name}</strong>
- <small>{repo.description || repo.language || 'No description'}</small>
- </span>
- <span className="git-connect__gh-repo-vis">{repo.private ? 'Private' : 'Public'}</span>
- {selected?.id === repo.id && <Check size={15} />}
- </button>
- ))}
- </div>
-
- {selected && branches.length > 0 && (
- <div className="git-connect__gh-branch">
- <label htmlFor="gh-branch">Branch</label>
- <select id="gh-branch" value={branch} onChange={(e) => pickBranch(e.target.value)}>
- {branches.map((b) => {
- const name = typeof b === 'string' ? b : b.name;
- return <option key={name} value={name}>{name}</option>;
- })}
- </select>
- </div>
- )}
- </div>
- );
-};
+import RepoPicker from './RepoPicker';
+import { githubProvider } from './repoProviders';
+
+// Thin binding over the shared picker contract (plan 79 G1). The four
+// provider pickers were near-identical copies; the shape they shared now
+// lives in RepoPicker and the differences in repoProviders.
+const GithubRepoPicker = ({ onPick }) => (
+ <RepoPicker provider={githubProvider} onPick={onPick} />
+);
export default GithubRepoPicker;
diff --git a/frontend/src/components/git/GitlabRepoPicker.jsx b/frontend/src/components/git/GitlabRepoPicker.jsx
index 63e00963..f3f4a298 100644
--- a/frontend/src/components/git/GitlabRepoPicker.jsx
+++ b/frontend/src/components/git/GitlabRepoPicker.jsx
@@ -1,172 +1,11 @@
-import { useState, useEffect, useCallback } from 'react';
-import { SiGitlab } from 'react-icons/si';
-import { Search, RefreshCw, Check } from 'lucide-react';
-import { Link } from 'react-router-dom';
-import api from '../../services/api';
-import { Button } from '@/components/ui/button';
-import { Input } from '@/components/ui/input';
-
-// One-click "Connect with GitLab" repo picker — mirrors GithubRepoPicker but uses
-// the GitLab source-connection OAuth flow. GitLab's API payload does not include
-// a clone_url, so we build one from the full_name.
-function cloneUrl(repo) {
- return `https://gitlab.com/${repo.full_name}.git`;
-}
-
-const GitlabRepoPicker = ({ onPick }) => {
- const [status, setStatus] = useState(null); // { configured, connection }
- const [loading, setLoading] = useState(true);
- const [repos, setRepos] = useState([]);
- const [reposLoading, setReposLoading] = useState(false);
- const [search, setSearch] = useState('');
- const [selected, setSelected] = useState(null);
- const [branches, setBranches] = useState([]);
- const [branch, setBranch] = useState('');
-
- const connection = status?.connection;
- const configured = status?.configured;
-
- const loadStatus = useCallback(async () => {
- setLoading(true);
- try {
- setStatus(await api.getGitlabSourceStatus());
- } catch {
- setStatus(null);
- } finally {
- setLoading(false);
- }
- }, []);
-
- useEffect(() => { loadStatus(); }, [loadStatus]);
-
- const loadRepos = useCallback(async (q = '') => {
- setReposLoading(true);
- try {
- const data = await api.listGitlabRepositories({ search: q, perPage: 80 });
- setRepos(data.repos || []);
- } catch {
- setRepos([]);
- } finally {
- setReposLoading(false);
- }
- }, []);
-
- useEffect(() => { if (connection) loadRepos(); }, [connection, loadRepos]);
-
- useEffect(() => {
- if (!selected) return undefined;
- const b = selected.default_branch || 'main';
- setBranch(b);
- onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- let cancelled = false;
- api.listGitlabBranches(selected.full_name)
- .then((data) => { if (!cancelled) setBranches(data.branches || []); })
- .catch(() => { if (!cancelled) setBranches([]); });
- return () => { cancelled = true; };
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selected]);
-
- function pickBranch(b) {
- setBranch(b);
- if (selected) onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
- }
-
- async function connectGitlab() {
- try {
- const redirectUri = `${window.location.origin}/connections/callback/gitlab`;
- sessionStorage.setItem('sourceConnectionReturnTo', window.location.pathname + window.location.search);
- const { auth_url } = await api.startSourceConnection('gitlab', redirectUri);
- window.location.href = auth_url;
- } catch {
- /* a retry surfaces the host's toast; nothing to do here */
- }
- }
-
- if (loading) return null;
-
- if (!configured) {
- return (
- <div className="git-connect__gh git-connect__gh--hint">
- <SiGitlab size={15} aria-hidden="true" />
- <span>
- Set up the GitLab connection in <Link to="/settings/connections">Settings</Link> to
- pick a repo in one click instead of pasting a URL.
- </span>
- </div>
- );
- }
-
- if (!connection) {
- return (
- <div className="git-connect__gh git-connect__gh--connect">
- <SiGitlab size={18} aria-hidden="true" />
- <div className="git-connect__gh-text">
- <strong>Connect with GitLab</strong>
- <span>Authorize once, then choose a repository instead of pasting a URL.</span>
- </div>
- <Button type="button" onClick={connectGitlab}>
- <SiGitlab size={15} /> Connect GitLab
- </Button>
- </div>
- );
- }
-
- return (
- <div className="git-connect__gh git-connect__gh--picker">
- <div className="git-connect__gh-account">
- {connection.avatar_url && <img src={connection.avatar_url} alt="" />}
- <span className="git-connect__gh-account-name">
- <strong>{connection.display_name || connection.provider_username}</strong>
- <small>@{connection.provider_username}</small>
- </span>
- <Button type="button" variant="outline" size="sm" onClick={() => loadRepos(search)}>
- <RefreshCw size={14} className={reposLoading ? 'spinning' : ''} /> Refresh
- </Button>
- </div>
-
- <div className="git-connect__gh-search">
- <Search size={15} aria-hidden="true" />
- <Input
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- placeholder="Search your repositories"
- onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); loadRepos(search); } }}
- />
- </div>
-
- <div className="git-connect__gh-list">
- {reposLoading && <div className="git-connect__gh-state">Loading repositories…</div>}
- {!reposLoading && repos.length === 0 && <div className="git-connect__gh-state">No repositories found.</div>}
- {!reposLoading && repos.map((repo) => (
- <button
- type="button"
- key={repo.id}
- className={`git-connect__gh-repo${selected?.id === repo.id ? ' is-active' : ''}`}
- onClick={() => setSelected(repo)}
- >
- <span className="git-connect__gh-repo-main">
- <strong>{repo.full_name}</strong>
- <small>{repo.description || repo.language || 'No description'}</small>
- </span>
- <span className="git-connect__gh-repo-vis">{repo.private ? 'Private' : 'Public'}</span>
- {selected?.id === repo.id && <Check size={15} />}
- </button>
- ))}
- </div>
-
- {selected && branches.length > 0 && (
- <div className="git-connect__gh-branch">
- <label htmlFor="gl-branch">Branch</label>
- <select id="gl-branch" value={branch} onChange={(e) => pickBranch(e.target.value)}>
- {branches.map((b) => {
- const name = typeof b === 'string' ? b : b.name;
- return <option key={name} value={name}>{name}</option>;
- })}
- </select>
- </div>
- )}
- </div>
- );
-};
+import RepoPicker from './RepoPicker';
+import { gitlabProvider } from './repoProviders';
+
+// Thin binding over the shared picker contract (plan 79 G1). The four
+// provider pickers were near-identical copies; the shape they shared now
+// lives in RepoPicker and the differences in repoProviders.
+const GitlabRepoPicker = ({ onPick }) => (
+ <RepoPicker provider={gitlabProvider} onPick={onPick} />
+);
export default GitlabRepoPicker;
diff --git a/frontend/src/components/git/RepoPicker.jsx b/frontend/src/components/git/RepoPicker.jsx
new file mode 100644
index 00000000..3e491c61
--- /dev/null
+++ b/frontend/src/components/git/RepoPicker.jsx
@@ -0,0 +1,215 @@
+import { useCallback, useEffect, useState } from 'react';
+import { RefreshCw, Search, Check } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+
+/**
+ * One repo picker for every git provider (plan 79 G1).
+ *
+ * Four near-identical components used to exist — GitHub, GitLab, Gitea and
+ * Bitbucket — differing in which API functions they called, one URL shape, and
+ * the provider's name in six strings. That is ~700 lines carrying four copies
+ * of the same search box, the same "Loading repositories…", the same empty
+ * state and the same branch selector.
+ *
+ * The copy duplication is the part that matters here: every one of those
+ * strings would otherwise need translating four times, and drift between them
+ * is invisible until someone reads all four files side by side.
+ *
+ * A provider supplies behaviour, not markup:
+ *
+ * {
+ * id, name, Icon,
+ * cloneUrl(repo),
+ * getStatus(), listRepos(search), listBranches(fullName),
+ * isReady(status), // when can we show the list?
+ * account(status, t), // { name, detail, avatarUrl }
+ * unavailable(status, t), // what to render when not ready
+ * connect?(), // OAuth start — omitted for local providers
+ * }
+ *
+ * It stays a selection helper: it calls onPick({ repoUrl, fullName, branch })
+ * as the user chooses and the host form turns that into its own request.
+ */
+const RepoPicker = ({ provider, onPick }) => {
+ const { t } = useTranslation();
+ const [status, setStatus] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [repos, setRepos] = useState([]);
+ const [reposLoading, setReposLoading] = useState(false);
+ const [search, setSearch] = useState('');
+ const [selected, setSelected] = useState(null);
+ const [branches, setBranches] = useState([]);
+ const [branch, setBranch] = useState('');
+
+ const { Icon } = provider;
+ const ready = provider.isReady(status);
+
+ const loadStatus = useCallback(async () => {
+ setLoading(true);
+ try {
+ setStatus(await provider.getStatus());
+ } catch {
+ setStatus(null);
+ } finally {
+ setLoading(false);
+ }
+ }, [provider]);
+
+ useEffect(() => { loadStatus(); }, [loadStatus]);
+
+ const loadRepos = useCallback(async (query = '') => {
+ setReposLoading(true);
+ try {
+ setRepos(await provider.listRepos(query));
+ } catch {
+ setRepos([]);
+ } finally {
+ setReposLoading(false);
+ }
+ }, [provider]);
+
+ useEffect(() => { if (ready) loadRepos(); }, [ready, loadRepos]);
+
+ // Picking a repo defaults the branch, loads its branch list, and emits.
+ useEffect(() => {
+ if (!selected) return undefined;
+ const next = selected.default_branch || 'main';
+ setBranch(next);
+ onPick?.({
+ repoUrl: provider.cloneUrl(selected),
+ fullName: selected.full_name,
+ branch: next,
+ });
+ let cancelled = false;
+ provider.listBranches(selected.full_name)
+ .then((list) => { if (!cancelled) setBranches(list); })
+ .catch(() => { if (!cancelled) setBranches([]); });
+ return () => { cancelled = true; };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [selected]);
+
+ function pickBranch(next) {
+ setBranch(next);
+ if (selected) {
+ onPick?.({
+ repoUrl: provider.cloneUrl(selected),
+ fullName: selected.full_name,
+ branch: next,
+ });
+ }
+ }
+
+ if (loading) return null;
+
+ if (!ready) {
+ // Never blocks the paste-a-URL path the host form still renders.
+ const blocked = provider.unavailable(status, t);
+ if (!blocked) return null;
+ if (blocked.action) {
+ return (
+ <div className="git-connect__gh git-connect__gh--connect">
+ <Icon size={18} aria-hidden="true" />
+ <div className="git-connect__gh-text">
+ <strong>{blocked.title}</strong>
+ <span>{blocked.message}</span>
+ </div>
+ <Button type="button" onClick={blocked.action.onClick}>
+ <Icon size={15} /> {blocked.action.label}
+ </Button>
+ </div>
+ );
+ }
+ return (
+ <div className="git-connect__gh git-connect__gh--hint">
+ <Icon size={15} aria-hidden="true" />
+ <span>{blocked.message}</span>
+ </div>
+ );
+ }
+
+ const account = provider.account(status, t);
+
+ return (
+ <div className="git-connect__gh git-connect__gh--picker">
+ <div className="git-connect__gh-account">
+ {account.avatarUrl && <img src={account.avatarUrl} alt="" />}
+ <span className="git-connect__gh-account-name">
+ <strong>{account.name}</strong>
+ <small>{account.detail}</small>
+ </span>
+ <Button type="button" variant="outline" size="sm" onClick={() => loadRepos(search)}>
+ <RefreshCw size={14} className={reposLoading ? 'spinning' : ''} />
+ {' '}{t('common.actions.refresh', 'Refresh')}
+ </Button>
+ </div>
+
+ <div className="git-connect__gh-search">
+ <Search size={15} aria-hidden="true" />
+ <Input
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ placeholder={t('git.picker.search', 'Search your repositories')}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') { e.preventDefault(); loadRepos(search); }
+ }}
+ />
+ </div>
+
+ <div className="git-connect__gh-list">
+ {reposLoading && (
+ <div className="git-connect__gh-state">
+ {t('git.picker.loading', 'Loading repositories…')}
+ </div>
+ )}
+ {!reposLoading && repos.length === 0 && (
+ <div className="git-connect__gh-state">
+ {t('git.picker.empty', 'No repositories found.')}
+ </div>
+ )}
+ {!reposLoading && repos.map((repo) => (
+ <button
+ type="button"
+ key={repo.id}
+ className={`git-connect__gh-repo${selected?.id === repo.id ? ' is-active' : ''}`}
+ onClick={() => setSelected(repo)}
+ >
+ <span className="git-connect__gh-repo-main">
+ <strong>{repo.full_name}</strong>
+ <small>
+ {repo.description || repo.language
+ || t('git.picker.noDescription', 'No description')}
+ </small>
+ </span>
+ <span className="git-connect__gh-repo-vis">
+ {repo.private
+ ? t('git.picker.private', 'Private')
+ : t('git.picker.public', 'Public')}
+ </span>
+ {selected?.id === repo.id && <Check size={15} />}
+ </button>
+ ))}
+ </div>
+
+ {selected && branches.length > 0 && (
+ <div className="git-connect__gh-branch">
+ <label htmlFor={`${provider.id}-branch`}>
+ {t('git.picker.branch', 'Branch')}
+ </label>
+ <select
+ id={`${provider.id}-branch`}
+ value={branch}
+ onChange={(e) => pickBranch(e.target.value)}
+ >
+ {branches.map((name) => (
+ <option key={name} value={name}>{name}</option>
+ ))}
+ </select>
+ </div>
+ )}
+ </div>
+ );
+};
+
+export default RepoPicker;
diff --git a/frontend/src/components/git/repoProviders.jsx b/frontend/src/components/git/repoProviders.jsx
new file mode 100644
index 00000000..fb7779d6
--- /dev/null
+++ b/frontend/src/components/git/repoProviders.jsx
@@ -0,0 +1,167 @@
+import { Link } from 'react-router-dom';
+import { Trans } from 'react-i18next';
+import { SiGithub, SiGitlab, SiGitea, SiBitbucket } from 'react-icons/si';
+import api from '../../services/api';
+
+// Provider behaviour for RepoPicker (plan 79 G1). Everything visual lives in
+// the component; these describe only what actually differs between providers —
+// which API to call, how a clone URL is shaped, and what to say when the
+// provider is not usable yet.
+
+const branchNames = (data) => (data.branches || []).map((b) => (typeof b === 'string' ? b : b.name));
+
+/** OAuth-backed hosted providers: GitHub, GitLab, Bitbucket. */
+function oauthProvider({ id, name, Icon, api: calls, cloneUrl }) {
+ return {
+ id,
+ name,
+ Icon,
+ cloneUrl,
+ getStatus: calls.status,
+ listRepos: async (search) => (await calls.repos({ search, perPage: 80 })).repos || [],
+ listBranches: async (fullName) => branchNames(await calls.branches(fullName)),
+
+ isReady: (status) => Boolean(status?.configured && status?.connection),
+
+ account: (status) => ({
+ name: status.connection.display_name || status.connection.provider_username,
+ detail: `@${status.connection.provider_username}`,
+ avatarUrl: status.connection.avatar_url,
+ }),
+
+ unavailable: (status, t) => {
+ if (!status?.configured) {
+ // One key with the link inside it, not a prefix/suffix pair:
+ // the link lands in a different place in the sentence in other
+ // languages, and split keys cannot be reordered by a translator.
+ return {
+ message: (
+ <Trans
+ i18nKey="git.picker.notConfigured"
+ defaults="Set up the {{provider}} connection in <0>Settings</0> to pick a repo in one click instead of pasting a URL."
+ values={{ provider: name }}
+ components={[<Link key="settings" to="/settings/connections" />]}
+ />
+ ),
+ };
+ }
+ return {
+ title: t('git.picker.connectTitle', 'Connect with {{provider}}', { provider: name }),
+ message: t('git.picker.connectMessage',
+ 'Authorize once, then choose a repository instead of pasting a URL.'),
+ action: {
+ label: t('git.picker.connectAction', 'Connect {{provider}}', { provider: name }),
+ onClick: async () => {
+ try {
+ const redirectUri = `${window.location.origin}/connections/callback/${id}`;
+ sessionStorage.setItem(
+ 'sourceConnectionReturnTo',
+ window.location.pathname + window.location.search,
+ );
+ const { auth_url } = await api.startSourceConnection(id, redirectUri);
+ window.location.href = auth_url;
+ } catch {
+ /* a retry surfaces the host's toast; nothing to do here */
+ }
+ },
+ },
+ };
+ },
+ };
+}
+
+export const githubProvider = oauthProvider({
+ id: 'github',
+ name: 'GitHub',
+ Icon: SiGithub,
+ cloneUrl: (repo) => repo.clone_url || `https://github.com/${repo.full_name}.git`,
+ api: {
+ status: () => api.getGithubSourceStatus(),
+ repos: (params) => api.listGithubRepositories(params),
+ branches: (fullName) => api.listGithubBranches(fullName),
+ },
+});
+
+export const gitlabProvider = oauthProvider({
+ id: 'gitlab',
+ name: 'GitLab',
+ Icon: SiGitlab,
+ // GitLab's payload carries no clone_url, so it is built from full_name.
+ cloneUrl: (repo) => `https://gitlab.com/${repo.full_name}.git`,
+ api: {
+ status: () => api.getGitlabSourceStatus(),
+ repos: (params) => api.listGitlabRepositories(params),
+ branches: (fullName) => api.listGitlabBranches(fullName),
+ },
+});
+
+export const bitbucketProvider = oauthProvider({
+ id: 'bitbucket',
+ name: 'Bitbucket',
+ Icon: SiBitbucket,
+ cloneUrl: (repo) => repo.clone_url || `https://bitbucket.org/${repo.full_name}.git`,
+ api: {
+ status: () => api.getBitbucketSourceStatus(),
+ repos: (params) => api.listBitbucketRepositories(params),
+ branches: (fullName) => api.listBitbucketBranches(fullName),
+ },
+});
+
+/**
+ * Gitea is the local one: no OAuth, so readiness is installed+running rather
+ * than configured+connected, and the branch API takes owner and repo
+ * separately. It is why the contract asks providers for `isReady` instead of
+ * assuming a connection object.
+ */
+export const giteaProvider = {
+ id: 'gitea',
+ name: 'Gitea',
+ Icon: SiGitea,
+ cloneUrl: (repo) => repo.clone_url || repo.html_url || repo.ssh_url || '',
+
+ getStatus: () => api.getGiteaStatus(),
+
+ listRepos: async (search) => {
+ const data = await api.getGiteaRepositories(200);
+ const list = data.repositories || data.repos || [];
+ const query = search.trim().toLowerCase();
+ if (!query) return list;
+ return list.filter((repo) => (repo.full_name || repo.name || '').toLowerCase().includes(query));
+ },
+
+ listBranches: async (fullName) => {
+ const parts = (fullName || '').split('/');
+ if (parts.length < 2) return [];
+ return branchNames(await api.getGiteaBranches(parts[0], parts.slice(1).join('/')));
+ },
+
+ isReady: (status) => Boolean(status?.installed && status?.running),
+
+ account: (status, t) => ({
+ name: t('git.picker.giteaAccount', 'Local Gitea'),
+ detail: t('git.picker.giteaDetail', 'Repositories on this ServerKit instance'),
+ }),
+
+ unavailable: (status) => {
+ if (!status?.installed) {
+ return {
+ message: (
+ <Trans
+ i18nKey="git.picker.giteaNotInstalled"
+ defaults="Install the ServerKit Git server in <0>Git</0> to pick a local repository instead of pasting a URL."
+ components={[<Link key="git" to="/git" />]}
+ />
+ ),
+ };
+ }
+ return {
+ message: (
+ <Trans
+ i18nKey="git.picker.giteaNotRunning"
+ defaults="Your Gitea server is installed but not running. Start it from <0>Git</0>."
+ components={[<Link key="git" to="/git" />]}
+ />
+ ),
+ };
+ },
+};
diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json
index 4f703a5f..363edd66 100644
--- a/frontend/src/i18n/locales/en.json
+++ b/frontend/src/i18n/locales/en.json
@@ -2,6 +2,7 @@
"common": {
"actions": {
"logOut": "Log out",
+ "refresh": "Refresh",
"retry": "Retry",
"tryAgain": "Try again"
},
@@ -36,6 +37,25 @@
"minutesShort": "{{count}}m"
}
},
+ "git": {
+ "picker": {
+ "branch": "Branch",
+ "connectAction": "Connect {{provider}}",
+ "connectMessage": "Authorize once, then choose a repository instead of pasting a URL.",
+ "connectTitle": "Connect with {{provider}}",
+ "empty": "No repositories found.",
+ "giteaAccount": "Local Gitea",
+ "giteaDetail": "Repositories on this ServerKit instance",
+ "giteaNotInstalled": "Install the ServerKit Git server in <0>Git</0> to pick a local repository instead of pasting a URL.",
+ "giteaNotRunning": "Your Gitea server is installed but not running. Start it from <0>Git</0>.",
+ "loading": "Loading repositories…",
+ "noDescription": "No description",
+ "notConfigured": "Set up the {{provider}} connection in <0>Settings</0> to pick a repo in one click instead of pasting a URL.",
+ "private": "Private",
+ "public": "Public",
+ "search": "Search your repositories"
+ }
+ },
"nav": {
"accountMenu": "Account and preferences",
"allSettings": "All Settings",
diff --git a/frontend/src/i18n/locales/es.json b/frontend/src/i18n/locales/es.json
index 2ad76d9b..3c94179f 100644
--- a/frontend/src/i18n/locales/es.json
+++ b/frontend/src/i18n/locales/es.json
@@ -2,6 +2,7 @@
"common": {
"actions": {
"logOut": "Cerrar sesión",
+ "refresh": "Actualizar",
"retry": "Reintentar",
"tryAgain": "Reintentar"
},
@@ -36,6 +37,25 @@
"minutesShort": "{{count}} min"
}
},
+ "git": {
+ "picker": {
+ "branch": "Rama",
+ "connectAction": "Conectar {{provider}}",
+ "connectMessage": "Autoriza una vez y elige un repositorio en lugar de pegar una URL.",
+ "connectTitle": "Conectar con {{provider}}",
+ "empty": "No se encontraron repositorios.",
+ "giteaAccount": "Gitea local",
+ "giteaDetail": "Repositorios en esta instancia de ServerKit",
+ "giteaNotInstalled": "Instala el servidor Git de ServerKit en <0>Git</0> para elegir un repositorio local en lugar de pegar una URL.",
+ "giteaNotRunning": "Tu servidor Gitea está instalado pero no se está ejecutando. Inícialo desde <0>Git</0>.",
+ "loading": "Cargando repositorios…",
+ "noDescription": "Sin descripción",
+ "notConfigured": "Configura la conexión con {{provider}} en <0>Ajustes</0> para elegir un repositorio con un clic en lugar de pegar una URL.",
+ "private": "Privado",
+ "public": "Público",
+ "search": "Busca en tus repositorios"
+ }
+ },
"nav": {
"accountMenu": "Cuenta y preferencias",
"allSettings": "Todos los ajustes",
diff --git a/frontend/src/styles/components/_ui.scss b/frontend/src/styles/components/_ui.scss
index 6a3e7f97..bdd95d9c 100644
--- a/frontend/src/styles/components/_ui.scss
+++ b/frontend/src/styles/components/_ui.scss
@@ -889,6 +889,17 @@
line-height: 1.5;
}
+// Form mode (Modal `onSubmit`) wraps body+footer so a submit button can live
+// inside the form it submits. It has to BE the flex column, or the body's
+// `flex: 1` would resolve against the form rather than the modal and the
+// footer would stop pinning to the bottom.
+.sk-modal__form {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-height: 0;
+}
+
.sk-modal__body {
flex: 1;
min-height: 0;