Skip to content

Commit 3463fca

Browse files
authored
Merge pull request #39 from beNative/codex/add-hints-to-repo-card-dropdowns
Add tooltips to branch controls on repository cards
2 parents c39764e + f404e1b commit 3463fca

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

components/RepositoryCard.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,28 @@ const BranchSwitcher: React.FC<{
8484
const [dropdownStyle, setDropdownStyle] = useState<React.CSSProperties>({});
8585
const [isModalOpen, setIsModalOpen] = useState(false);
8686
const [isRefreshingBranches, setIsRefreshingBranches] = useState(false);
87-
87+
88+
const localBranches = branchInfo?.local ?? [];
89+
const remoteBranches = branchInfo?.remote ?? [];
90+
const currentBranch = branchInfo?.current ?? '';
91+
92+
const remoteBranchesToOffer = remoteBranches.filter(rBranch => {
93+
const localEquivalent = rBranch.split('/').slice(1).join('/');
94+
return !localBranches.includes(localEquivalent);
95+
});
96+
97+
const otherLocalBranches = localBranches.filter(b => b !== currentBranch);
98+
const hasOptions = otherLocalBranches.length > 0 || remoteBranchesToOffer.length > 0;
99+
100+
const branchDropdownTooltip = useTooltip(
101+
branchInfo
102+
? (currentBranch ? `Current branch: ${currentBranch}` : 'Branch name unavailable')
103+
: 'Branch information unavailable'
104+
);
105+
const branchSearchTooltip = useTooltip(
106+
isRefreshingBranches ? 'Refreshing branches…' : 'Search all branches'
107+
);
108+
88109
useEffect(() => {
89110
if (isOpen && buttonRef.current) {
90111
const rect = buttonRef.current.getBoundingClientRect();
@@ -129,19 +150,8 @@ const BranchSwitcher: React.FC<{
129150
}
130151
return () => document.removeEventListener("mousedown", handleClickOutside);
131152
}, [isOpen, onClose]);
132-
133153
if (!branchInfo) return null;
134154

135-
const { local, remote, current } = branchInfo;
136-
137-
const remoteBranchesToOffer = remote.filter(rBranch => {
138-
const localEquivalent = rBranch.split('/').slice(1).join('/');
139-
return !local.includes(localEquivalent);
140-
});
141-
142-
const otherLocalBranches = local.filter(b => b !== current);
143-
const hasOptions = otherLocalBranches.length > 0 || remoteBranchesToOffer.length > 0;
144-
145155
const handleBranchClick = (branch: string) => {
146156
onSwitchBranch(repoId, branch);
147157
onClose();
@@ -208,6 +218,7 @@ const BranchSwitcher: React.FC<{
208218
<div className="flex items-center gap-1">
209219
<div className="min-w-0 flex-1">
210220
<button
221+
{...branchDropdownTooltip}
211222
ref={buttonRef}
212223
type="button"
213224
className="inline-flex items-center justify-center w-full rounded-md disabled:cursor-not-allowed"
@@ -216,11 +227,12 @@ const BranchSwitcher: React.FC<{
216227
aria-haspopup="true"
217228
aria-expanded={isOpen}
218229
>
219-
<span className="truncate max-w-[150px] sm:max-w-[200px]">{current}</span>
230+
<span className="truncate max-w-[150px] sm:max-w-[200px]">{currentBranch}</span>
220231
<ChevronDownIcon className={`ml-1 -mr-1 h-4 w-4 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
221232
</button>
222233
</div>
223234
<button
235+
{...branchSearchTooltip}
224236
type="button"
225237
onClick={openModal}
226238
className="flex-shrink-0 p-1.5 rounded-md text-gray-500 hover:text-blue-600 dark:text-gray-300 dark:hover:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-60 disabled:cursor-not-allowed"

0 commit comments

Comments
 (0)