Files
homebrewery-oidc/client/fork/git/GitNavItem.jsx
T
dev-bot BotandClaude Sonnet 5.5 448c67912f
CI / App (npm ci + Build, ESLint, Stylelint, Jest) (push) Successful in 3m25s
CI / Storage (mongo) (push) Successful in 1m24s
CI / Storage (postgres) (push) Successful in 1m13s
Image / Image bauen und pushen (push) Successful in 1m3s
feat(git): Git-Backend über HTTPS + PAT (ADR 0003, FLW-86) (#19)
Repositories gitConnections/brewGitLinks (Mongo/PG), Krypto, SSRF-Policy mit net.BlockList, git-Client ohne Arbeitskopie, Sync/Konflikte, /api/git/*, Client (Verbindungen, Git-Status, Konfliktdialog), Autosave 60 s für Git-Brews (F6), Tests und Doku.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Dev (Paperclip) <dev-bot@noreply.git.morlana.online>
2026-11-25 21:16:42 +00:00

83 lines
3.8 KiB
React

import './git.less';
import React, { useEffect, useState } from 'react';
import Nav from '@navbar/nav.jsx';
import { gitApi } from './gitApi.js';
// Git-Status im Editor-Navbar (ADR 0003 §7): Branch, Pfad, kurzer SHA, Fehler; Pull; Verknüpfen/Lösen.
const short = (sha)=>sha ? sha.slice(0, 7) : '';
const GitNavItem = ({ brew, lastSavedTime, onLinkedChange })=>{
const editId = brew?.editId;
const [status, setStatus] = useState(null); // null: unbekannt/aus
const [conns, setConns] = useState(null);
const [form, setForm] = useState({ connectionId: '', branch: '', path: '' });
const [busy, setBusy] = useState(false);
const [error, setError] = useState('');
const refresh = ()=>gitApi.status(editId).then(setStatus).catch(()=>setStatus(null));
useEffect(()=>{ if(editId) refresh(); }, [editId, lastSavedTime]);
// Verbindungen nur laden, wenn verknüpft werden soll (403/503: Git nicht verfügbar → Item bleibt unsichtbar)
useEffect(()=>{
if(status && !status.linked && conns === null) {
gitApi.listConnections().then((list)=>{ setConns(list); setForm((f)=>({ ...f, connectionId: list[0]?.id ?? '' })); }).catch(()=>setConns(false));
}
}, [status]);
useEffect(()=>{ onLinkedChange?.(!!status?.linked); }, [status?.linked]);
if(!editId || !status) return null;
const run = async (fn)=>{
setBusy(true); setError('');
try { await fn(); await refresh(); } catch (err) { setError(`${err.HBErrorCode ?? ''} ${err.message}`.trim()); }
setBusy(false);
};
if(status.linked) {
return (
<Nav.dropdown className='gitNav'>
<Nav.item icon={status.lastError ? 'fas fa-exclamation-triangle' : 'fab fa-git-alt'} className={status.lastError ? 'error' : ''}>
{status.branch}
</Nav.item>
<div className='gitDropdown'>
<div className='meta'>{status.connectionLabel}: {status.repoUrl}</div>
<div className='meta'>{status.branch} · {status.path}{status.lastCommitSha ? ` · ${short(status.lastCommitSha)}` : ''}</div>
{status.lastError === 'G04' && <div className='error'>Git nicht erreichbar, angezeigt wird der zuletzt gespeicherte Stand.</div>}
{status.lastError && status.lastError !== 'G04' && <div className='error'>Letzter Fehler: {status.lastError}</div>}
{error && <div className='error'>{error}</div>}
<button disabled={busy} onClick={()=>run(async ()=>{
if(!window.confirm('Remote-Stand laden? Ungespeicherte Änderungen im Editor gehen verloren.')) return;
await gitApi.pull(editId);
window.location.reload();
})}>Pull</button>
{status.isConnectionOwner && <button disabled={busy} onClick={()=>run(async ()=>{
if(window.confirm('Verknüpfung lösen? Der Brew bleibt erhalten, die Datei im Repository auch.')) await gitApi.unlinkBrew(editId);
})}>Verknüpfung lösen</button>}
</div>
</Nav.dropdown>
);
}
if(!conns || conns.length === 0) return null; // nichts zu verknüpfen (kein OIDC-Konto oder keine Verbindung)
return (
<Nav.dropdown className='gitNav'>
<Nav.item icon='fab fa-git-alt'>Git</Nav.item>
<div className='gitDropdown'>
<select value={form.connectionId} onChange={(e)=>setForm({ ...form, connectionId: e.target.value })}>
{conns.map((c)=><option key={c.id} value={c.id}>{c.label}</option>)}
</select>
<input placeholder='Branch (Standard der Verbindung)' value={form.branch} onChange={(e)=>setForm({ ...form, branch: e.target.value })} />
<input placeholder='Pfad, z. B. brews/mein-brew.md' value={form.path} onChange={(e)=>setForm({ ...form, path: e.target.value })} />
{error && <div className='error'>{error}</div>}
<button disabled={busy || !form.connectionId} onClick={()=>run(()=>gitApi.linkBrew(editId, { connectionId: form.connectionId, branch: form.branch || undefined, path: form.path || undefined }))}>
In Git speichern
</button>
</div>
</Nav.dropdown>
);
};
export default GitNavItem;