From 6adbeefb9911b9d4054729801e31280e0590efef Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 16 Sep 2022 01:15:36 -0400 Subject: [PATCH] Fixes stuck progress on the Graph (again!!) --- src/plus/webviews/graph/graphWebview.ts | 1 + src/plus/webviews/graph/protocol.ts | 3 ++- src/webviews/apps/plus/graph/GraphWrapper.tsx | 10 ++++------ src/webviews/apps/plus/graph/graph.tsx | 26 ++++++++++---------------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index 2c3d05e..d03c758 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -569,6 +569,7 @@ export class GraphWebview extends WebviewBase { subscription: access.subscription.current, allowed: access.allowed, avatars: data != null ? Object.fromEntries(data.avatars) : undefined, + loading: deferRows, rows: data?.rows, paging: data != null diff --git a/src/plus/webviews/graph/protocol.ts b/src/plus/webviews/graph/protocol.ts index 9e281cf..8fa1d00 100644 --- a/src/plus/webviews/graph/protocol.ts +++ b/src/plus/webviews/graph/protocol.ts @@ -13,6 +13,7 @@ export interface State { subscription?: Subscription; allowed: boolean; avatars?: { [email: string]: string }; + loading?: boolean; rows?: GraphRow[]; paging?: GraphPaging; config?: GraphCompositeConfig; @@ -60,7 +61,7 @@ export interface GraphCompositeConfig extends GraphConfig { } export interface UpdateStateCallback { - (state: State, previousRowCount: number | undefined): void; + (state: State): void; } // Commands diff --git a/src/webviews/apps/plus/graph/GraphWrapper.tsx b/src/webviews/apps/plus/graph/GraphWrapper.tsx index d9431c6..cf9ef81 100644 --- a/src/webviews/apps/plus/graph/GraphWrapper.tsx +++ b/src/webviews/apps/plus/graph/GraphWrapper.tsx @@ -143,6 +143,7 @@ export function GraphWrapper({ allowed, avatars, config, + loading, paging, onSelectRepository, onColumnChange, @@ -164,7 +165,7 @@ export function GraphWrapper({ const [graphSelectedRows, setSelectedRows] = useState(selectedRows); const [graphColSettings, setGraphColSettings] = useState(getGraphColSettingsModel(config)); const [pagingState, setPagingState] = useState(paging); - const [isLoading, setIsLoading] = useState(true); + const [isLoading, setIsLoading] = useState(loading); const [styleProps, setStyleProps] = useState(getStyleProps(mixedColumnColors)); // TODO: application shouldn't know about the graph component's header const graphHeaderOffset = 24; @@ -197,7 +198,7 @@ export function GraphWrapper({ return () => resizeObserver.disconnect(); }, [mainRef]); - function transformData(state: State, previousRowCount: number | undefined) { + function transformData(state: State) { setGraphRows(state.rows ?? []); setAvatars(state.avatars ?? {}); setReposList(state.repositories ?? []); @@ -210,10 +211,7 @@ export function GraphWrapper({ setShowAccount(state.trialBanner ?? true); setSubscriptionSnapshot(state.subscription); setIsPrivateRepo(state.selectedRepositoryVisibility === RepositoryVisibility.Private); - - if (!isLoading || previousRowCount !== state.rows?.length || previousRowCount == null) { - setIsLoading(state.rows == null); - } + setIsLoading(state.loading); } useEffect(() => subscriber?.(transformData), []); diff --git a/src/webviews/apps/plus/graph/graph.tsx b/src/webviews/apps/plus/graph/graph.tsx index d1ed952..ee1a6ef 100644 --- a/src/webviews/apps/plus/graph/graph.tsx +++ b/src/webviews/apps/plus/graph/graph.tsx @@ -96,17 +96,15 @@ export class GraphApp extends App { switch (msg.method) { case DidChangeNotificationType.method: onIpc(DidChangeNotificationType, msg, params => { - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, ...params.state }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); }); break; case DidChangeAvatarsNotificationType.method: onIpc(DidChangeAvatarsNotificationType, msg, params => { - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, avatars: params.avatars }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); }); break; @@ -173,42 +171,39 @@ export class GraphApp extends App { } } - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, avatars: params.avatars, rows: rows, + loading: false, paging: params.paging, }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); }); break; case DidChangeSelectionNotificationType.method: onIpc(DidChangeSelectionNotificationType, msg, params => { - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, selectedRows: params.selection }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); }); break; case DidChangeGraphConfigurationNotificationType.method: onIpc(DidChangeGraphConfigurationNotificationType, msg, params => { - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, config: params.config }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); }); break; case DidChangeSubscriptionNotificationType.method: onIpc(DidChangeSubscriptionNotificationType, msg, params => { - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, subscription: params.subscription, allowed: params.allowed, }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); }); break; @@ -218,9 +213,8 @@ export class GraphApp extends App { } protected override onThemeUpdated() { - const previousRowCount = this.state.rows?.length; this.setState({ ...this.state, mixedColumnColors: undefined }); - this.refresh(this.state, previousRowCount); + this.refresh(this.state); } protected override setState(state: State) { @@ -297,8 +291,8 @@ export class GraphApp extends App { }; } - private refresh(state: State, previousRowCount: number | undefined) { - this.callback?.(state, previousRowCount); + private refresh(state: State) { + this.callback?.(state); } }