11import { consume } from '@lit/context' ;
22import { SignalWatcher } from '@lit-labs/signals' ;
33import { css , html , LitElement , nothing } from 'lit' ;
4- import { customElement , property , state } from 'lit/decorators.js' ;
5- import { repeat } from 'lit/directives/repeat.js' ;
4+ import { customElement , state } from 'lit/decorators.js' ;
65import { when } from 'lit/directives/when.js' ;
76import type { GitTrackingState } from '../../../../../git/models/branch' ;
8- import type { GetOverviewBranch , RepositoryChoice , State } from '../../../../home/protocol' ;
7+ import type { GetOverviewBranch , State } from '../../../../home/protocol' ;
98import { stateContext } from '../../../home/context' ;
10- import { GlElement } from '../../../shared/components/element' ;
119import { branchCardStyles , sectionHeadingStyles } from './branch-section' ;
1210import type { Overview , OverviewState } from './overviewState' ;
1311import { overviewStateContext } from './overviewState' ;
@@ -34,6 +32,15 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
3432 ` ,
3533 branchCardStyles ,
3634 sectionHeadingStyles ,
35+ css `
36+ .is-end {
37+ margin-block-end: 0;
38+ }
39+ .section-heading-action {
40+ --button-padding: 0.1rem 0.2rem 0;
41+ margin-block: -1rem;
42+ }
43+ ` ,
3744 ] ;
3845
3946 @consume < State > ( { context : stateContext , subscribe : true } )
@@ -80,7 +87,18 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
8087 return html `
8188 < h3 class ="section-heading section-heading--actions ">
8289 < span > Active (${ activeBranches . length } )</ span >
83- ${ when ( overview ! . choices , ( ) => html `< gl-change-repo .options =${ overview ! . choices } > </ gl-change-repo > ` ) }
90+ ${ when (
91+ this . _homeState . repositories . openCount > 1 ,
92+ ( ) =>
93+ html `< span
94+ > < gl-button
95+ class ="section-heading-action "
96+ appearance ="toolbar "
97+ tooltip ="Change Repository "
98+ @click =${ ( e : MouseEvent ) => this . onChange ( e ) }
99+ > < code-icon icon ="chevron-down "> </ code-icon > </ gl-button
100+ > </ span > ` ,
101+ ) }
84102 </ h3 >
85103 ${ activeBranches . map ( branch => this . renderRepoBranchCard ( overview ! . repository . name , branch ) ) }
86104 ` ;
@@ -99,7 +117,7 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
99117 ${ when ( state , ( ) => this . renderBranchStateActions ( state , upstream ) ) }
100118 < p class ="branch-item__main ">
101119 < span class ="branch-item__icon ">
102- < code-icon icon =${ branch . worktree ? 'gl-repositories -view' : 'git-branch' } > </ code-icon >
120+ < code-icon icon =${ branch . worktree ? 'gl-worktrees -view' : 'git-branch' } > </ code-icon >
103121 </ span >
104122 < span class ="branch-item__name "> ${ name } </ span >
105123 </ p >
@@ -217,77 +235,14 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
217235
218236 return nothing ;
219237 }
220- }
221-
222- @customElement ( 'gl-change-repo' )
223- export class GlChangeRepo extends GlElement {
224- static override styles = [
225- css `
226- .popover::part(body) {
227- padding: 0;
228- font-size: var(--vscode-font-size);
229- background-color: var(--vscode-menu-background);
230- }
231- .trigger {
232- --button-padding: 0.1rem 0.2rem 0;
233- margin-block: -1rem;
234- }
235-
236- .option {
237- max-width: 20rem;
238- white-space: nowrap;
239- overflow: hidden;
240- text-overflow: ellipsis;
241- }
242-
243- .option code-icon {
244- color: var(--color-foreground--50);
245- }
246- ` ,
247- ] ;
248-
249- @consume ( { context : overviewStateContext } )
250- private _overviewState ! : OverviewState ;
251-
252- @property ( { type : Array } ) options ?: RepositoryChoice [ ] ;
253-
254- protected getLabel ( option : RepositoryChoice ) {
255- return option . name ;
256- }
257-
258- protected onChange ( option : RepositoryChoice ) {
259- void this . querySelector ( 'gl-popover' ) ?. hide ( ) ;
260- void this . _overviewState . changeRepository ( option . path ) ;
261- }
262238
263- override render ( ) {
264- if ( ! this . options ) {
265- return ;
266- }
267- return html `
268- < gl-popover class ="popover " placement ="bottom-end " trigger ="focus " .distance =${ 4 } .arrow =${ false } >
269- < gl-button class ="trigger " appearance ="toolbar " slot ="anchor "
270- > < code-icon icon ="chevron-down "> </ code-icon
271- > </ gl-button >
272- < div slot ="content ">
273- ${ repeat ( this . options , item => {
274- if ( item . selected ) {
275- return nothing ;
276- }
277- const label = this . getLabel ( item ) ;
278- return html `< menu-item class ="option " @click =${ ( ) => this . onChange ( item ) }
279- > < code-icon icon ="repo "> </ code-icon > ${ label } </ menu-item
280- > ` ;
281- } ) }
282- </ div >
283- </ gl-popover >
284- ` ;
239+ private onChange ( _e : MouseEvent ) {
240+ void this . _overviewState . changeRepository ( ) ;
285241 }
286242}
287243
288244declare global {
289245 interface HTMLElementTagNameMap {
290246 [ activeWorkTagName ] : GlActiveWork ;
291- 'gl-change-repo' : GlChangeRepo ;
292247 }
293248}
0 commit comments