From 38528246f4590c34e53fa854ef7bcf6d8c4cb8fb Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 11 Dec 2022 10:24:48 -0500 Subject: [PATCH] (wip) hack to demo "include" filtering in Graph --- src/plus/webviews/graph/graphWebview.ts | 25 ++++++++++++++++++++++++- src/plus/webviews/graph/protocol.ts | 5 +++++ src/webviews/apps/plus/graph/GraphWrapper.tsx | 4 ++++ src/webviews/apps/plus/graph/graph.tsx | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index d6c6155..6c610a4 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -35,7 +35,7 @@ import type { Container } from '../../../container'; import { getContext, onDidChangeContext } from '../../../context'; import { PlusFeatures } from '../../../features'; import { GitSearchError } from '../../../git/errors'; -import { getBranchNameWithoutRemote, getRemoteNameFromBranchName } from '../../../git/models/branch'; +import { getBranchId, getBranchNameWithoutRemote, getRemoteNameFromBranchName } from '../../../git/models/branch'; import { GitContributor } from '../../../git/models/contributor'; import { GitGraphRowType } from '../../../git/models/graph'; import type { GitGraph } from '../../../git/models/graph'; @@ -89,6 +89,7 @@ import type { GraphHiddenRef, GraphHiddenRefs, GraphHostingServiceType, + GraphIncludeRef, GraphMissingRefsMetadataType, GraphPullRequestMetadata, GraphRefMetadata, @@ -1029,6 +1030,7 @@ export class GraphWebview extends WebviewBase { return this.notify(DidChangeRefsVisibilityNotificationType, { hiddenRefs: this.getHiddenRefs(this._graph), + includeRefs: this.getIncludeRefs(this._graph), }); } @@ -1271,6 +1273,26 @@ export class GraphWebview extends WebviewBase { return this.filterHiddenRefs(this.container.storage.getWorkspace('graph:hiddenRefs'), graph); } + private getIncludeRefs(graph: GitGraph | undefined): Record | undefined { + if (graph == null) return undefined; + + if (Math.random() < 0.5) return {}; + + return { + [getBranchId(graph.repoPath, false, 'main')]: { + id: getBranchId(graph.repoPath, false, 'main'), + name: 'main', + type: 'head', + }, + [getBranchId(graph.repoPath, true, 'main')]: { + id: getBranchId(graph.repoPath, true, 'main'), + name: 'main', + type: 'head', + owner: 'origin', + }, + }; + } + private filterHiddenRefs( hiddenRefs: Record | undefined, graph: GitGraph | undefined, @@ -1497,6 +1519,7 @@ export class GraphWebview extends WebviewBase { header: this.getColumnHeaderContext(columns), }, hiddenRefs: data != null ? this.getHiddenRefs(data) : undefined, + includeRefs: data != null ? this.getIncludeRefs(data) : undefined, nonce: this.cspNonce, workingTreeStats: getSettledValue(workingStatsResult) ?? { added: 0, deleted: 0, modified: 0 }, }; diff --git a/src/plus/webviews/graph/protocol.ts b/src/plus/webviews/graph/protocol.ts index bfb7513..1058596 100644 --- a/src/plus/webviews/graph/protocol.ts +++ b/src/plus/webviews/graph/protocol.ts @@ -9,6 +9,7 @@ import type { GraphZoneType, Head, HostingServiceType, + IncludeRefsById, PullRequestMetadata, RefMetadata, RefMetadataType, @@ -60,6 +61,7 @@ export interface State { workingTreeStats?: GraphWorkingTreeStats; searchResults?: DidSearchParams['results']; hiddenRefs?: GraphHiddenRefs; + includeRefs?: GraphIncludeRefs; // Props below are computed in the webview (not passed) activeRow?: string; @@ -121,6 +123,8 @@ export type GraphColumnsConfig = { [name: string]: GraphColumnConfig }; export type GraphHiddenRefs = ExcludeRefsById; // TODO: rename all HiddenRefs to use the new naming export type GraphHiddenRef = GraphRefOptData; +export type GraphIncludeRefs = IncludeRefsById; +export type GraphIncludeRef = GraphRefOptData; export type GraphColumnName = GraphZoneType; @@ -259,6 +263,7 @@ export const DidChangeWindowFocusNotificationType = new IpcNotificationType( 'graph/refs/didChangeVisibility', diff --git a/src/webviews/apps/plus/graph/GraphWrapper.tsx b/src/webviews/apps/plus/graph/GraphWrapper.tsx index cc2ec09..773509f 100644 --- a/src/webviews/apps/plus/graph/GraphWrapper.tsx +++ b/src/webviews/apps/plus/graph/GraphWrapper.tsx @@ -163,6 +163,7 @@ export function GraphWrapper({ // const [graphDateFormatter, setGraphDateFormatter] = useState(getGraphDateFormatter(config)); const [columns, setColumns] = useState(state.columns); const [hiddenRefsById, setHiddenRefsById] = useState(state.hiddenRefs); + const [includeRefsById, setIncludeRefsById] = useState(state.includeRefs); const [context, setContext] = useState(state.context); const [pagingHasMore, setPagingHasMore] = useState(state.paging?.hasMore ?? false); const [isLoading, setIsLoading] = useState(state.loading); @@ -246,6 +247,7 @@ export function GraphWrapper({ break; case DidChangeRefsVisibilityNotificationType: setHiddenRefsById(state.hiddenRefs); + setIncludeRefsById(state.includeRefs); break; case DidChangeSubscriptionNotificationType: setIsAccessAllowed(state.allowed ?? false); @@ -270,6 +272,7 @@ export function GraphWrapper({ setGraphConfig(state.config); setSelectedRows(state.selectedRows); setHiddenRefsById(state.hiddenRefs); + setIncludeRefsById(state.includeRefs); setContext(state.context); setAvatars(state.avatars ?? {}); setRefsMetadata(state.refsMetadata); @@ -837,6 +840,7 @@ export function GraphWrapper({ highlightedShas={searchResults?.ids as GraphContainerProps['highlightedShas']} highlightRowsOnRefHover={graphConfig?.highlightRowsOnRefHover} excludeRefsById={hiddenRefsById} + includeRefsById={includeRefsById} scrollRowPadding={graphConfig?.scrollRowPadding} showGhostRefsOnRowHover={graphConfig?.showGhostRefsOnRowHover} showRemoteNamesOnRefs={graphConfig?.showRemoteNamesOnRefs} diff --git a/src/webviews/apps/plus/graph/graph.tsx b/src/webviews/apps/plus/graph/graph.tsx index ea52d2a..94eef75 100644 --- a/src/webviews/apps/plus/graph/graph.tsx +++ b/src/webviews/apps/plus/graph/graph.tsx @@ -171,6 +171,7 @@ export class GraphApp extends App { case DidChangeRefsVisibilityNotificationType.method: onIpc(DidChangeRefsVisibilityNotificationType, msg, (params, type) => { this.state.hiddenRefs = params.hiddenRefs; + this.state.includeRefs = params.includeRefs; this.setState(this.state, type); }); break;