Skip to content

Commit d300f2c

Browse files
committed
Fixes issues when changing timeline scope
Improves timeline tab titles Adds ability to open timeline new tab by using `Alt` or `Shift` on breadcrumbs Temporarily disables the base reference selection Updates Head branch label until base is re-added
1 parent b013b45 commit d300f2c

File tree

3 files changed

+89
-48
lines changed

3 files changed

+89
-48
lines changed

src/webviews/apps/plus/timeline/timeline.ts

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class GlTimelineApp extends GlApp<State> {
186186
<gl-button
187187
appearance="toolbar"
188188
density="compact"
189-
@click=${this.onUpdateScope}
189+
@click=${this.onChangeScope}
190190
tooltip="Visualize Repository History&#10;&#10;${repo.name}"
191191
aria-label="Visualize Repository History&#10;&#10;${repo.name}"
192192
>${repo.name}</gl-button
@@ -240,7 +240,7 @@ export class GlTimelineApp extends GlApp<State> {
240240
>
241241
<gl-button
242242
appearance="toolbar"
243-
@click=${this.onUpdateScope}
243+
@click=${this.onChangeScope}
244244
tooltip="Visualize Folder History&#10;&#10;${rootPart}"
245245
aria-label="Visualize Folder History &#10;&#10;${rootPart}"
246246
>${rootPart}</gl-button
@@ -256,7 +256,7 @@ export class GlTimelineApp extends GlApp<State> {
256256
>
257257
<gl-button
258258
appearance="toolbar"
259-
@click=${this.onUpdateScope}
259+
@click=${this.onChangeScope}
260260
tooltip="Visualize Folder History&#10;&#10;${fullPath}"
261261
aria-label="Visualize Folder History&#10;&#10;${fullPath}"
262262
>${part}</gl-button
@@ -350,40 +350,61 @@ export class GlTimelineApp extends GlApp<State> {
350350
config: { showAllBranches },
351351
} = this;
352352
return html`<section>
353-
<label for="head" ?disabled=${showAllBranches}>Head</label>
353+
<label for="head" ?disabled=${showAllBranches}>Branch</label>
354354
<gl-ref-button
355355
name="head"
356356
?disabled=${showAllBranches}
357357
icon
358-
tooltip="Change Head Reference"
358+
tooltip="Change Reference"
359359
.ref=${head}
360360
location="config"
361361
@click=${this.onChooseHeadRef}
362362
></gl-ref-button>
363363
</section>`;
364+
365+
// Commenting out for now, until base is ready
366+
367+
// const {
368+
// head,
369+
// config: { showAllBranches },
370+
// } = this;
371+
// return html`<section>
372+
// <label for="head" ?disabled=${showAllBranches}>Head</label>
373+
// <gl-ref-button
374+
// name="head"
375+
// ?disabled=${showAllBranches}
376+
// icon
377+
// tooltip="Change Head Reference"
378+
// .ref=${head}
379+
// location="config"
380+
// @click=${this.onChooseHeadRef}
381+
// ></gl-ref-button>
382+
// </section>`;
364383
}
365384

366385
private renderConfigBase() {
367-
if (this.repository?.virtual) return nothing;
368-
369-
const {
370-
head,
371-
base,
372-
config: { showAllBranches },
373-
} = this;
374-
return html`<section>
375-
<label for="base" ?disabled=${showAllBranches}>Base</label>
376-
<gl-ref-button
377-
name="base"
378-
?disabled=${showAllBranches}
379-
icon
380-
tooltip="Change Base Reference"
381-
.ref=${base?.ref === head?.ref ? undefined : base}
382-
location="config"
383-
@click=${this.onChooseBaseRef}
384-
><span slot="empty">&lt;choose base&gt;</span></gl-ref-button
385-
>
386-
</section>`;
386+
// Commenting out for now, as its not yet ready
387+
return nothing;
388+
// if (this.repository?.virtual) return nothing;
389+
390+
// const {
391+
// head,
392+
// base,
393+
// config: { showAllBranches },
394+
// } = this;
395+
// return html`<section>
396+
// <label for="base" ?disabled=${showAllBranches}>Base</label>
397+
// <gl-ref-button
398+
// name="base"
399+
// ?disabled=${showAllBranches}
400+
// icon
401+
// tooltip="Change Base Reference"
402+
// .ref=${base?.ref === head?.ref ? undefined : base}
403+
// location="config"
404+
// @click=${this.onChooseBaseRef}
405+
// ><span slot="empty">&lt;choose base&gt;</span></gl-ref-button
406+
// >
407+
// </section>`;
387408
}
388409

389410
private renderConfigShowAllBranches() {
@@ -488,7 +509,7 @@ export class GlTimelineApp extends GlApp<State> {
488509
return html`<span class="details__timeframe" tabindex="0">${label}</span>`;
489510
}
490511

491-
private onChooseBaseRef = async (e: Event) => {
512+
private onChooseBaseRef = async (e: MouseEvent) => {
492513
if ((e.target as GlRefButton).disabled) return;
493514

494515
const result = await this._ipc.sendRequest(ChooseRefRequest, { scope: this.scope!, type: 'base' });
@@ -497,7 +518,7 @@ export class GlTimelineApp extends GlApp<State> {
497518
this._ipc.sendCommand(UpdateScopeCommand, { scope: this.scope!, changes: { base: result.ref } });
498519
};
499520

500-
private onChooseHeadRef = async (e: Event) => {
521+
private onChooseHeadRef = async (e: MouseEvent) => {
501522
if ((e.target as GlRefButton).disabled) return;
502523

503524
const location = (e.target as GlRefButton).getAttribute('location');
@@ -521,7 +542,7 @@ export class GlTimelineApp extends GlApp<State> {
521542
}
522543
};
523544

524-
private onChoosePath = async (e: Event) => {
545+
private onChoosePath = async (e: MouseEvent) => {
525546
e.stopImmediatePropagation();
526547
if (this.repository == null || this.scope == null) return;
527548

@@ -536,10 +557,11 @@ export class GlTimelineApp extends GlApp<State> {
536557
this._ipc.sendCommand(UpdateScopeCommand, {
537558
scope: this.scope,
538559
changes: { type: result.picked.type, relativePath: result.picked.relativePath },
560+
altOrShift: e.altKey || e.shiftKey,
539561
});
540562
};
541563

542-
private onUpdateScope = (e: Event) => {
564+
private onChangeScope = (e: MouseEvent) => {
543565
const el =
544566
(e.target as HTMLElement)?.closest('gl-breadcrumb-item-child') ??
545567
(e.target as HTMLElement)?.closest('gl-breadcrumb-item');
@@ -548,14 +570,22 @@ export class GlTimelineApp extends GlApp<State> {
548570
if (type == null) return;
549571

550572
if (type === 'repo') {
551-
this._ipc.sendCommand(UpdateScopeCommand, { scope: this.scope!, changes: { type: 'repo' } });
573+
this._ipc.sendCommand(UpdateScopeCommand, {
574+
scope: this.scope!,
575+
changes: { type: 'repo' },
576+
altOrShift: e.altKey || e.shiftKey,
577+
});
552578
return;
553579
}
554580

555581
const value = el?.getAttribute('value');
556582
if (value == null) return;
557583

558-
this._ipc.sendCommand(UpdateScopeCommand, { scope: this.scope!, changes: { type: type, relativePath: value } });
584+
this._ipc.sendCommand(UpdateScopeCommand, {
585+
scope: this.scope!,
586+
changes: { type: type, relativePath: value },
587+
altOrShift: e.altKey || e.shiftKey,
588+
});
559589
};
560590

561591
private onChartCommitSelected(e: CustomEvent<CommitEventDetail>) {

src/webviews/plus/timeline/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface UpdateScopeParams {
9999
base?: GitReference | null;
100100
relativePath?: never;
101101
};
102+
altOrShift?: boolean;
102103
}
103104
export const UpdateScopeCommand = new IpcCommand<UpdateScopeParams>(scope, 'scope/update');
104105

src/webviews/plus/timeline/timelineWebview.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,11 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
479479

480480
let changed = false;
481481
if (type != null && type !== scope.type) {
482-
// If we are changing the type, and in the view, open it in the editor
483-
if (this.host.is('view')) {
484-
void executeCommand<TimelineScope>('gitlens.visualizeHistory', scope);
485-
return;
486-
}
487-
488482
changed = true;
489483
scope.type = type;
484+
if (type === 'repo') {
485+
scope.uri = repo.uri;
486+
}
490487
}
491488

492489
if (head !== undefined) {
@@ -501,7 +498,13 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
501498

502499
if (relativePath != null) {
503500
changed = true;
504-
scope.uri = scope.type === 'repo' ? repo.uri : this.container.git.getAbsoluteUri(relativePath, repo.uri);
501+
scope.uri = this.container.git.getAbsoluteUri(relativePath, repo.uri);
502+
}
503+
504+
// If we are changing the type, and in the view, open it in the editor
505+
if (this.host.is('view') || e.params.altOrShift) {
506+
void executeCommand<TimelineScope>('gitlens.visualizeHistory', scope);
507+
return;
505508
}
506509

507510
if (!changed) return;
@@ -896,7 +899,7 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
896899
repositoryWip: undefined,
897900
subscription: this.container.subscription.etag,
898901
};
899-
let title;
902+
let title = '';
900903

901904
if (scope != null) {
902905
if (this.container.git.isDiscoveringRepositories) {
@@ -917,14 +920,21 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
917920

918921
this._repositorySubscription ??= new SubscriptionManager(repo, r => this.subscribeToRepository(r));
919922

920-
switch (scope.type) {
921-
case 'repo':
922-
title = repo.name;
923-
break;
924-
case 'folder':
925-
case 'file':
926-
title = basename(this.container.git.getRelativePath(scope.uri, repo.uri));
927-
break;
923+
if (scope.type === 'file' || scope.type === 'folder') {
924+
title = basename(this.container.git.getRelativePath(scope.uri, repo.uri));
925+
if (scope.head) {
926+
title += ` (${scope.head.ref})`;
927+
}
928+
if (this.container.git.repositoryCount > 1) {
929+
title += ` \u2022 ${repo.name}`;
930+
}
931+
} else if (scope.head) {
932+
title += scope.head.name;
933+
if (this.container.git.repositoryCount > 1) {
934+
title += ` \u2022 ${repo.name}`;
935+
}
936+
} else {
937+
title = repo.name;
928938
}
929939
}
930940

@@ -951,7 +961,7 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
951961
this._context.etags = etags;
952962

953963
if (this.host.is('editor')) {
954-
this.host.title = title ? `${title} \u2022 Visual History` : 'Visual History';
964+
this.host.title = title || 'Visual History';
955965
} else {
956966
this.host.description = title || proBadge;
957967
}

0 commit comments

Comments
 (0)