Skip to content

Commit b727d85

Browse files
Show Hidden APIs always if one of them is a diff (Azure#8934)
1 parent 8d731be commit b727d85

File tree

9 files changed

+44
-24
lines changed

9 files changed

+44
-24
lines changed

src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public static async Task<CodePanelData> GenerateCodePanelDataAsync(CodePanelRawD
2626
codePanelData.AddNavigation(rootNodeId, CreateRootNode($"{codeFile.PackageName} {codeFile.PackageVersion}", rootNodeId));
2727

2828
//Collect documentation lines from active revision
29-
CollectDocumentationLines(codeFile.ReviewLines, codePanelData.ActiveDocumentationMap, 1, "root");
29+
CollectDocumentationLines(codePanelData, codeFile.ReviewLines, codePanelData.ActiveDocumentationMap, 1, "root");
3030

3131
//Calculate the diff if diff revision code file is present
3232
if (codePanelRawData.diffRevisionCodeFile != null)
3333
{
3434
var diffLines = codePanelRawData.diffRevisionCodeFile.ReviewLines;
35-
CollectDocumentationLines(diffLines, codePanelData.DiffDocumentationMap, 1, "root", true);
35+
CollectDocumentationLines(codePanelData, diffLines, codePanelData.DiffDocumentationMap, 1, "root", true);
3636
// Check if diff is required for active revision and diff revision to avoid unnecessary diff calculation
3737
bool hasSameApis = AreCodeFilesSame(codePanelRawData.activeRevisionCodeFile, codePanelRawData.diffRevisionCodeFile);
3838
if(!hasSameApis)
@@ -175,7 +175,7 @@ private static NavigationTreeNode CreateRootNode(string rootName, string nodeIdH
175175
private static void BuildNodeTokens(CodePanelData codePanelData, CodePanelRawData codePanelRawData, ReviewLine reviewLine, string nodeIdHashed, int indent)
176176
{
177177
// Generate code line row
178-
var codePanelRow = GetCodePanelRowData(reviewLine, nodeIdHashed, indent);
178+
var codePanelRow = GetCodePanelRowData(codePanelData, reviewLine, nodeIdHashed, indent);
179179

180180
// Add documentation rows to code panel data
181181
if (codePanelData.ActiveDocumentationMap.ContainsKey(nodeIdHashed))
@@ -216,7 +216,7 @@ private static void BuildNodeTokens(CodePanelData codePanelData, CodePanelRawDat
216216
AddDiagnosticRow(codePanelData: codePanelData, codeFile: codePanelRawData.activeRevisionCodeFile, nodeId: reviewLine.LineId, nodeIdHashed: nodeIdHashed);
217217
}
218218

219-
private static CodePanelRowData GetCodePanelRowData(ReviewLine reviewLine, string nodeIdHashed, int indent)
219+
private static CodePanelRowData GetCodePanelRowData(CodePanelData codePanelData, ReviewLine reviewLine, string nodeIdHashed, int indent)
220220
{
221221
CodePanelRowData codePanelRowData = new()
222222
{
@@ -238,14 +238,14 @@ private static CodePanelRowData GetCodePanelRowData(ReviewLine reviewLine, strin
238238
return codePanelRowData;
239239
}
240240

241-
if(reviewLine.DiffKind == DiffKind.Added)
241+
if(reviewLine.DiffKind == DiffKind.Added || reviewLine.DiffKind == DiffKind.Removed)
242242
{
243-
rowClasses.Add("added");
244-
}
245-
else if (reviewLine.DiffKind == DiffKind.Removed)
246-
{
247-
rowClasses.Add("removed");
243+
rowClasses.Add(reviewLine.DiffKind.ToString().ToLower());
244+
if (codePanelRowData.IsHiddenAPI) {
245+
codePanelData.HasHiddenAPIThatIsDiff = true;
246+
}
248247
}
248+
249249
// Convert ReviewToken to UI required StructuredToken
250250
foreach (var token in reviewLine.Tokens)
251251
{
@@ -286,6 +286,7 @@ private static CodePanelRowData CollectUserCommentsForRow(CodePanelRawData codeP
286286
commentRowData.CommentsObj = commentsForRow.ToList();
287287
codePanelRowData.ToggleCommentsClasses = codePanelRowData.ToggleCommentsClasses.Replace("can-show", "show");
288288
commentRowData.IsResolvedCommentThread = commentsForRow.Any(c => c.IsResolved);
289+
commentRowData.IsHiddenAPI = codePanelRowData.IsHiddenAPI;
289290
}
290291
}
291292
else
@@ -457,7 +458,7 @@ private static void MarkTreeNodeAsModified(ReviewLine line, DiffKind diffKind)
457458
* This method collects all documentation lines from the review line and generate a CodePanelRow object for each documentation line.
458459
* These documentation rows will be stored in a dictionary so it can be mapped and connected tp code line when processing code lines.
459460
* */
460-
private static void CollectDocumentationLines(List<ReviewLine> reviewLines, Dictionary<string,List<CodePanelRowData>> documentationRowMap, int indent, string parentNodeIdHash, bool enableSkipDiff = false)
461+
private static void CollectDocumentationLines(CodePanelData codePanelData, List<ReviewLine> reviewLines, Dictionary<string,List<CodePanelRowData>> documentationRowMap, int indent, string parentNodeIdHash, bool enableSkipDiff = false)
461462
{
462463
if(reviewLines?.Count == 0)
463464
return;
@@ -471,7 +472,7 @@ private static void CollectDocumentationLines(List<ReviewLine> reviewLines, Dict
471472
bool hasNonSkippedTokens = line.Tokens.Any(t => t.SkipDiff != true);
472473
if(line.IsDocumentation && (!enableSkipDiff ||hasNonSkippedTokens))
473474
{
474-
docRows.Add(GetCodePanelRowData(line, parentNodeIdHash, indent));
475+
docRows.Add(GetCodePanelRowData(codePanelData, line, parentNodeIdHash, indent));
475476
continue;
476477
}
477478

@@ -487,7 +488,7 @@ private static void CollectDocumentationLines(List<ReviewLine> reviewLines, Dict
487488
idx++;
488489
// Recursively process child node lines
489490
if (line.Children.Count > 0)
490-
CollectDocumentationLines(line.Children, documentationRowMap, indent + 1, nodeIdHashed, enableSkipDiff);
491+
CollectDocumentationLines(codePanelData, line.Children, documentationRowMap, indent + 1, nodeIdHashed, enableSkipDiff);
491492
}
492493
}
493494

src/dotnet/APIView/APIViewWeb/LeanModels/CodePanelModels.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class CodePanelData
9999
public Dictionary<string, CodePanelNodeMetaData> NodeMetaDataObj { get; set; } = new Dictionary<string, CodePanelNodeMetaData>();
100100
public Dictionary<string, CodePanelNodeMetaData> NodeMetaData => NodeMetaDataObj.Count > 0 ? NodeMetaDataObj : null;
101101
public bool HasDiff { get; set; } = false;
102+
public bool HasHiddenAPIThatIsDiff { get; set; } = false;
102103
[JsonIgnore]
103104
public Dictionary<string, string> LineIdToNodeIdHashed { get; set; } = new Dictionary<string, string>();
104105
[JsonIgnore]

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div *ngIf="isLoading" class="spinner-border m-3" role="status">
33
<span class="visually-hidden">Loading...</span>
44
</div>
5-
<p-messages *ngIf="codePanelData && !isLoading && isDiffView && !codePanelData?.hasDiff" [(value)]="noDiffInContentMessage" [closable]="false" />
65
<div *ngIf="codePanelRowSource;" class="viewport {{languageSafeName!}}" (click)="onCodePanelItemClick($event)">
6+
<p-messages class="sticky-top" *ngIf="showNoDiffInContentMessage()" [(value)]="noDiffInContentMessage" [closable]="false" />
77
<div *uiScroll="let item of codePanelRowSource; let index = index" class="code-line" [attr.data-node-id]="item.nodeIdHashed"
88
[attr.data-row-position-in-group]="item.rowPositionInGroup" [attr.data-row-type]="item.type" [ngClass]="getRowClassObject(item)">
99
<ng-container *ngIf="item.type === CodePanelRowDatatype.CodeLine || item.type === CodePanelRowDatatype.Documentation">

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { MessageService } from 'primeng/api';
1414
import { SignalRService } from 'src/app/_services/signal-r/signal-r.service';
1515
import { Subject } from 'rxjs';
1616
import { CommentThreadUpdateAction, CommentUpdatesDto } from 'src/app/_dtos/commentThreadUpdateDto';
17-
import { computeStyles } from '@popperjs/core';
1817

1918
@Component({
2019
selector: 'app-code-panel',
@@ -39,6 +38,7 @@ export class CodePanelComponent implements OnChanges{
3938

4039

4140
noDiffInContentMessage : Message[] = [{ severity: 'info', icon:'bi bi-info-circle', detail: 'There is no difference between the two API revisions.' }];
41+
4242
isLoading: boolean = true;
4343
codeWindowHeight: string | undefined = undefined;
4444
codePanelRowDataIndicesMap = new Map<string, number>();
@@ -422,7 +422,10 @@ export class CodePanelComponent implements OnChanges{
422422
index++;
423423
}
424424
if (scrollIndex) {
425-
this.codePanelRowSource?.adapter?.reload(scrollIndex);
425+
let scrollPadding = 0;
426+
scrollPadding = (this.showNoDiffInContentMessage()) ? scrollPadding + 2 : scrollPadding;
427+
428+
this.codePanelRowSource?.adapter?.reload(scrollIndex - scrollPadding);
426429
let newQueryParams = getQueryParams(this.route);
427430
newQueryParams[SCROLL_TO_NODE_QUERY_PARAM] = this.codePanelRowData[scrollIndex].nodeId;
428431
this.router.navigate([], { queryParams: newQueryParams, state: { skipStateUpdate: true } });
@@ -666,6 +669,10 @@ export class CodePanelComponent implements OnChanges{
666669
}
667670
return undefined;
668671
}
672+
673+
showNoDiffInContentMessage() {
674+
return this.codePanelData && !this.isLoading && this.isDiffView && !this.codePanelData?.hasDiff
675+
}
669676

670677
private updateHasActiveConversations() {
671678
let hasActiveConversation = false;

src/dotnet/APIView/ClientSPA/src/app/_components/review-page-options/review-page-options.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
2929
@Input() hasFatalDiagnostics : boolean = false;
3030
@Input() hasActiveConversation : boolean = false;
3131
@Input() hasHiddenAPIs : boolean = false;
32+
@Input() hasHiddenAPIThatIsDiff : boolean = false;
3233

3334
@Output() diffStyleEmitter : EventEmitter<string> = new EventEmitter<string>();
3435
@Output() showCommentsEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
@@ -135,6 +136,10 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
135136
this.setSubscribeSwitch();
136137
this.setReviewApprovalStatus();
137138
}
139+
140+
if (changes['hasHiddenAPIThatIsDiff']) {
141+
this.setPageOptionValues();
142+
}
138143
}
139144

140145
/**
@@ -256,10 +261,10 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
256261
this.showCommentsSwitch = this.userProfile?.preferences.showComments ?? this.showCommentsSwitch;
257262
this.showSystemCommentsSwitch = this.userProfile?.preferences.showSystemComments ?? this.showSystemCommentsSwitch;
258263
this.showDocumentationSwitch = this.userProfile?.preferences.showDocumentation ?? this.showDocumentationSwitch;
259-
this.showHiddenAPISwitch = this.userProfile?.preferences.showHiddenApis ?? this.showHiddenAPISwitch;
260264
this.disableCodeLinesLazyLoading = this.userProfile?.preferences.disableCodeLinesLazyLoading ?? this.disableCodeLinesLazyLoading;
261265
this.showLineNumbersSwitch = (this.userProfile?.preferences.hideLineNumbers) ? false : this.showLineNumbersSwitch;
262266
this.showLeftNavigationSwitch = (this.userProfile?.preferences.hideLeftNavigation) ? false : this.showLeftNavigationSwitch;
267+
this.showHiddenAPISwitch = (this.userProfile?.preferences.showHiddenApis || this.hasHiddenAPIThatIsDiff || this.showHiddenAPISwitch) ? true : false;
263268
}
264269

265270
setAPIRevisionApprovalStates() {

src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
[hasFatalDiagnostics]="hasFatalDiagnostics"
5959
[hasActiveConversation]="hasActiveConversation"
6060
[hasHiddenAPIs]="hasHiddenAPIs"
61+
[hasHiddenAPIThatIsDiff]="hasHiddenAPIThatIsDiff"
6162
(showSystemCommentsEmitter)="handleShowSystemCommentsEmitter($event)"
6263
(showDocumentationEmitter)="handleShowDocumentationEmitter($event)"
6364
(showCommentsEmitter)="handleShowCommentsEmitter($event)"

src/dotnet/APIView/ClientSPA/src/app/_components/review-page/review-page.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class ReviewPageComponent implements OnInit {
5151
hasActiveConversation : boolean = false;
5252
numberOfActiveConversation : number = 0;
5353
hasHiddenAPIs : boolean = false;
54+
hasHiddenAPIThatIsDiff : boolean = false;
5455
loadFailed : boolean = false;
5556

5657
showLeftNavigation : boolean = true;
@@ -165,6 +166,7 @@ export class ReviewPageComponent implements OnInit {
165166

166167
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelData) {
167168
this.codePanelData = data.payload as CodePanelData;
169+
this.hasHiddenAPIThatIsDiff = this.codePanelData.hasHiddenAPIThatIsDiff;
168170
this.workerService.terminateWorker();
169171
}
170172
});

src/dotnet/APIView/ClientSPA/src/app/_models/codePanelModels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class CodePanelRowData {
5757
export interface CodePanelData {
5858
nodeMetaData: { [key: string]: CodePanelNodeMetaData };
5959
hasDiff: boolean;
60+
hasHiddenAPIThatIsDiff: boolean;
6061
}
6162

6263
export class CodePanelNodeMetaData {

src/dotnet/APIView/ClientSPA/src/app/_workers/apitree-builder.worker.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ addEventListener('message', ({ data }) => {
4343

4444
const hasHiddenAPIMessage : InsertCodePanelRowDataMessage = {
4545
directive: ReviewPageWorkerMessageDirective.SetHasHiddenAPIFlag,
46-
payload: hasHiddenAPI
46+
payload: hasHiddenAPI,
4747
};
4848
postMessage(hasHiddenAPIMessage);
4949

@@ -203,11 +203,13 @@ function buildCodePanelRows(nodeIdHashed: string, navigationTree: NavigationTree
203203

204204
if (bottomTokenNode.codeLines) {
205205
bottomTokenNode.codeLines.forEach((codeLine, index) => {
206-
codeLine.toggleDocumentationClasses = `bi ${toggleDocumentationClassPart} hide`;
207-
setLineNumber(codeLine);
208-
if (buildNode) {
209-
codePanelRowData.push(codeLine);
210-
visibleNodes.add(codeLine.nodeIdHashed);
206+
if (shouldAppendIfRowIsHiddenAPI(codeLine)) {
207+
codeLine.toggleDocumentationClasses = `bi ${toggleDocumentationClassPart} hide`;
208+
setLineNumber(codeLine);
209+
if (buildNode) {
210+
codePanelRowData.push(codeLine);
211+
visibleNodes.add(codeLine.nodeIdHashed);
212+
}
211213
}
212214
});
213215
}
@@ -246,7 +248,7 @@ function addJustDiffBuffer() {
246248
function shouldAppendIfRowIsHiddenAPI(row: CodePanelRowData) {
247249
if (row.isHiddenAPI) {
248250
hasHiddenAPI = true;
249-
return apiTreeBuilderData?.showHiddenApis;
251+
return apiTreeBuilderData?.showHiddenApis || codePanelData?.hasHiddenAPIThatIsDiff;
250252
} else {
251253
return true;
252254
}

0 commit comments

Comments
 (0)