@@ -38,13 +38,15 @@ import ReactMarkdown from 'react-markdown';
3838import remarkGfm from 'remark-gfm' ;
3939import { PencilIcon } from '../icons/PencilIcon' ;
4040import { ArrowPathIcon } from '../icons/ArrowPathIcon' ;
41+ import type { StatusBarMessage } from '../StatusBar' ;
4142
4243interface RepoEditViewProps {
4344 onSave : ( repository : Repository , categoryId ?: string ) => void ;
4445 onCancel : ( ) => void ;
4546 repository : Repository | null ;
4647 onRefreshState : ( repoId : string ) => Promise < void > ;
4748 setToast : ( toast : { message : string ; type : 'success' | 'error' | 'info' } | null ) => void ;
49+ setStatusBarMessage ?: ( message : StatusBarMessage | null ) => void ;
4850 confirmAction : ( options : {
4951 title : string ;
5052 message : React . ReactNode ;
@@ -1869,7 +1871,7 @@ const CommitListItem: React.FC<CommitListItemProps> = ({ commit, highlight }) =>
18691871 ) ;
18701872} ;
18711873
1872- const RepoEditView : React . FC < RepoEditViewProps > = ( { onSave, onCancel, repository, onRefreshState, setToast, confirmAction, defaultCategoryId, onOpenWeblink, detectedExecutables } ) => {
1874+ const RepoEditView : React . FC < RepoEditViewProps > = ( { onSave, onCancel, repository, onRefreshState, setToast, setStatusBarMessage , confirmAction, defaultCategoryId, onOpenWeblink, detectedExecutables } ) => {
18731875 const logger = useLogger ( ) ;
18741876 const [ formData , setFormData ] = useState < Repository | Omit < Repository , 'id' > > ( ( ) => repository || NEW_REPO_TEMPLATE ) ;
18751877
@@ -1967,6 +1969,43 @@ const RepoEditView: React.FC<RepoEditViewProps> = ({ onSave, onCancel, repositor
19671969 return keySet ;
19681970 } , [ selectedBranches ] ) ;
19691971
1972+ const branchSelectionStats = useMemo ( ( ) => {
1973+ const selectedBranchCount = selectedBranches . length ;
1974+ let selectedLocalCount = 0 ;
1975+ selectedBranches . forEach ( selection => {
1976+ if ( selection . scope === 'local' ) {
1977+ selectedLocalCount += 1 ;
1978+ }
1979+ } ) ;
1980+ const selectedRemoteCount = selectedBranchCount - selectedLocalCount ;
1981+ const isCurrentSelection = Boolean (
1982+ selectedBranchCount === 1 &&
1983+ primarySelectedBranch ?. scope === 'local' &&
1984+ branchInfo ?. current &&
1985+ primarySelectedBranch . name === branchInfo . current
1986+ ) ;
1987+
1988+ let selectionDescription : string | null = null ;
1989+ if ( ! selectedBranchCount ) {
1990+ selectionDescription = 'Select a branch to checkout.' ;
1991+ } else if ( selectedBranchCount === 1 && primarySelectedBranch ) {
1992+ if ( ! ( primarySelectedBranch . scope === 'local' && branchInfo ?. current === primarySelectedBranch . name ) ) {
1993+ selectionDescription = `${ primarySelectedBranch . scope === 'remote' ? 'Remote' : 'Local' } branch: ${ primarySelectedBranch . name } ` ;
1994+ }
1995+ } else {
1996+ const parts : string [ ] = [ ] ;
1997+ if ( selectedLocalCount ) {
1998+ parts . push ( `${ selectedLocalCount } local` ) ;
1999+ }
2000+ if ( selectedRemoteCount ) {
2001+ parts . push ( `${ selectedRemoteCount } remote` ) ;
2002+ }
2003+ selectionDescription = `${ selectedBranchCount } branches selected (${ parts . join ( ', ' ) } )` ;
2004+ }
2005+
2006+ return { selectedBranchCount, selectedLocalCount, selectedRemoteCount, isCurrentSelection, selectionDescription } ;
2007+ } , [ selectedBranches , primarySelectedBranch , branchInfo ?. current ] ) ;
2008+
19702009 // State for Releases Tab
19712010 const [ releases , setReleases ] = useState < ReleaseInfo [ ] | null > ( null ) ;
19722011 const [ releasesLoading , setReleasesLoading ] = useState ( false ) ;
@@ -2035,6 +2074,23 @@ const RepoEditView: React.FC<RepoEditViewProps> = ({ onSave, onCancel, repositor
20352074 } ) ;
20362075 } , [ filteredLocalBranches , filteredRemoteBranches , branchInfo ?. current ] ) ;
20372076
2077+ useEffect ( ( ) => {
2078+ if ( ! setStatusBarMessage ) {
2079+ return ;
2080+ }
2081+ if ( activeTab === 'branches' && branchSelectionStats . selectionDescription ) {
2082+ setStatusBarMessage ( { text : branchSelectionStats . selectionDescription , tone : 'info' } ) ;
2083+ } else {
2084+ setStatusBarMessage ( null ) ;
2085+ }
2086+ } , [ activeTab , branchSelectionStats . selectionDescription , setStatusBarMessage ] ) ;
2087+
2088+ useEffect ( ( ) => {
2089+ return ( ) => {
2090+ setStatusBarMessage ?.( null ) ;
2091+ } ;
2092+ } , [ setStatusBarMessage ] ) ;
2093+
20382094 useEffect ( ( ) => {
20392095 if ( ! branchInfo ) {
20402096 return ;
@@ -3500,35 +3556,13 @@ const RepoEditView: React.FC<RepoEditViewProps> = ({ onSave, onCancel, repositor
35003556 if ( ! supportsBranchTab ) {
35013557 return < div className = "p-2 text-center text-gray-500" > Branch management is only available for Git or SVN repositories.</ div > ;
35023558 }
3503- const selectedBranchCount = selectedBranches . length ;
3504- const selectedLocalCount = selectedBranches . filter ( selection => selection . scope === 'local' ) . length ;
3505- const selectedRemoteCount = selectedBranchCount - selectedLocalCount ;
3506- const isCurrentSelection = Boolean (
3507- selectedBranchCount === 1 &&
3508- primarySelectedBranch ?. scope === 'local' &&
3509- branchInfo ?. current &&
3510- primarySelectedBranch . name === branchInfo . current
3511- ) ;
3559+ const {
3560+ selectedBranchCount,
3561+ selectedLocalCount,
3562+ selectedRemoteCount,
3563+ isCurrentSelection,
3564+ } = branchSelectionStats ;
35123565 const checkoutDisabled = selectedBranchCount !== 1 || isCheckoutLoading || branchesLoading || isCurrentSelection ;
3513- const selectionDescription = ( ( ) => {
3514- if ( ! selectedBranchCount ) {
3515- return 'Select a branch to checkout.' ;
3516- }
3517- if ( selectedBranchCount === 1 && primarySelectedBranch ) {
3518- if ( primarySelectedBranch . scope === 'local' && branchInfo ?. current === primarySelectedBranch . name ) {
3519- return undefined ;
3520- }
3521- return `${ primarySelectedBranch . scope === 'remote' ? 'Remote' : 'Local' } branch: ${ primarySelectedBranch . name } ` ;
3522- }
3523- const parts : string [ ] = [ ] ;
3524- if ( selectedLocalCount ) {
3525- parts . push ( `${ selectedLocalCount } local` ) ;
3526- }
3527- if ( selectedRemoteCount ) {
3528- parts . push ( `${ selectedRemoteCount } remote` ) ;
3529- }
3530- return `${ selectedBranchCount } branches selected (${ parts . join ( ', ' ) } )` ;
3531- } ) ( ) ;
35323566 const hasProtectedSelection = selectedBranches . some ( selection => isProtectedBranch ( selection . name , selection . scope ) ) ;
35333567 const hasCurrentBranchSelected = selectedBranches . some ( selection => selection . scope === 'local' && branchInfo ?. current && selection . name === branchInfo . current ) ;
35343568 const hasDeletableSelection = selectedBranches . some ( selection => {
@@ -3720,9 +3754,6 @@ const RepoEditView: React.FC<RepoEditViewProps> = ({ onSave, onCancel, repositor
37203754 </ div >
37213755 </ div >
37223756 < div className = "pt-4 mt-2 border-t border-gray-200 dark:border-gray-700 flex flex-col gap-4 flex-shrink-0" >
3723- { selectionDescription && (
3724- < p className = "text-sm text-gray-600 dark:text-gray-300" > { selectionDescription } </ p >
3725- ) }
37263757 { isSvnRepo && (
37273758 < p className = "text-xs text-gray-500 dark:text-gray-400" >
37283759 Branch creation, deletion, and merging are currently only available for Git repositories.
0 commit comments