Browse Source

Fixes stash selection in the Graph/Commit Details

main
Eric Amodio 2 years ago
parent
commit
7d8d621323
4 changed files with 25 additions and 12 deletions
  1. +12
    -5
      src/plus/webviews/graph/graphWebview.ts
  2. +4
    -3
      src/plus/webviews/graph/protocol.ts
  3. +3
    -2
      src/webviews/apps/plus/graph/GraphWrapper.tsx
  4. +6
    -2
      src/webviews/apps/plus/graph/graph.tsx

+ 12
- 5
src/plus/webviews/graph/graphWebview.ts View File

@ -9,6 +9,7 @@ import type { Container } from '../../../container';
import { setContext } from '../../../context';
import { PlusFeatures } from '../../../features';
import type { GitCommit } from '../../../git/models/commit';
import { GitGraphRowType } from '../../../git/models/graph';
import type { GitGraph } from '../../../git/models/graph';
import type { Repository, RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
@ -316,13 +317,19 @@ export class GraphWebview extends WebviewBase {
this.repository = this.container.git.getRepository(path);
}
private async onSelectionChanged(selection: string[]) {
const sha = selection[0];
this._selectedSha = sha;
private async onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) {
const item = selection[0];
this._selectedSha = item?.id;
let commits: GitCommit[] | undefined;
if (sha != null) {
const commit = await this.repository?.getCommit(sha);
if (item?.id != null) {
let commit;
if (item.type === GitGraphRowType.Stash) {
const stash = await this.repository?.getStash();
commit = stash?.commits.get(item.id);
} else {
commit = await this.repository?.getCommit(item?.id);
}
if (commit != null) {
commits = [commit];
}

+ 4
- 3
src/plus/webviews/graph/protocol.ts View File

@ -1,6 +1,7 @@
import type { CommitType, GraphRow, Remote } from '@gitkraken/gitkraken-components';
import type { GraphRow, Remote } from '@gitkraken/gitkraken-components';
import type { GraphColumnConfig, GraphConfig } from '../../../config';
import type { RepositoryVisibility } from '../../../git/gitProvider';
import type { GitGraphRowType } from '../../../git/models/graph';
import type { Subscription } from '../../../subscription';
import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol';
@ -45,7 +46,7 @@ export interface GraphCommit {
message: string;
parents: string[];
committer: GraphCommitIdentity;
type: CommitType;
type: GitGraphRowType;
avatarUrl: string | undefined;
}
@ -83,7 +84,7 @@ export const UpdateSelectedRepositoryCommandType = new IpcCommandType
);
export interface UpdateSelectionParams {
selection: string[];
selection: { id: string; type: GitGraphRowType }[];
}
export const UpdateSelectionCommandType = new IpcCommandType<UpdateSelectionParams>('graph/update/selection');

+ 3
- 2
src/webviews/apps/plus/graph/GraphWrapper.tsx View File

@ -7,6 +7,7 @@ import GraphContainer, {
} from '@gitkraken/gitkraken-components';
import type { ReactElement } from 'react';
import React, { createElement, useEffect, useRef, useState } from 'react';
import type { GitGraphRowType } from 'src/git/models/graph';
import type { GraphColumnConfig } from '../../../../config';
import type {
CommitListCallback,
@ -25,7 +26,7 @@ export interface GraphWrapperProps extends State {
onColumnChange?: (name: string, settings: GraphColumnConfig) => void;
onMoreCommits?: (limit?: number) => void;
onDismissPreview?: () => void;
onSelectionChange?: (selection: string[]) => void;
onSelectionChange?: (selection: { id: string; type: GitGraphRowType }[]) => void;
}
const getStyleProps = (
@ -219,7 +220,7 @@ export function GraphWrapper({
};
const handleSelectGraphRows = (graphRows: GraphRow[]) => {
onSelectionChange?.(graphRows.map(r => r.sha));
onSelectionChange?.(graphRows.map(r => ({ id: r.sha, type: r.type as GitGraphRowType })));
};
const handleDismissPreview = () => {

+ 6
- 2
src/webviews/apps/plus/graph/graph.tsx View File

@ -2,6 +2,7 @@
import type { CssVariables } from '@gitkraken/gitkraken-components';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import type { GitGraphRowType } from 'src/git/models/graph';
import type { GraphColumnConfig } from '../../../../config';
import type { CommitListCallback, GraphRepository, State } from '../../../../plus/webviews/graph/protocol';
import {
@ -61,7 +62,10 @@ export class GraphApp extends App {
250,
)}
onMoreCommits={(...params) => this.onGetMoreCommits(...params)}
onSelectionChange={debounce((selection: string[]) => this.onSelectionChanged(selection), 250)}
onSelectionChange={debounce(
(selection: { id: string; type: GitGraphRowType }[]) => this.onSelectionChanged(selection),
250,
)}
onDismissPreview={() => this.onDismissPreview()}
{...this.state}
/>,
@ -236,7 +240,7 @@ export class GraphApp extends App {
});
}
private onSelectionChanged(selection: string[]) {
private onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) {
this.sendCommand(UpdateSelectionCommandType, {
selection: selection,
});

Loading…
Cancel
Save