Browse Source

Graph: double-click on a ref to check it out (similar to GKC) (#2258)

* Graph: double-click on a ref to check it out (similar to GKC)

* Renamed command type and function as requested in PR

* Removed cast to any
main
ericf-axosoft 2 years ago
committed by GitHub
parent
commit
706d580660
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 4 deletions
  1. +24
    -1
      src/plus/webviews/graph/graphWebview.ts
  2. +6
    -0
      src/plus/webviews/graph/protocol.ts
  3. +12
    -1
      src/webviews/apps/plus/graph/GraphWrapper.tsx
  4. +10
    -2
      src/webviews/apps/plus/graph/graph.tsx

+ 24
- 1
src/plus/webviews/graph/graphWebview.ts View File

@ -1,3 +1,5 @@
import type { Head } from '@gitkraken/gitkraken-components';
import { stringify } from 'json5';
import type { import type {
ColorTheme, ColorTheme,
ConfigurationChangeEvent, ConfigurationChangeEvent,
@ -81,6 +83,7 @@ import type { SubscriptionChangeEvent } from '../../subscription/subscriptionSer
import { arePlusFeaturesEnabled, ensurePlusFeaturesEnabled } from '../../subscription/utils'; import { arePlusFeaturesEnabled, ensurePlusFeaturesEnabled } from '../../subscription/utils';
import type { import type {
DismissBannerParams, DismissBannerParams,
DoubleClickedRefParams,
EnsureRowParams, EnsureRowParams,
GetMissingAvatarsParams, GetMissingAvatarsParams,
GetMissingRefsMetadataParams, GetMissingRefsMetadataParams,
@ -104,7 +107,7 @@ import type {
UpdateColumnParams, UpdateColumnParams,
UpdateRefsVisibilityParams, UpdateRefsVisibilityParams,
UpdateSelectedRepositoryParams, UpdateSelectedRepositoryParams,
UpdateSelectionParams,
UpdateSelectionParams
} from './protocol'; } from './protocol';
import { import {
DidChangeAvatarsNotificationType, DidChangeAvatarsNotificationType,
@ -120,6 +123,7 @@ import {
DidEnsureRowNotificationType, DidEnsureRowNotificationType,
DidSearchNotificationType, DidSearchNotificationType,
DismissBannerCommandType, DismissBannerCommandType,
DoubleClickedRefCommandType,
EnsureRowCommandType, EnsureRowCommandType,
GetMissingAvatarsCommandType, GetMissingAvatarsCommandType,
GetMissingRefsMetadataCommandType, GetMissingRefsMetadataCommandType,
@ -420,6 +424,9 @@ export class GraphWebview extends WebviewBase {
case UpdateRefsVisibilityCommandType.method: case UpdateRefsVisibilityCommandType.method:
onIpc(UpdateRefsVisibilityCommandType, e, params => this.onRefsVisibilityChanged(params)); onIpc(UpdateRefsVisibilityCommandType, e, params => this.onRefsVisibilityChanged(params));
break; break;
case DoubleClickedRefCommandType.method:
onIpc(DoubleClickedRefCommandType, e, params => this.onDoubleClickRef(params));
break;
case UpdateSelectedRepositoryCommandType.method: case UpdateSelectedRepositoryCommandType.method:
onIpc(UpdateSelectedRepositoryCommandType, e, params => this.onSelectedRepositoryChanged(params)); onIpc(UpdateSelectedRepositoryCommandType, e, params => this.onSelectedRepositoryChanged(params));
break; break;
@ -561,6 +568,22 @@ export class GraphWebview extends WebviewBase {
this.updateHiddenRefs(e.refs, e.visible); this.updateHiddenRefs(e.refs, e.visible);
} }
private onDoubleClickRef(e: DoubleClickedRefParams) {
if (e.ref.context) {
const item: GraphItemContext = typeof e.ref.context === 'string'
? JSON.parse(e.ref.context)
: e.ref.context as GraphItemContext;
const { ref } = item.webviewItemValue as GraphItemRefContextValue;
if (e.ref.refType === 'head' && (e.ref as Head).isCurrentHead) {
return GitActions.switchTo(ref.repoPath);
}
return GitActions.switchTo(ref.repoPath, ref);
}
return Promise.resolve();
}
@debug() @debug()
private async onEnsureRow(e: EnsureRowParams, completionId?: string) { private async onEnsureRow(e: EnsureRowParams, completionId?: string) {
if (this._graph == null) return; if (this._graph == null) return;

+ 6
- 0
src/plus/webviews/graph/protocol.ts View File

@ -2,6 +2,7 @@ import type {
CssVariables, CssVariables,
GraphColumnSetting, GraphColumnSetting,
GraphContexts, GraphContexts,
GraphRef,
GraphRefOptData, GraphRefOptData,
GraphRow, GraphRow,
GraphZoneType, GraphZoneType,
@ -178,6 +179,11 @@ export const UpdateRefsVisibilityCommandType = new IpcCommandType
'graph/refs/update/visibility', 'graph/refs/update/visibility',
); );
export interface DoubleClickedRefParams {
ref: GraphRef
}
export const DoubleClickedRefCommandType = new IpcCommandType<DoubleClickedRefParams>('graph/ref/doubleclick');
export interface UpdateSelectedRepositoryParams { export interface UpdateSelectedRepositoryParams {
path: string; path: string;
} }

+ 12
- 1
src/webviews/apps/plus/graph/GraphWrapper.tsx View File

@ -3,7 +3,9 @@ import type {
GraphColumnSetting, GraphColumnSetting,
GraphContainerProps, GraphContainerProps,
GraphPlatform, GraphPlatform,
GraphRefOptData,
GraphRef,
GraphRefGroup,
GraphRefOptData,
GraphRow, GraphRow,
OnFormatCommitDateTime, OnFormatCommitDateTime,
} from '@gitkraken/gitkraken-components'; } from '@gitkraken/gitkraken-components';
@ -57,6 +59,7 @@ export interface GraphWrapperProps {
subscriber: (callback: UpdateStateCallback) => () => void; subscriber: (callback: UpdateStateCallback) => () => void;
onSelectRepository?: (repository: GraphRepository) => void; onSelectRepository?: (repository: GraphRepository) => void;
onColumnChange?: (name: GraphColumnName, settings: GraphColumnConfig) => void; onColumnChange?: (name: GraphColumnName, settings: GraphColumnConfig) => void;
onDoubleClickRef?: (ref: GraphRef) => void;
onMissingAvatars?: (emails: { [email: string]: string }) => void; onMissingAvatars?: (emails: { [email: string]: string }) => void;
onMissingRefsMetadata?: (metadata: GraphMissingRefsMetadata) => void; onMissingRefsMetadata?: (metadata: GraphMissingRefsMetadata) => void;
onMoreRows?: (id?: string) => void; onMoreRows?: (id?: string) => void;
@ -140,6 +143,7 @@ export function GraphWrapper({
state, state,
onSelectRepository, onSelectRepository,
onColumnChange, onColumnChange,
onDoubleClickRef,
onEnsureRowPromise, onEnsureRowPromise,
onMissingAvatars, onMissingAvatars,
onMissingRefsMetadata, onMissingRefsMetadata,
@ -506,6 +510,12 @@ export function GraphWrapper({
onRefsVisibilityChange?.(refs, visible); onRefsVisibilityChange?.(refs, visible);
}; };
const handleOnDoubleClickRef = (event: React.MouseEvent<HTMLButtonElement, globalThis.MouseEvent>, refGroup: GraphRefGroup) => {
if (refGroup.length > 0) {
onDoubleClickRef?.(refGroup[0]);
}
};
const handleSelectGraphRows = (rows: GraphRow[]) => { const handleSelectGraphRows = (rows: GraphRow[]) => {
const active = rows[0]; const active = rows[0];
const activeKey = active != null ? `${active.sha}|${active.date}` : undefined; const activeKey = active != null ? `${active.sha}|${active.date}` : undefined;
@ -733,6 +743,7 @@ export function GraphWrapper({
isSelectedBySha={selectedRows} isSelectedBySha={selectedRows}
nonce={nonce} nonce={nonce}
onColumnResized={handleOnColumnResized} onColumnResized={handleOnColumnResized}
onDoubleClickGraphRef={handleOnDoubleClickRef}
onSelectGraphRows={handleSelectGraphRows} onSelectGraphRows={handleSelectGraphRows}
onToggleRefsVisibilityClick={handleOnToggleRefsVisibilityClick} onToggleRefsVisibilityClick={handleOnToggleRefsVisibilityClick}
onEmailsMissingAvatarUrls={handleMissingAvatars} onEmailsMissingAvatarUrls={handleMissingAvatars}

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

@ -1,5 +1,5 @@
/*global document window*/ /*global document window*/
import type { CssVariables, GraphRow } from '@gitkraken/gitkraken-components';
import type { CssVariables, GraphRef, GraphRow } from '@gitkraken/gitkraken-components';
import React from 'react'; import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom'; import { render, unmountComponentAtNode } from 'react-dom';
import type { GitGraphRowType } from '../../../../git/models/graph'; import type { GitGraphRowType } from '../../../../git/models/graph';
@ -14,7 +14,7 @@ import type {
GraphRepository, GraphRepository,
InternalNotificationType, InternalNotificationType,
State, State,
UpdateStateCallback,
UpdateStateCallback
} from '../../../../plus/webviews/graph/protocol'; } from '../../../../plus/webviews/graph/protocol';
import { import {
DidChangeAvatarsNotificationType, DidChangeAvatarsNotificationType,
@ -30,6 +30,7 @@ import {
DidEnsureRowNotificationType, DidEnsureRowNotificationType,
DidSearchNotificationType, DidSearchNotificationType,
DismissBannerCommandType, DismissBannerCommandType,
DoubleClickedRefCommandType,
EnsureRowCommandType, EnsureRowCommandType,
GetMissingAvatarsCommandType, GetMissingAvatarsCommandType,
GetMissingRefsMetadataCommandType, GetMissingRefsMetadataCommandType,
@ -94,6 +95,7 @@ export class GraphApp extends App {
path => this.onRepositorySelectionChanged(path), path => this.onRepositorySelectionChanged(path),
250, 250,
)} )}
onDoubleClickRef={(ref) => this.onDoubleClickRef(ref)}
onMissingAvatars={(...params) => this.onGetMissingAvatars(...params)} onMissingAvatars={(...params) => this.onGetMissingAvatars(...params)}
onMissingRefsMetadata={(...params) => this.onGetMissingRefsMetadata(...params)} onMissingRefsMetadata={(...params) => this.onGetMissingRefsMetadata(...params)}
onMoreRows={(...params) => this.onGetMoreRows(...params)} onMoreRows={(...params) => this.onGetMoreRows(...params)}
@ -390,6 +392,12 @@ export class GraphApp extends App {
}); });
} }
private onDoubleClickRef(ref: GraphRef) {
this.sendCommand(DoubleClickedRefCommandType, {
ref: ref,
});
}
private onRepositorySelectionChanged(repo: GraphRepository) { private onRepositorySelectionChanged(repo: GraphRepository) {
this.sendCommand(UpdateRepositorySelectionCommandType, { this.sendCommand(UpdateRepositorySelectionCommandType, {
path: repo.path, path: repo.path,

Loading…
Cancel
Save