From 677ce748cd70e3ee7e3e540339ec79cfcfa064d2 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Sun, 8 Feb 2026 19:24:04 -0500 Subject: [PATCH] Improve git settings UI and credential management (#119) Remove collapsible sections and batch save, implement immediate credential CRUD with toast feedback. Add default hosts for credential types and improve responsive layout in credential dialog. --- .../settings/GitCredentialDialog.tsx | 68 ++-- .../src/components/settings/GitSettings.tsx | 311 +++++++++--------- 2 files changed, 195 insertions(+), 184 deletions(-) diff --git a/frontend/src/components/settings/GitCredentialDialog.tsx b/frontend/src/components/settings/GitCredentialDialog.tsx index 6d09b8fb..10676945 100644 --- a/frontend/src/components/settings/GitCredentialDialog.tsx +++ b/frontend/src/components/settings/GitCredentialDialog.tsx @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react' import { Loader2, Key, Lock, AlertTriangle } from 'lucide-react' import { Button } from '@/components/ui/button' -import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' @@ -50,7 +50,15 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is token: credential.type === 'pat' ? '' : credential.token }) } else { - setFormData({ name: '', host: '', type: 'pat', token: '', username: '', sshPrivateKey: '', passphrase: '' }) + setFormData({ + name: '', + host: 'github.com', + type: 'pat', + token: '', + username: '', + sshPrivateKey: '', + passphrase: '' + }) } } }, [open, credential]) @@ -151,7 +159,13 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is - + ) diff --git a/frontend/src/components/settings/GitSettings.tsx b/frontend/src/components/settings/GitSettings.tsx index 14c2e74e..eccc0316 100644 --- a/frontend/src/components/settings/GitSettings.tsx +++ b/frontend/src/components/settings/GitSettings.tsx @@ -1,6 +1,6 @@ import { useState, useEffect } from 'react' import { useSettings } from '@/hooks/useSettings' -import { Loader2, Plus, Trash2, Save, ChevronDown, ChevronRight, User, Key, Pencil } from 'lucide-react' +import { Loader2, Plus, Trash2, Save, User, Key, Pencil } from 'lucide-react' import { showToast } from '@/lib/toast' import { GitCredentialDialog } from './GitCredentialDialog' import { Label } from '@/components/ui/label' @@ -16,8 +16,7 @@ export function GitSettings() { const [hasChanges, setHasChanges] = useState(false) const [isCredentialDialogOpen, setIsCredentialDialogOpen] = useState(false) const [editingCredentialIndex, setEditingCredentialIndex] = useState(null) - const [identityExpanded, setIdentityExpanded] = useState(true) - const [credentialsExpanded, setCredentialsExpanded] = useState(true) + useEffect(() => { if (preferences) { @@ -27,12 +26,10 @@ export function GitSettings() { } }, [preferences]) - const checkForChanges = (newCredentials: GitCredential[], newIdentity: GitIdentity) => { - const currentCreds = JSON.stringify(preferences?.gitCredentials || []) - const newCreds = JSON.stringify(newCredentials) + const checkForIdentityChanges = (newIdentity: GitIdentity) => { const currentIdentity = preferences?.gitIdentity || { name: '', email: '' } const identityChanged = currentIdentity.name !== newIdentity.name || currentIdentity.email !== newIdentity.email - setHasChanges(currentCreds !== newCreds || identityChanged) + setHasChanges(identityChanged) } const openAddCredentialDialog = () => { @@ -68,19 +65,31 @@ export function GitSettings() { } setGitCredentials(newCredentials) - checkForChanges(newCredentials, gitIdentity) + + try { + await updateSettingsAsync({ gitCredentials: newCredentials, gitIdentity }) + showToast.success('Credential saved') + } catch { + showToast.error('Failed to save credential') + } } - const removeCredential = (index: number) => { + const removeCredential = async (index: number) => { const newCredentials = gitCredentials.filter((_, i) => i !== index) setGitCredentials(newCredentials) - checkForChanges(newCredentials, gitIdentity) + + try { + await updateSettingsAsync({ gitCredentials: newCredentials, gitIdentity }) + showToast.success('Credential deleted') + } catch { + showToast.error('Failed to delete credential') + } } const updateIdentity = (field: keyof GitIdentity, value: string) => { const newIdentity = { ...gitIdentity, [field]: value } setGitIdentity(newIdentity) - checkForChanges(gitCredentials, newIdentity) + checkForIdentityChanges(newIdentity) } const saveAll = async () => { @@ -132,171 +141,151 @@ export function GitSettings() { )} -
-
- +
+
+
+ + Identity + + {gitIdentity.name || gitIdentity.email ? `${gitIdentity.name || 'No name'} <${gitIdentity.email || 'No email'}>` : 'Not configured'} + +
- {identityExpanded && ( -
+

Author identity used for git commits. Leave empty to use system defaults.

-
-
- - updateIdentity('name', e.target.value)} - disabled={isSaving} - className="bg-background border-border text-foreground placeholder:text-muted-foreground" - /> -
-
- - updateIdentity('email', e.target.value)} - disabled={isSaving} - className="bg-background border-border text-foreground placeholder:text-muted-foreground" - /> -
-
+
+
+ + updateIdentity('name', e.target.value)} + disabled={isSaving} + className="bg-background border-border text-foreground placeholder:text-muted-foreground" + /> +
+
+ + updateIdentity('email', e.target.value)} + disabled={isSaving} + className="bg-background border-border text-foreground placeholder:text-muted-foreground" + /> +
+
+
+
+ +
+
+ + Credentials + + {gitCredentials.length} configured +
- )} -
-
- - - {credentialsExpanded && ( -
+

Credentials for cloning private repositories

- -
+ +
- {gitCredentials.length === 0 ? ( -
-

- No credentials configured. Click "Add" to add credentials. -

-
- ) : ( -
- - - - - - - - - - - {gitCredentials.map((cred, index) => ( - + {gitCredentials.length === 0 ? ( +
+

+ No credentials configured. Click "Add" to add credentials. +

+
+ ) : ( +
+
NameHostTypeActions
+ + + + + + + + + + {gitCredentials.map((cred, index) => ( + + + + - - - - - ))} - -
NameHostTypeActions
+
+ {cred.name || 'Unnamed'} +
{cred.host}
+
+
+ {cred.host} + + + {cred.type === 'ssh' ? 'SSH' : 'PAT'} + + -
- {cred.name || 'Unnamed'} -
{cred.host}
+
+ +
- {cred.host} - - - {cred.type === 'ssh' ? 'SSH' : 'PAT'} - - -
- - -
-
-
- )} -
- )} -
-
+ + ))} + + +
+ )} +
+
+ - + ) }