Skip to content

Commit 7d8d621

Browse files
committed
Fixes stash selection in the Graph/Commit Details
1 parent d3db970 commit 7d8d621

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/plus/webviews/graph/graphWebview.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Container } from '../../../container';
99
import { setContext } from '../../../context';
1010
import { PlusFeatures } from '../../../features';
1111
import type { GitCommit } from '../../../git/models/commit';
12+
import { GitGraphRowType } from '../../../git/models/graph';
1213
import type { GitGraph } from '../../../git/models/graph';
1314
import type { Repository, RepositoryChangeEvent } from '../../../git/models/repository';
1415
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
@@ -316,13 +317,19 @@ export class GraphWebview extends WebviewBase<State> {
316317
this.repository = this.container.git.getRepository(path);
317318
}
318319

319-
private async onSelectionChanged(selection: string[]) {
320-
const sha = selection[0];
321-
this._selectedSha = sha;
320+
private async onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) {
321+
const item = selection[0];
322+
this._selectedSha = item?.id;
322323

323324
let commits: GitCommit[] | undefined;
324-
if (sha != null) {
325-
const commit = await this.repository?.getCommit(sha);
325+
if (item?.id != null) {
326+
let commit;
327+
if (item.type === GitGraphRowType.Stash) {
328+
const stash = await this.repository?.getStash();
329+
commit = stash?.commits.get(item.id);
330+
} else {
331+
commit = await this.repository?.getCommit(item?.id);
332+
}
326333
if (commit != null) {
327334
commits = [commit];
328335
}

src/plus/webviews/graph/protocol.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { CommitType, GraphRow, Remote } from '@gitkraken/gitkraken-components';
1+
import type { GraphRow, Remote } from '@gitkraken/gitkraken-components';
22
import type { GraphColumnConfig, GraphConfig } from '../../../config';
33
import type { RepositoryVisibility } from '../../../git/gitProvider';
4+
import type { GitGraphRowType } from '../../../git/models/graph';
45
import type { Subscription } from '../../../subscription';
56
import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol';
67

@@ -45,7 +46,7 @@ export interface GraphCommit {
4546
message: string;
4647
parents: string[];
4748
committer: GraphCommitIdentity;
48-
type: CommitType;
49+
type: GitGraphRowType;
4950

5051
avatarUrl: string | undefined;
5152
}
@@ -83,7 +84,7 @@ export const UpdateSelectedRepositoryCommandType = new IpcCommandType<UpdateSele
8384
);
8485

8586
export interface UpdateSelectionParams {
86-
selection: string[];
87+
selection: { id: string; type: GitGraphRowType }[];
8788
}
8889
export const UpdateSelectionCommandType = new IpcCommandType<UpdateSelectionParams>('graph/update/selection');
8990

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import GraphContainer, {
77
} from '@gitkraken/gitkraken-components';
88
import type { ReactElement } from 'react';
99
import React, { createElement, useEffect, useRef, useState } from 'react';
10+
import type { GitGraphRowType } from 'src/git/models/graph';
1011
import type { GraphColumnConfig } from '../../../../config';
1112
import type {
1213
CommitListCallback,
@@ -25,7 +26,7 @@ export interface GraphWrapperProps extends State {
2526
onColumnChange?: (name: string, settings: GraphColumnConfig) => void;
2627
onMoreCommits?: (limit?: number) => void;
2728
onDismissPreview?: () => void;
28-
onSelectionChange?: (selection: string[]) => void;
29+
onSelectionChange?: (selection: { id: string; type: GitGraphRowType }[]) => void;
2930
}
3031

3132
const getStyleProps = (
@@ -219,7 +220,7 @@ export function GraphWrapper({
219220
};
220221

221222
const handleSelectGraphRows = (graphRows: GraphRow[]) => {
222-
onSelectionChange?.(graphRows.map(r => r.sha));
223+
onSelectionChange?.(graphRows.map(r => ({ id: r.sha, type: r.type as GitGraphRowType })));
223224
};
224225

225226
const handleDismissPreview = () => {

src/webviews/apps/plus/graph/graph.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { CssVariables } from '@gitkraken/gitkraken-components';
33
import React from 'react';
44
import { render, unmountComponentAtNode } from 'react-dom';
5+
import type { GitGraphRowType } from 'src/git/models/graph';
56
import type { GraphColumnConfig } from '../../../../config';
67
import type { CommitListCallback, GraphRepository, State } from '../../../../plus/webviews/graph/protocol';
78
import {
@@ -61,7 +62,10 @@ export class GraphApp extends App<State> {
6162
250,
6263
)}
6364
onMoreCommits={(...params) => this.onGetMoreCommits(...params)}
64-
onSelectionChange={debounce((selection: string[]) => this.onSelectionChanged(selection), 250)}
65+
onSelectionChange={debounce(
66+
(selection: { id: string; type: GitGraphRowType }[]) => this.onSelectionChanged(selection),
67+
250,
68+
)}
6569
onDismissPreview={() => this.onDismissPreview()}
6670
{...this.state}
6771
/>,
@@ -236,7 +240,7 @@ export class GraphApp extends App<State> {
236240
});
237241
}
238242

239-
private onSelectionChanged(selection: string[]) {
243+
private onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) {
240244
this.sendCommand(UpdateSelectionCommandType, {
241245
selection: selection,
242246
});

0 commit comments

Comments
 (0)