1
1
import { useState } from 'react'
2
2
import { useParams } from 'react-router-dom'
3
3
4
- import { useBranch , query as useBranchQuery } from 'services/branches/useBranch'
5
4
import { useBranches } from 'services/branches/useBranches'
6
5
7
6
interface URLParams {
@@ -23,7 +22,7 @@ export const useCommitsTabBranchSelector = ({
23
22
const [ branchSearchTerm , setBranchSearchTerm ] = useState ( '' )
24
23
25
24
const {
26
- data : branchList ,
25
+ data : branchesData ,
27
26
isFetching : branchListIsFetching ,
28
27
hasNextPage : branchListHasNextPage ,
29
28
fetchNextPage : branchListFetchNextPage ,
@@ -37,39 +36,17 @@ export const useCommitsTabBranchSelector = ({
37
36
} ,
38
37
} )
39
38
40
- const { data : branchesData , fetchNextPage : branchesFetchNextPage } =
41
- useBranches ( {
42
- repo,
43
- owner,
44
- provider,
45
- filters : { } ,
46
- opts : { suspense : false } ,
47
- } )
48
-
49
39
const selectedBranch = passedBranch ?? defaultBranch
50
40
51
- const { data : searchBranchValue } = useBranch ( {
52
- provider,
53
- owner,
54
- repo,
55
- branch : selectedBranch ,
56
- opts : {
57
- queryKey : [
58
- 'GetCommitsTabSelectedBranch' ,
59
- provider ,
60
- owner ,
61
- repo ,
62
- selectedBranch ,
63
- useBranchQuery ,
64
- ] ,
65
- enabled : ! ! selectedBranch ,
66
- } ,
67
- } )
41
+ // Check if the selected branch exists in the branches list
42
+ const branchExists = branchesData ?. branches ?. some (
43
+ ( branch ) => branch ?. name === selectedBranch
44
+ )
68
45
69
- let selection = searchBranchValue ?. branch ?. name
46
+ let selection = selectedBranch
70
47
if ( isAllCommits ) {
71
48
selection = 'All branches'
72
- } else if ( ! selection ) {
49
+ } else if ( ! branchExists ) {
73
50
selection = 'Select branch'
74
51
}
75
52
@@ -80,8 +57,7 @@ export const useCommitsTabBranchSelector = ({
80
57
value : selection ,
81
58
} ,
82
59
currentBranchSelected : selection ,
83
- branchesFetchNextPage,
84
- branchList : branchList ?. branches ?. map ( ( branch ) => branch ?. name ) || [ ] ,
60
+ branchList : branchesData ?. branches ?. map ( ( branch ) => branch ?. name ) || [ ] ,
85
61
branchListIsFetching,
86
62
branchListHasNextPage,
87
63
branchListFetchNextPage,
0 commit comments