Skip to content

Commit c9853b6

Browse files
Fix Documentation Issues during Diff (#8733)
* Dont show node with diff in only docs when nodes or tree diff is selected * Add message on Page to Report when there is not diff between APIRevision
1 parent fb1b7a2 commit c9853b6

24 files changed

Lines changed: 33023 additions & 181 deletions

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,13 @@ private static void BuildTokensForDiffNodes(CodePanelData codePanelData, CodePan
557557
{
558558
var parentNode = codePanelData.NodeMetaDataObj[parentNodeIdHashed];
559559
parentNode.IsNodeWithDiffInDescendants = true;
560+
561+
if ((diffTokenRowResult.Before.Any() && !beforeRowClasses.Contains("doc")) ||
562+
(diffTokenRowResult.After.Any() && !afterRowClasses.Contains("doc")))
563+
{
564+
parentNode.IsNodeWithNoneDocDiffInDescendants = true;
565+
}
566+
560567
parentNodeIdHashed = parentNode.ParentNodeIdHashed;
561568
}
562569

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using APIView.TreeToken;
2+
using APIView;
3+
using System.Collections.Concurrent;
4+
using System.Collections.Generic;
5+
using System.Text.Json.Serialization;
6+
7+
namespace APIViewWeb.LeanModels
8+
{
9+
10+
public class CodePanelRawData
11+
{
12+
public IEnumerable<CommentItemModel> Comments { get; set; } = new List<CommentItemModel>();
13+
public List<APITreeNode> APIForest { get; set; } = new List<APITreeNode>();
14+
public CodeDiagnostic[] Diagnostics { get; set; } = new CodeDiagnostic[0];
15+
public string Language { get; set; }
16+
public bool ApplySkipDiff { get; set; }
17+
public bool SkipDocsWhenDiffing { get; set; }
18+
}
19+
20+
public class CodePanelRowData
21+
{
22+
public CodePanelRowDatatype Type { get; set; }
23+
public int? LineNumber { get; set; }
24+
[JsonIgnore]
25+
public List<StructuredToken> RowOfTokensObj { get; set; } = new List<StructuredToken>();
26+
public List<StructuredToken> RowOfTokens => RowOfTokensObj.Count > 0 ? RowOfTokensObj : null;
27+
public string NodeId { get; set; }
28+
public string NodeIdHashed { get; set; }
29+
public int RowPositionInGroup { get; set; } // The position / index of the row within the group of similar rows
30+
public int AssociatedRowPositionInGroup { get; set; } // For comment threads, this is the position of the associated code line within the group of similar rows
31+
public RowOfTokensPosition RowOfTokensPosition { get; set; }
32+
[JsonIgnore]
33+
public HashSet<string> RowClassesObj { get; set; } = new HashSet<string>();
34+
public HashSet<string> RowClasses => RowClassesObj.Count > 0 ? RowClassesObj : null;
35+
public int? Indent { get; set; }
36+
public DiffKind DiffKind { get; set; }
37+
public string ToggleDocumentationClasses { get; set; }
38+
public string ToggleCommentsClasses { get; set; }
39+
public CodeDiagnostic Diagnostics { get; set; }
40+
[JsonIgnore]
41+
public List<CommentItemModel> CommentsObj { get; set; } = new List<CommentItemModel>();
42+
public List<CommentItemModel> Comments => CommentsObj.Count > 0 ? CommentsObj : null;
43+
public bool IsResolvedCommentThread { get; set; }
44+
public bool IsHiddenAPI { get; set; }
45+
46+
}
47+
48+
public class CodePanelNodeMetaData
49+
{
50+
[JsonIgnore]
51+
public List<CodePanelRowData> DocumentationObj { get; set; } = new List<CodePanelRowData>();
52+
public List<CodePanelRowData> Documentation => DocumentationObj.Count > 0 ? DocumentationObj : null;
53+
[JsonIgnore]
54+
public List<CodePanelRowData> DiagnosticsObj { get; set; } = new List<CodePanelRowData>();
55+
public List<CodePanelRowData> Diagnostics => DiagnosticsObj.Count > 0 ? DiagnosticsObj : null;
56+
[JsonIgnore]
57+
public List<CodePanelRowData> CodeLinesObj { get; set; } = new List<CodePanelRowData>();
58+
public List<CodePanelRowData> CodeLines => CodeLinesObj.Count > 0 ? CodeLinesObj : null;
59+
[JsonIgnore]
60+
public ConcurrentDictionary<int, CodePanelRowData> CommentThreadObj { get; set; } = new ConcurrentDictionary<int, CodePanelRowData>(); //Dictionary key map to the index of the code line within this node which the comment thread is mapped to
61+
public ConcurrentDictionary<int, CodePanelRowData> CommentThread => CommentThreadObj.Count > 0 ? CommentThreadObj : null;
62+
public NavigationTreeNode NavigationTreeNode { get; set; }
63+
public string ParentNodeIdHashed { get; set; }
64+
[JsonIgnore]
65+
public ConcurrentDictionary<int, string> ChildrenNodeIdsInOrderObj { get; set; } = new ConcurrentDictionary<int, string>();
66+
public ConcurrentDictionary<int, string> ChildrenNodeIdsInOrder => ChildrenNodeIdsInOrderObj.Count > 0 ? ChildrenNodeIdsInOrderObj : null;
67+
public bool IsNodeWithDiff { get; set; }
68+
public bool IsNodeWithDiffInDescendants { get; set; }
69+
public bool IsNodeWithNoneDocDiffInDescendants { get; set; }
70+
public string BottomTokenNodeIdHash { get; set; }
71+
}
72+
73+
public class CodePanelData
74+
{
75+
[JsonIgnore]
76+
public ConcurrentDictionary<string, CodePanelNodeMetaData> NodeMetaDataObj { get; set; } = new ConcurrentDictionary<string, CodePanelNodeMetaData>();
77+
public ConcurrentDictionary<string, CodePanelNodeMetaData> NodeMetaData => NodeMetaDataObj.Count > 0 ? NodeMetaDataObj : null;
78+
public bool HasDiff { get; set; } = false;
79+
}
80+
}

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

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Concurrent;
21
using System.Collections.Generic;
32
using System.Text.Json.Serialization;
43
using APIView;
@@ -61,76 +60,6 @@ public class ReviewBadgeModel
6160
public bool? ShowDiffOnly { get; set; }
6261
}
6362

64-
public class CodePanelRawData
65-
{
66-
public IEnumerable<CommentItemModel> Comments { get; set; } = new List<CommentItemModel>();
67-
public List<APITreeNode> APIForest { get; set; } = new List<APITreeNode>();
68-
public CodeDiagnostic[] Diagnostics { get; set; } = new CodeDiagnostic[0];
69-
public string Language { get; set; }
70-
public bool ApplySkipDiff { get; set; }
71-
public bool SkipDocsWhenDiffing { get; set; }
72-
}
73-
74-
public class CodePanelRowData
75-
{
76-
public CodePanelRowDatatype Type { get; set; }
77-
public int? LineNumber { get; set; }
78-
[JsonIgnore]
79-
public List<StructuredToken> RowOfTokensObj { get; set; } = new List<StructuredToken>();
80-
public List<StructuredToken> RowOfTokens => RowOfTokensObj.Count > 0 ? RowOfTokensObj : null;
81-
public string NodeId { get; set; }
82-
public string NodeIdHashed { get; set; }
83-
public int RowPositionInGroup { get; set; } // The position / index of the row within the group of similar rows
84-
public int AssociatedRowPositionInGroup { get; set; } // For comment threads, this is the position of the associated code line within the group of similar rows
85-
public RowOfTokensPosition RowOfTokensPosition { get; set; }
86-
[JsonIgnore]
87-
public HashSet<string> RowClassesObj { get; set; } = new HashSet<string>();
88-
public HashSet<string> RowClasses => RowClassesObj.Count > 0 ? RowClassesObj : null;
89-
public int? Indent { get; set; }
90-
public DiffKind DiffKind { get; set; }
91-
public string ToggleDocumentationClasses { get; set; }
92-
public string ToggleCommentsClasses { get; set; }
93-
public CodeDiagnostic Diagnostics { get; set; }
94-
[JsonIgnore]
95-
public List<CommentItemModel> CommentsObj { get; set; } = new List<CommentItemModel>();
96-
public List<CommentItemModel> Comments => CommentsObj.Count > 0 ? CommentsObj : null;
97-
public bool IsResolvedCommentThread { get; set; }
98-
public bool IsHiddenAPI { get; set; }
99-
100-
}
101-
102-
public class CodePanelNodeMetaData
103-
{
104-
[JsonIgnore]
105-
public List<CodePanelRowData> DocumentationObj { get; set; } = new List<CodePanelRowData>();
106-
public List<CodePanelRowData> Documentation => DocumentationObj.Count > 0 ? DocumentationObj : null;
107-
[JsonIgnore]
108-
public List<CodePanelRowData> DiagnosticsObj { get; set; } = new List<CodePanelRowData>();
109-
public List<CodePanelRowData> Diagnostics => DiagnosticsObj.Count > 0 ? DiagnosticsObj : null;
110-
[JsonIgnore]
111-
public List<CodePanelRowData> CodeLinesObj { get; set; } = new List<CodePanelRowData>();
112-
public List<CodePanelRowData> CodeLines => CodeLinesObj.Count > 0 ? CodeLinesObj : null;
113-
[JsonIgnore]
114-
public ConcurrentDictionary<int, CodePanelRowData> CommentThreadObj { get; set; } = new ConcurrentDictionary<int, CodePanelRowData>(); //Dictionary key map to the index of the code line within this node which the comment thread is mapped to
115-
public ConcurrentDictionary<int, CodePanelRowData> CommentThread => CommentThreadObj.Count > 0 ? CommentThreadObj : null;
116-
public NavigationTreeNode NavigationTreeNode { get; set; }
117-
public string ParentNodeIdHashed { get; set; }
118-
[JsonIgnore]
119-
public ConcurrentDictionary<int, string> ChildrenNodeIdsInOrderObj { get; set; } = new ConcurrentDictionary<int, string>();
120-
public ConcurrentDictionary<int, string> ChildrenNodeIdsInOrder => ChildrenNodeIdsInOrderObj.Count > 0 ? ChildrenNodeIdsInOrderObj : null;
121-
public bool IsNodeWithDiff { get; set; }
122-
public bool IsNodeWithDiffInDescendants { get; set; }
123-
public string BottomTokenNodeIdHash { get; set; }
124-
}
125-
126-
public class CodePanelData
127-
{
128-
[JsonIgnore]
129-
public ConcurrentDictionary<string, CodePanelNodeMetaData> NodeMetaDataObj { get; set; } = new ConcurrentDictionary<string, CodePanelNodeMetaData>();
130-
public ConcurrentDictionary<string, CodePanelNodeMetaData> NodeMetaData => NodeMetaDataObj.Count > 0 ? NodeMetaDataObj : null;
131-
public bool HasDiff { get; set; } = false;
132-
}
133-
13463
public class NavigationTreeNodeData
13564
{
13665
public string Kind { get; set; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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" />
56
<div *ngIf="codePanelRowSource;" class="viewport {{languageSafeName!}}" (click)="onCodePanelItemClick($event)">
67
<div *uiScroll="let item of codePanelRowSource; let index = index" class="code-line" [attr.data-node-id]="item.nodeIdHashed"
78
[attr.data-row-position-in-group]="item.rowPositionInGroup" [ngClass]="getRowClassObject(item)">

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
22
import { take } from 'rxjs/operators';
3-
import { CodePanelData } from 'src/app/_models/revision';
43
import { Datasource, IDatasource, SizeStrategy } from 'ngx-ui-scroll';
54
import { CommentsService } from 'src/app/_services/comments/comments.service';
65
import { getQueryParams } from 'src/app/_helpers/router-helpers';
76
import { ActivatedRoute, Router } from '@angular/router';
87
import { SCROLL_TO_NODE_QUERY_PARAM } from 'src/app/_helpers/common-helpers';
9-
import { CodePanelRowData, CodePanelRowDatatype } from 'src/app/_models/codePanelRowData';
8+
import { CodePanelData, CodePanelRowData, CodePanelRowDatatype } from 'src/app/_models/codePanelModels';
109
import { StructuredToken } from 'src/app/_models/structuredToken';
1110
import { CommentItemModel, CommentType } from 'src/app/_models/commentItemModel';
1211
import { UserProfile } from 'src/app/_models/userProfile';
12+
import { Message } from 'primeng/api/message';
1313

1414
@Component({
1515
selector: 'app-code-panel',
@@ -32,6 +32,7 @@ export class CodePanelComponent implements OnChanges{
3232

3333
@Output() hasActiveConversation : EventEmitter<boolean> = new EventEmitter<boolean>();
3434

35+
noDiffInContentMessage : Message[] = [{ severity: 'info', icon:'bi bi-info-circle', detail: 'There is no difference between the two API revisions.' }];
3536
isLoading: boolean = true;
3637
codeWindowHeight: string | undefined = undefined;
3738
codePanelRowDataIndicesMap = new Map<string, number>();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
(onChange)="onDiffStyleChange($event)"
9090
[options]="diffStyleOptions"
9191
[(ngModel)]="selectedDiffStyle"
92+
[disabled]="!contentHasDiff"
9293
inputId="diff-style-select"
9394
optionLabel="label"
9495
[style]="{'width':'100%'}"/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { UserProfile } from 'src/app/_models/userProfile';
1818
export class ReviewPageOptionsComponent implements OnInit, OnChanges{
1919
@Input() userProfile: UserProfile | undefined;
2020
@Input() isDiffView: boolean = false;
21+
@Input() contentHasDiff: boolean | undefined = false;
2122
@Input() diffStyleInput: string | undefined;
2223
@Input() review : Review | undefined = undefined;
2324
@Input() activeAPIRevision : APIRevision | undefined = undefined;

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
@@ -41,6 +41,7 @@
4141
<div *ngIf="showPageOptions" class="col flex align-items-center justify-content-center border rounded-end overflow-auto review-panel px-3">
4242
<app-review-page-options
4343
[isDiffView]="!!diffApiRevisionId"
44+
[contentHasDiff]="codePanelData?.hasDiff"
4445
[diffStyleInput]="diffStyle!"
4546
[userProfile]="userProfile"
4647
[review]="review"

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import { Subject, take, takeUntil } from 'rxjs';
55
import { getLanguageCssSafeName } from 'src/app/_helpers/common-helpers';
66
import { getQueryParams } from 'src/app/_helpers/router-helpers';
77
import { Review } from 'src/app/_models/review';
8-
import { APIRevision, ApiTreeBuilderData, CodePanelData, ReviewPageWorkerMessageDirective } from 'src/app/_models/revision';
8+
import { APIRevision, ApiTreeBuilderData } from 'src/app/_models/revision';
99
import { ReviewsService } from 'src/app/_services/reviews/reviews.service';
1010
import { RevisionsService } from 'src/app/_services/revisions/revisions.service';
1111
import { UserProfileService } from 'src/app/_services/user-profile/user-profile.service';
1212
import { WorkerService } from 'src/app/_services/worker/worker.service';
1313
import { CodePanelComponent } from '../code-panel/code-panel.component';
1414
import { CommentsService } from 'src/app/_services/comments/comments.service';
1515
import { ACTIVE_API_REVISION_ID_QUERY_PARAM, DIFF_API_REVISION_ID_QUERY_PARAM, DIFF_STYLE_QUERY_PARAM, REVIEW_ID_ROUTE_PARAM, SCROLL_TO_NODE_QUERY_PARAM } from 'src/app/_helpers/common-helpers';
16-
import { CodePanelRowData, CodePanelRowDatatype } from 'src/app/_models/codePanelRowData';
16+
import { CodePanelData, CodePanelRowData, CodePanelRowDatatype } from 'src/app/_models/codePanelModels';
1717
import { UserProfile } from 'src/app/_models/userProfile';
18+
import { ReviewPageWorkerMessageDirective } from 'src/app/_models/insertCodePanelRowDataMessage';
1819

1920
@Component({
2021
selector: 'app-review-page',

src/dotnet/APIView/ClientSPA/src/app/_components/shared/comment-thread/comment-thread.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { CommentThreadComponent } from './comment-thread.component';
44
import { HttpClientTestingModule } from '@angular/common/http/testing';
55
import { SharedAppModule } from 'src/app/_modules/shared/shared-app.module';
6-
import { CodePanelRowData } from 'src/app/_models/codePanelRowData';
6+
import { CodePanelRowData } from 'src/app/_models/codePanelModels';
77
import { ReviewPageModule } from 'src/app/_modules/review-page/review-page.module';
88

99
describe('CommentThreadComponent', () => {

0 commit comments

Comments
 (0)