Skip to content

Commit 9b035bf

Browse files
BoscoCHWfcollonval
andauthored
add current branch name on status bar (#1131)
* add current branch name on status bar * update current branch name on path changes * vertically center the current branch name using css * Remove '*' from the current branch name Co-authored-by: Frédéric Collonval <[email protected]> Co-authored-by: Frédéric Collonval <[email protected]>
1 parent c266fb3 commit 9b035bf

File tree

5 files changed

+60
-34
lines changed

5 files changed

+60
-34
lines changed

src/components/StatusWidget.tsx

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { gitIcon } from '../style/icons';
1010
import {
1111
badgeClass,
1212
statusAnimatedIconClass,
13-
statusIconClass
13+
statusIconClass,
14+
currentBranchNameClass
1415
} from '../style/StatusWidget';
1516
import { toolbarButtonClass } from '../style/Toolbar';
1617
import { IGitExtension } from '../tokens';
@@ -27,6 +28,8 @@ export class StatusWidget extends ReactWidget {
2728
super();
2829
this._model = model;
2930
this._trans = trans;
31+
32+
this.addClass('jp-git-StatusWidget');
3033
}
3134

3235
/**
@@ -41,39 +44,51 @@ export class StatusWidget extends ReactWidget {
4144

4245
render(): JSX.Element {
4346
return (
44-
<UseSignal
45-
signal={this._model.credentialsRequiredChanged}
46-
initialArgs={false}
47-
>
48-
{(_, needsCredentials) => (
49-
<Badge
50-
className={badgeClass}
51-
variant="dot"
52-
invisible={!needsCredentials}
53-
data-test-id="git-credential-badge"
54-
>
55-
<ActionButton
56-
className={classes(
57-
toolbarButtonClass,
58-
this._status !== 'idle'
59-
? statusAnimatedIconClass
60-
: statusIconClass
61-
)}
62-
icon={gitIcon}
63-
onClick={
64-
needsCredentials
65-
? async () => this._showGitOperationDialog()
66-
: undefined
67-
}
68-
title={
69-
needsCredentials
70-
? `Git: ${this._trans.__('credentials required')}`
71-
: `Git: ${this._trans.__(this._status)}`
72-
}
73-
/>
74-
</Badge>
75-
)}
76-
</UseSignal>
47+
<>
48+
<UseSignal
49+
signal={this._model.credentialsRequiredChanged}
50+
initialArgs={false}
51+
>
52+
{(_, needsCredentials) => (
53+
<Badge
54+
className={badgeClass}
55+
variant="dot"
56+
invisible={!needsCredentials}
57+
data-test-id="git-credential-badge"
58+
>
59+
<ActionButton
60+
className={classes(
61+
toolbarButtonClass,
62+
this._status !== 'idle'
63+
? statusAnimatedIconClass
64+
: statusIconClass
65+
)}
66+
icon={gitIcon}
67+
onClick={
68+
needsCredentials
69+
? async () => this._showGitOperationDialog()
70+
: undefined
71+
}
72+
title={
73+
needsCredentials
74+
? `Git: ${this._trans.__('credentials required')}`
75+
: `Git: ${this._trans.__(this._status)}`
76+
}
77+
/>
78+
</Badge>
79+
)}
80+
</UseSignal>
81+
82+
<UseSignal signal={this._model.headChanged}>
83+
{() =>
84+
this._model.currentBranch && (
85+
<span className={currentBranchNameClass}>
86+
{this._model.currentBranch.name}
87+
</span>
88+
)
89+
}
90+
</UseSignal>
91+
</>
7792
);
7893
}
7994

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ async function activate(
149149
change: IChangedArgs<string>
150150
) => {
151151
gitExtension.pathRepository = change.newValue;
152+
gitExtension.refreshBranch();
152153
};
153154

154155
// Whenever the file browser path changes, sync the Git extension path

src/style/StatusWidget.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ export const badgeClass = style({
3838
}
3939
}
4040
});
41+
42+
export const currentBranchNameClass = style({
43+
fontSize: 'var(--jp-ui-font-size1)',
44+
lineHeight: '100%'
45+
});

style/base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
@import url('diff-nb.css');
99
@import url('diff-text.css');
1010
@import url('variables.css');
11+
@import url('status-widget.css');

style/status-widget.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.jp-git-StatusWidget {
2+
display: flex;
3+
align-items: center;
4+
}

0 commit comments

Comments
 (0)