Skip to content

Commit 40d04ba

Browse files
authored
Merge pull request #176 from Open-VCS/ai-findings-autofix/Frontend-src-scripts-features-branches.ts
Potential fixes for 5 code quality findings
2 parents e8443c1 + 18b0ed6 commit 40d04ba

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

Frontend/src/scripts/features/branches.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import type { ConflictDetails, FileStatus } from '../types';
1818
import { openConflictsSummary } from './conflicts';
1919
import { getPluginContextMenuItems, runHook, runPluginAction } from '../plugins';
2020

21-
type Branch = { name: string; full_ref?: string; current?: boolean; kind?: { type?: string; remote?: string } };
21+
type BranchKind = { type?: string; remote?: string };
22+
type Branch = { name: string; full_ref?: string; current?: boolean; kind?: BranchKind };
2223

2324
const branchBtn = qs<HTMLButtonElement>('#branch-switch');
2425
const branchName = qs<HTMLElement>('#branch-name');
@@ -85,10 +86,11 @@ function renderBranches() {
8586
const kindType = b.kind?.type || '';
8687
const remoteFromName = b.name.includes('/') ? b.name.split('/')[0] : '';
8788
const remote = b.kind?.remote || remoteFromName || '';
89+
const remoteLabel = remote || 'remote';
8890
let kindLabel = '';
8991
if (kindType.toLowerCase() === 'local') kindLabel = '<span class="badge kind">Local</span>';
90-
else if (kindType.toLowerCase() === 'remote') kindLabel = `<span class="badge kind">Remote:${remote || 'remote'}</span>`;
91-
else if (remote) kindLabel = `<span class="badge kind">Remote:${remote || 'remote'}</span>`;
92+
else if (kindType.toLowerCase() === 'remote') kindLabel = `<span class="badge kind">Remote:${remoteLabel}</span>`;
93+
else if (remote) kindLabel = `<span class="badge kind">Remote:${remoteLabel}</span>`;
9294
return `
9395
<li role="option" data-branch="${b.name}" aria-selected="${b.current ? 'true' : 'false'}">
9496
<span class="label">
@@ -125,7 +127,11 @@ async function openBranchPopover() {
125127
branchPop.style.top = `${r.bottom + 6}px`;
126128
branchPop.hidden = false;
127129
branchBtn.setAttribute('aria-expanded', 'true');
128-
try { refreshOverlayScrollbarsFor(branchPop); } catch {}
130+
try {
131+
refreshOverlayScrollbarsFor(branchPop);
132+
} catch (err) {
133+
console.debug('Failed to refresh scrollbars for branch popover:', err);
134+
}
129135
setTimeout(() => branchFilter?.focus(), 0);
130136
}
131137

@@ -234,8 +240,8 @@ export function bindBranchUI() {
234240
items.push({ label: 'Set upstream…', action: async () => {
235241
await loadBranches();
236242
const remoteBranches = (state.branches || [])
237-
.filter((br: any) => (br?.kind?.type || '').toLowerCase() === 'remote')
238-
.map((br: any) => String(br?.name || '').trim())
243+
.filter((br: Branch) => (br?.kind?.type || '').toLowerCase() === 'remote')
244+
.map((br: Branch) => String(br?.name || '').trim())
239245
.filter((s: string) => !!s);
240246

241247
if (remoteBranches.length === 0) {
@@ -285,7 +291,10 @@ export function bindBranchUI() {
285291
notify(`Force-deleted '${name}'`);
286292
await loadBranches();
287293
await runHook('postBranchDelete', hookData);
288-
} catch (e) { console.error('Force delete failed:', e); notify('Force delete failed'); }
294+
} catch (e) {
295+
console.error('Force delete failed:', e);
296+
notify('Force delete failed');
297+
}
289298
}
290299
}});
291300
}

0 commit comments

Comments
 (0)