Skip to content

Commit

Permalink
add current branch name on status bar (#1131)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
BoscoCHW and fcollonval authored Jun 17, 2022
1 parent c266fb3 commit 9b035bf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 deletions.
83 changes: 49 additions & 34 deletions src/components/StatusWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { gitIcon } from '../style/icons';
import {
badgeClass,
statusAnimatedIconClass,
statusIconClass
statusIconClass,
currentBranchNameClass
} from '../style/StatusWidget';
import { toolbarButtonClass } from '../style/Toolbar';
import { IGitExtension } from '../tokens';
Expand All @@ -27,6 +28,8 @@ export class StatusWidget extends ReactWidget {
super();
this._model = model;
this._trans = trans;

this.addClass('jp-git-StatusWidget');
}

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

render(): JSX.Element {
return (
<UseSignal
signal={this._model.credentialsRequiredChanged}
initialArgs={false}
>
{(_, needsCredentials) => (
<Badge
className={badgeClass}
variant="dot"
invisible={!needsCredentials}
data-test-id="git-credential-badge"
>
<ActionButton
className={classes(
toolbarButtonClass,
this._status !== 'idle'
? statusAnimatedIconClass
: statusIconClass
)}
icon={gitIcon}
onClick={
needsCredentials
? async () => this._showGitOperationDialog()
: undefined
}
title={
needsCredentials
? `Git: ${this._trans.__('credentials required')}`
: `Git: ${this._trans.__(this._status)}`
}
/>
</Badge>
)}
</UseSignal>
<>
<UseSignal
signal={this._model.credentialsRequiredChanged}
initialArgs={false}
>
{(_, needsCredentials) => (
<Badge
className={badgeClass}
variant="dot"
invisible={!needsCredentials}
data-test-id="git-credential-badge"
>
<ActionButton
className={classes(
toolbarButtonClass,
this._status !== 'idle'
? statusAnimatedIconClass
: statusIconClass
)}
icon={gitIcon}
onClick={
needsCredentials
? async () => this._showGitOperationDialog()
: undefined
}
title={
needsCredentials
? `Git: ${this._trans.__('credentials required')}`
: `Git: ${this._trans.__(this._status)}`
}
/>
</Badge>
)}
</UseSignal>

<UseSignal signal={this._model.headChanged}>
{() =>
this._model.currentBranch && (
<span className={currentBranchNameClass}>
{this._model.currentBranch.name}
</span>
)
}
</UseSignal>
</>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ async function activate(
change: IChangedArgs<string>
) => {
gitExtension.pathRepository = change.newValue;
gitExtension.refreshBranch();
};

// Whenever the file browser path changes, sync the Git extension path
Expand Down
5 changes: 5 additions & 0 deletions src/style/StatusWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ export const badgeClass = style({
}
}
});

export const currentBranchNameClass = style({
fontSize: 'var(--jp-ui-font-size1)',
lineHeight: '100%'
});
1 change: 1 addition & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
@import url('diff-nb.css');
@import url('diff-text.css');
@import url('variables.css');
@import url('status-widget.css');
4 changes: 4 additions & 0 deletions style/status-widget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.jp-git-StatusWidget {
display: flex;
align-items: center;
}

0 comments on commit 9b035bf

Please sign in to comment.