import { useTranslation } from "react-i18next"; import BranchIcon from "#/icons/u-code-branch.svg?react"; import { constructBranchUrl, cn } from "#/utils/utils"; import { Provider } from "#/types/settings"; import { I18nKey } from "#/i18n/declaration"; import { GitExternalLinkIcon } from "./git-external-link-icon"; import { useSettings } from "#/hooks/query/use-settings"; interface GitControlBarBranchButtonProps { selectedBranch: string | null | undefined; selectedRepository: string | null | undefined; gitProvider: Provider | null | undefined; } export function GitControlBarBranchButton({ selectedBranch, selectedRepository, gitProvider, }: GitControlBarBranchButtonProps) { const { t } = useTranslation("openhands"); const { data: settings } = useSettings(); const providerHost = gitProvider ? settings?.provider_tokens_set[gitProvider] : null; // Render the linked styling only when we have enough info to build a URL. // Local-workspace fallbacks may give us a branch name without a known // provider — show the branch text in that case but skip the external link. const hasLinkableBranch = !!selectedBranch && !!selectedRepository && !!gitProvider; const branchUrl = hasLinkableBranch ? constructBranchUrl( gitProvider, selectedRepository, selectedBranch, providerHost, ) : undefined; const buttonText = selectedBranch || t(I18nKey.COMMON$NO_BRANCH); return (
{buttonText}
{hasLinkableBranch && }
); }