diff --git a/src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs b/src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs index 3c90c2bdabc..aabe09e095e 100644 --- a/src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs +++ b/src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs @@ -26,13 +26,13 @@ public static async Task GenerateCodePanelDataAsync(CodePanelRawD codePanelData.AddNavigation(rootNodeId, CreateRootNode($"{codeFile.PackageName} {codeFile.PackageVersion}", rootNodeId)); //Collect documentation lines from active revision - CollectDocumentationLines(codeFile.ReviewLines, codePanelData.ActiveDocumentationMap, 1, "root"); + CollectDocumentationLines(codePanelData, codeFile.ReviewLines, codePanelData.ActiveDocumentationMap, 1, "root"); //Calculate the diff if diff revision code file is present if (codePanelRawData.diffRevisionCodeFile != null) { var diffLines = codePanelRawData.diffRevisionCodeFile.ReviewLines; - CollectDocumentationLines(diffLines, codePanelData.DiffDocumentationMap, 1, "root", true); + CollectDocumentationLines(codePanelData, diffLines, codePanelData.DiffDocumentationMap, 1, "root", true); // Check if diff is required for active revision and diff revision to avoid unnecessary diff calculation bool hasSameApis = AreCodeFilesSame(codePanelRawData.activeRevisionCodeFile, codePanelRawData.diffRevisionCodeFile); if(!hasSameApis) @@ -175,7 +175,7 @@ private static NavigationTreeNode CreateRootNode(string rootName, string nodeIdH private static void BuildNodeTokens(CodePanelData codePanelData, CodePanelRawData codePanelRawData, ReviewLine reviewLine, string nodeIdHashed, int indent) { // Generate code line row - var codePanelRow = GetCodePanelRowData(reviewLine, nodeIdHashed, indent); + var codePanelRow = GetCodePanelRowData(codePanelData, reviewLine, nodeIdHashed, indent); // Add documentation rows to code panel data if (codePanelData.ActiveDocumentationMap.ContainsKey(nodeIdHashed)) @@ -216,7 +216,7 @@ private static void BuildNodeTokens(CodePanelData codePanelData, CodePanelRawDat AddDiagnosticRow(codePanelData: codePanelData, codeFile: codePanelRawData.activeRevisionCodeFile, nodeId: reviewLine.LineId, nodeIdHashed: nodeIdHashed); } - private static CodePanelRowData GetCodePanelRowData(ReviewLine reviewLine, string nodeIdHashed, int indent) + private static CodePanelRowData GetCodePanelRowData(CodePanelData codePanelData, ReviewLine reviewLine, string nodeIdHashed, int indent) { CodePanelRowData codePanelRowData = new() { @@ -238,14 +238,14 @@ private static CodePanelRowData GetCodePanelRowData(ReviewLine reviewLine, strin return codePanelRowData; } - if(reviewLine.DiffKind == DiffKind.Added) + if(reviewLine.DiffKind == DiffKind.Added || reviewLine.DiffKind == DiffKind.Removed) { - rowClasses.Add("added"); - } - else if (reviewLine.DiffKind == DiffKind.Removed) - { - rowClasses.Add("removed"); + rowClasses.Add(reviewLine.DiffKind.ToString().ToLower()); + if (codePanelRowData.IsHiddenAPI) { + codePanelData.HasHiddenAPIThatIsDiff = true; + } } + // Convert ReviewToken to UI required StructuredToken foreach (var token in reviewLine.Tokens) { @@ -286,6 +286,7 @@ private static CodePanelRowData CollectUserCommentsForRow(CodePanelRawData codeP commentRowData.CommentsObj = commentsForRow.ToList(); codePanelRowData.ToggleCommentsClasses = codePanelRowData.ToggleCommentsClasses.Replace("can-show", "show"); commentRowData.IsResolvedCommentThread = commentsForRow.Any(c => c.IsResolved); + commentRowData.IsHiddenAPI = codePanelRowData.IsHiddenAPI; } } else @@ -457,7 +458,7 @@ private static void MarkTreeNodeAsModified(ReviewLine line, DiffKind diffKind) * This method collects all documentation lines from the review line and generate a CodePanelRow object for each documentation line. * These documentation rows will be stored in a dictionary so it can be mapped and connected tp code line when processing code lines. * */ - private static void CollectDocumentationLines(List reviewLines, Dictionary> documentationRowMap, int indent, string parentNodeIdHash, bool enableSkipDiff = false) + private static void CollectDocumentationLines(CodePanelData codePanelData, List reviewLines, Dictionary> documentationRowMap, int indent, string parentNodeIdHash, bool enableSkipDiff = false) { if(reviewLines?.Count == 0) return; @@ -471,7 +472,7 @@ private static void CollectDocumentationLines(List reviewLines, Dict bool hasNonSkippedTokens = line.Tokens.Any(t => t.SkipDiff != true); if(line.IsDocumentation && (!enableSkipDiff ||hasNonSkippedTokens)) { - docRows.Add(GetCodePanelRowData(line, parentNodeIdHash, indent)); + docRows.Add(GetCodePanelRowData(codePanelData, line, parentNodeIdHash, indent)); continue; } @@ -487,7 +488,7 @@ private static void CollectDocumentationLines(List reviewLines, Dict idx++; // Recursively process child node lines if (line.Children.Count > 0) - CollectDocumentationLines(line.Children, documentationRowMap, indent + 1, nodeIdHashed, enableSkipDiff); + CollectDocumentationLines(codePanelData, line.Children, documentationRowMap, indent + 1, nodeIdHashed, enableSkipDiff); } } diff --git a/src/dotnet/APIView/APIViewWeb/LeanModels/CodePanelModels.cs b/src/dotnet/APIView/APIViewWeb/LeanModels/CodePanelModels.cs index 6ab77bc264b..5e8bf732388 100644 --- a/src/dotnet/APIView/APIViewWeb/LeanModels/CodePanelModels.cs +++ b/src/dotnet/APIView/APIViewWeb/LeanModels/CodePanelModels.cs @@ -99,6 +99,7 @@ public class CodePanelData public Dictionary NodeMetaDataObj { get; set; } = new Dictionary(); public Dictionary NodeMetaData => NodeMetaDataObj.Count > 0 ? NodeMetaDataObj : null; public bool HasDiff { get; set; } = false; + public bool HasHiddenAPIThatIsDiff { get; set; } = false; [JsonIgnore] public Dictionary LineIdToNodeIdHashed { get; set; } = new Dictionary(); [JsonIgnore] diff --git a/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html b/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html index 9f2c5b7fb10..9b6ef816bdd 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html +++ b/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html @@ -2,8 +2,8 @@
Loading...
-
+
diff --git a/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts b/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts index a168d02f0de..45955efe375 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts +++ b/src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts @@ -14,7 +14,6 @@ import { MessageService } from 'primeng/api'; import { SignalRService } from 'src/app/_services/signal-r/signal-r.service'; import { Subject } from 'rxjs'; import { CommentThreadUpdateAction, CommentUpdatesDto } from 'src/app/_dtos/commentThreadUpdateDto'; -import { computeStyles } from '@popperjs/core'; @Component({ selector: 'app-code-panel', @@ -39,6 +38,7 @@ export class CodePanelComponent implements OnChanges{ noDiffInContentMessage : Message[] = [{ severity: 'info', icon:'bi bi-info-circle', detail: 'There is no difference between the two API revisions.' }]; + isLoading: boolean = true; codeWindowHeight: string | undefined = undefined; codePanelRowDataIndicesMap = new Map(); @@ -422,7 +422,10 @@ export class CodePanelComponent implements OnChanges{ index++; } if (scrollIndex) { - this.codePanelRowSource?.adapter?.reload(scrollIndex); + let scrollPadding = 0; + scrollPadding = (this.showNoDiffInContentMessage()) ? scrollPadding + 2 : scrollPadding; + + this.codePanelRowSource?.adapter?.reload(scrollIndex - scrollPadding); let newQueryParams = getQueryParams(this.route); newQueryParams[SCROLL_TO_NODE_QUERY_PARAM] = this.codePanelRowData[scrollIndex].nodeId; this.router.navigate([], { queryParams: newQueryParams, state: { skipStateUpdate: true } }); @@ -666,6 +669,10 @@ export class CodePanelComponent implements OnChanges{ } return undefined; } + + showNoDiffInContentMessage() { + return this.codePanelData && !this.isLoading && this.isDiffView && !this.codePanelData?.hasDiff + } private updateHasActiveConversations() { let hasActiveConversation = false; diff --git a/src/dotnet/APIView/ClientSPA/src/app/_components/review-page-options/review-page-options.component.ts b/src/dotnet/APIView/ClientSPA/src/app/_components/review-page-options/review-page-options.component.ts index c40bc9d587f..8d86cd8c473 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_components/review-page-options/review-page-options.component.ts +++ b/src/dotnet/APIView/ClientSPA/src/app/_components/review-page-options/review-page-options.component.ts @@ -29,6 +29,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{ @Input() hasFatalDiagnostics : boolean = false; @Input() hasActiveConversation : boolean = false; @Input() hasHiddenAPIs : boolean = false; + @Input() hasHiddenAPIThatIsDiff : boolean = false; @Output() diffStyleEmitter : EventEmitter = new EventEmitter(); @Output() showCommentsEmitter : EventEmitter = new EventEmitter(); @@ -135,6 +136,10 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{ this.setSubscribeSwitch(); this.setReviewApprovalStatus(); } + + if (changes['hasHiddenAPIThatIsDiff']) { + this.setPageOptionValues(); + } } /** @@ -256,10 +261,10 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{ this.showCommentsSwitch = this.userProfile?.preferences.showComments ?? this.showCommentsSwitch; this.showSystemCommentsSwitch = this.userProfile?.preferences.showSystemComments ?? this.showSystemCommentsSwitch; this.showDocumentationSwitch = this.userProfile?.preferences.showDocumentation ?? this.showDocumentationSwitch; - this.showHiddenAPISwitch = this.userProfile?.preferences.showHiddenApis ?? this.showHiddenAPISwitch; this.disableCodeLinesLazyLoading = this.userProfile?.preferences.disableCodeLinesLazyLoading ?? this.disableCodeLinesLazyLoading; this.showLineNumbersSwitch = (this.userProfile?.preferences.hideLineNumbers) ? false : this.showLineNumbersSwitch; this.showLeftNavigationSwitch = (this.userProfile?.preferences.hideLeftNavigation) ? false : this.showLeftNavigationSwitch; + this.showHiddenAPISwitch = (this.userProfile?.preferences.showHiddenApis || this.hasHiddenAPIThatIsDiff || this.showHiddenAPISwitch) ? true : false; } setAPIRevisionApprovalStates() { diff --git a/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.html b/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.html index 0db6a08ef15..7ffb7a8b2df 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.html +++ b/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.html @@ -58,6 +58,7 @@ [hasFatalDiagnostics]="hasFatalDiagnostics" [hasActiveConversation]="hasActiveConversation" [hasHiddenAPIs]="hasHiddenAPIs" + [hasHiddenAPIThatIsDiff]="hasHiddenAPIThatIsDiff" (showSystemCommentsEmitter)="handleShowSystemCommentsEmitter($event)" (showDocumentationEmitter)="handleShowDocumentationEmitter($event)" (showCommentsEmitter)="handleShowCommentsEmitter($event)" diff --git a/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.ts b/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.ts index 332022cffd7..e929f583613 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.ts +++ b/src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.ts @@ -51,6 +51,7 @@ export class ReviewPageComponent implements OnInit { hasActiveConversation : boolean = false; numberOfActiveConversation : number = 0; hasHiddenAPIs : boolean = false; + hasHiddenAPIThatIsDiff : boolean = false; loadFailed : boolean = false; showLeftNavigation : boolean = true; @@ -165,6 +166,7 @@ export class ReviewPageComponent implements OnInit { if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelData) { this.codePanelData = data.payload as CodePanelData; + this.hasHiddenAPIThatIsDiff = this.codePanelData.hasHiddenAPIThatIsDiff; this.workerService.terminateWorker(); } }); diff --git a/src/dotnet/APIView/ClientSPA/src/app/_models/codePanelModels.ts b/src/dotnet/APIView/ClientSPA/src/app/_models/codePanelModels.ts index ecb495ef2fe..2844d2ab0d4 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_models/codePanelModels.ts +++ b/src/dotnet/APIView/ClientSPA/src/app/_models/codePanelModels.ts @@ -57,6 +57,7 @@ export class CodePanelRowData { export interface CodePanelData { nodeMetaData: { [key: string]: CodePanelNodeMetaData }; hasDiff: boolean; + hasHiddenAPIThatIsDiff: boolean; } export class CodePanelNodeMetaData { diff --git a/src/dotnet/APIView/ClientSPA/src/app/_workers/apitree-builder.worker.ts b/src/dotnet/APIView/ClientSPA/src/app/_workers/apitree-builder.worker.ts index dfb3bacb318..8f60846afda 100644 --- a/src/dotnet/APIView/ClientSPA/src/app/_workers/apitree-builder.worker.ts +++ b/src/dotnet/APIView/ClientSPA/src/app/_workers/apitree-builder.worker.ts @@ -43,7 +43,7 @@ addEventListener('message', ({ data }) => { const hasHiddenAPIMessage : InsertCodePanelRowDataMessage = { directive: ReviewPageWorkerMessageDirective.SetHasHiddenAPIFlag, - payload: hasHiddenAPI + payload: hasHiddenAPI, }; postMessage(hasHiddenAPIMessage); @@ -203,11 +203,13 @@ function buildCodePanelRows(nodeIdHashed: string, navigationTree: NavigationTree if (bottomTokenNode.codeLines) { bottomTokenNode.codeLines.forEach((codeLine, index) => { - codeLine.toggleDocumentationClasses = `bi ${toggleDocumentationClassPart} hide`; - setLineNumber(codeLine); - if (buildNode) { - codePanelRowData.push(codeLine); - visibleNodes.add(codeLine.nodeIdHashed); + if (shouldAppendIfRowIsHiddenAPI(codeLine)) { + codeLine.toggleDocumentationClasses = `bi ${toggleDocumentationClassPart} hide`; + setLineNumber(codeLine); + if (buildNode) { + codePanelRowData.push(codeLine); + visibleNodes.add(codeLine.nodeIdHashed); + } } }); } @@ -246,7 +248,7 @@ function addJustDiffBuffer() { function shouldAppendIfRowIsHiddenAPI(row: CodePanelRowData) { if (row.isHiddenAPI) { hasHiddenAPI = true; - return apiTreeBuilderData?.showHiddenApis; + return apiTreeBuilderData?.showHiddenApis || codePanelData?.hasHiddenAPIThatIsDiff; } else { return true; }