Skip to content

Commit d74f56a

Browse files
author
WangQianliang
authored
fix(code/frontend): HEAD should be default branch in branch selector (#40832) (#40837)
1 parent 31b4ae4 commit d74f56a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

x-pack/legacy/plugins/code/public/components/main/content.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
SearchOptions,
2121
SearchScope,
2222
WorkerReservedProgress,
23+
Repository,
2324
} from '../../../model';
2425
import { CommitInfo, ReferenceInfo } from '../../../model/commit';
2526
import { changeSearchScope, FetchFileResponse, RepoState, RepoStatus } from '../../actions';
@@ -57,6 +58,7 @@ interface Props extends RouteComponentProps<MainRouteParams> {
5758
fileTreeLoadingPaths: string[];
5859
searchOptions: SearchOptions;
5960
query: string;
61+
currentRepository: Repository;
6062
}
6163
const LANG_MD = 'markdown';
6264

@@ -232,6 +234,7 @@ class CodeContent extends React.PureComponent<Props> {
232234
searchOptions={this.props.searchOptions}
233235
branches={this.props.branches}
234236
query={this.props.query}
237+
currentRepository={this.props.currentRepository}
235238
/>
236239
{this.renderContent()}
237240
</div>
@@ -402,6 +405,7 @@ const mapStateToProps = (state: RootState) => ({
402405
repoStatus: statusSelector(state, repoUriSelector(state)),
403406
searchOptions: state.search.searchOptions,
404407
query: state.search.query,
408+
currentRepository: state.repository.repository,
405409
});
406410

407411
const mapDispatchToProps = {

x-pack/legacy/plugins/code/public/components/main/top_bar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { EuiFlexGroup, EuiFlexItem, EuiSelect } from '@elastic/eui';
88
import React, { ChangeEvent } from 'react';
9-
import { SearchOptions, SearchScope } from '../../../model';
9+
import { SearchOptions, SearchScope, Repository } from '../../../model';
1010
import { ReferenceInfo } from '../../../model/commit';
1111
import { MainRouteParams } from '../../common/types';
1212
import { encodeRevisionString, decodeRevisionString } from '../../../common/uri_util';
@@ -22,6 +22,7 @@ interface Props {
2222
searchOptions: SearchOptions;
2323
branches: ReferenceInfo[];
2424
query: string;
25+
currentRepository?: Repository;
2526
}
2627

2728
export class TopBar extends React.Component<Props, { value: string }> {
@@ -38,6 +39,9 @@ export class TopBar extends React.Component<Props, { value: string }> {
3839

3940
getBranch = (revision: string) => {
4041
const r = decodeRevisionString(revision);
42+
if (r.toUpperCase() === 'HEAD' && this.props.currentRepository) {
43+
return this.props.currentRepository.defaultBranch;
44+
}
4145
const branch = this.props.branches.find(b => b.name === r);
4246
if (branch) {
4347
return branch.name;

0 commit comments

Comments
 (0)