Skip to content

Commit b444030

Browse files
Add Button for Disabling CodeLines Lazy Loading (#8803)
* Add Button for Disabling CodeLines LazyLoadin * Add test for page options defaults
1 parent 062cdcf commit b444030

8 files changed

Lines changed: 87 additions & 34 deletions

File tree

src/dotnet/APIView/APIViewWeb/Models/UserPreferenceModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class UserPreferenceModel
2323
internal bool? _hideRevisionsPageOptions;
2424
internal bool? _showComments;
2525
internal bool? _showSystemComments;
26+
internal bool? _disableCodeLinesLazyLoading;
2627
internal bool? _useBetaIndexPage;
2728
internal string _theme;
2829

@@ -132,6 +133,13 @@ public bool? ShowSystemComments
132133
set => _showSystemComments = value;
133134
}
134135

136+
[Name("DisableCodeLinesLazyLoading")]
137+
public bool? DisableCodeLinesLazyLoading
138+
{
139+
get => _disableCodeLinesLazyLoading ?? false;
140+
set => _disableCodeLinesLazyLoading = value;
141+
}
142+
135143
[Name("UseBetaIndexPage")]
136144
public bool? UseBetaIndexPage
137145
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class CodePanelComponent implements OnChanges{
368368
success(data);
369369
},
370370
settings: {
371-
bufferSize: 50,
371+
bufferSize: (this.userProfile?.preferences.disableCodeLinesLazyLoading) ? this.codePanelRowData.length : 50,
372372
padding: 1,
373373
itemSize: 21,
374374
startIndex : 0,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
(onChange)="onShowLeftNavigationSwitchChange($event)" />
8484
<label class="ms-2">Left Navigation</label>
8585
</li>
86+
<li class="list-group-item">
87+
<p-inputSwitch [(ngModel)]="disableCodeLinesLazyLoading"
88+
(onChange)="onDisableLazyLoadingSwitchChange($event)" />
89+
<label class="ms-2">Disable Lazy Loading</label>
90+
</li>
8691
<li *ngIf="isDiffView" class="list-group-item">
8792
<label class="small mx-1 fw-semibold" for="diff-style-select">Diff Style :</label>
8893
<p-dropdown
@@ -180,4 +185,14 @@
180185
(click)="toggleAPIRevisionApproval()"
181186
[disabled]="(hasActiveConversation && !overrideActiveConversationforApproval) || (hasFatalDiagnostics && !overrideFatalDiagnosticsforApproval)">Confirm</button>
182187
</div>
188+
</p-dialog>
189+
190+
<p-dialog header="Disable Lazy Loading"
191+
[modal]="true" [(visible)]="showDisableCodeLinesLazyLoadingModal"
192+
[style]="{ width: '30dvw' }" (onHide)="disableCodeLinesLazyLoading = userProfile?.preferences?.disableCodeLinesLazyLoading!">
193+
<p>Disabling lazy loading will load all code lines at once. This may lead to degraded performance.</p>
194+
<div class="d-grid gap-2 mt-2">
195+
<button class="btn btn-primary" type="button" (click)="disableCodeLinesLazyLoadingEmitter.emit(disableCodeLinesLazyLoading); showDisableCodeLinesLazyLoadingModal = false">Disable</button>
196+
<button class="btn btn-link" type="button" (click)="showDisableCodeLinesLazyLoadingModal = false;">Cancel</button>
197+
</div>
183198
</p-dialog>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,20 @@ describe('ReviewPageOptionsComponent', () => {
8686
expect(message.textContent).toEqual("First Release Approval Pending");
8787
});
8888
});
89+
90+
describe('Page Option Values', () => {
91+
it('Should set Page Option Defaults when UserProfile is undefined', () => {
92+
component.userProfile = undefined;
93+
component.ngOnInit();
94+
expect(component.userProfile).toBeUndefined();
95+
expect(component.showCommentsSwitch).toEqual(true);
96+
expect(component.showSystemCommentsSwitch).toEqual(true);
97+
expect(component.showDocumentationSwitch).toEqual(true);
98+
expect(component.showHiddenAPISwitch).toEqual(false);
99+
expect(component.showLeftNavigationSwitch).toEqual(true);
100+
expect(component.markedAsViewSwitch).toEqual(false);
101+
expect(component.showLineNumbersSwitch).toEqual(true);
102+
expect(component.disableCodeLinesLazyLoading).toEqual(false);
103+
})
104+
});
89105
});

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
3434
@Output() showDocumentationEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
3535
@Output() showHiddenAPIEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
3636
@Output() showLeftNavigationEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
37+
@Output() disableCodeLinesLazyLoadingEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
3738
@Output() markAsViewedEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
3839
@Output() showLineNumbersEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
3940
@Output() apiRevisionApprovalEmitter : EventEmitter<boolean> = new EventEmitter<boolean>();
@@ -48,13 +49,15 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
4849
showLeftNavigationSwitch : boolean = true;
4950
markedAsViewSwitch : boolean = false;
5051
showLineNumbersSwitch : boolean = true;
52+
disableCodeLinesLazyLoading: boolean = false;
5153

5254
canToggleApproveAPIRevision: boolean = false;
5355
activeAPIRevisionIsApprovedByCurrentUser: boolean = false;
5456
apiRevisionApprovalMessage: string = '';
5557
apiRevisionApprovalBtnClass: string = '';
5658
apiRevisionApprovalBtnLabel: string = '';
5759
showAPIRevisionApprovalModal: boolean = false;
60+
showDisableCodeLinesLazyLoadingModal: boolean = false;
5861
overrideActiveConversationforApproval : boolean = false;
5962
overrideFatalDiagnosticsforApproval : boolean = false;
6063

@@ -88,21 +91,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
8891

8992
ngOnInit() {
9093
this.setSelectedDiffStyle();
91-
this.showCommentsSwitch = this.userProfile?.preferences.showComments ?? true;
92-
this.showSystemCommentsSwitch = this.userProfile?.preferences.showSystemComments ?? true;
93-
this.showDocumentationSwitch = this.userProfile?.preferences.showDocumentation ?? false;
94-
this.showHiddenAPISwitch = this.userProfile?.preferences.showHiddenApis ?? false;
95-
96-
if (this.userProfile?.preferences.hideLeftNavigation != undefined) {
97-
this.showLeftNavigationSwitch = !(this.userProfile?.preferences.hideLeftNavigation);
98-
} else {
99-
this.showLeftNavigationSwitch = false;
100-
}
101-
if (this.userProfile?.preferences.hideLineNumbers){
102-
this.showLineNumbersSwitch = false;
103-
} else {
104-
this.showLineNumbersSwitch = true;
105-
}
94+
this.setPageOptionValues();
10695

10796
this.activeAPIRevision?.assignedReviewers.map(revision => this.selectedApprovers.push(revision.assingedTo));
10897
this.setAPIRevisionApprovalStates();
@@ -115,21 +104,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
115104
}
116105

117106
if (changes['userProfile']) {
118-
this.showCommentsSwitch = this.userProfile?.preferences.showComments ?? this.showCommentsSwitch;
119-
this.showSystemCommentsSwitch = this.userProfile?.preferences.showSystemComments ?? this.showSystemCommentsSwitch;
120-
this.showDocumentationSwitch = this.userProfile?.preferences.showDocumentation ?? this.showDocumentationSwitch;
121-
this.showHiddenAPISwitch = this.userProfile?.preferences.showHiddenApis ?? false;
122-
123-
if (this.userProfile?.preferences.hideLeftNavigation != undefined) {
124-
this.showLeftNavigationSwitch = !(this.userProfile?.preferences.hideLeftNavigation);
125-
} else {
126-
this.showLeftNavigationSwitch = false;
127-
}
128-
if (this.userProfile?.preferences.hideLineNumbers){
129-
this.showLineNumbersSwitch = false;
130-
} else {
131-
this.showLineNumbersSwitch = true;
132-
}
107+
this.setPageOptionValues();
133108
}
134109

135110
if (changes['activeAPIRevision'] && changes['activeAPIRevision'].currentValue != undefined) {
@@ -191,6 +166,19 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
191166
this.showLeftNavigationEmitter.emit(event.checked);
192167
}
193168

169+
/**
170+
* Disable Lazy Loading
171+
* @param event the Filter event
172+
*/
173+
onDisableLazyLoadingSwitchChange(event: InputSwitchOnChangeEvent) {
174+
if (event.checked) {
175+
this.showDisableCodeLinesLazyLoadingModal = true;
176+
} else {
177+
this.disableCodeLinesLazyLoadingEmitter.emit(event.checked);
178+
}
179+
}
180+
181+
194182
/**
195183
* Callback for markedAsViewSwitch Change
196184
* @param event the Filter event
@@ -241,6 +229,16 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
241229
this.selectedDiffStyle = (inputDiffStyle) ? inputDiffStyle : this.diffStyleOptions[0];
242230
}
243231

232+
setPageOptionValues() {
233+
this.showCommentsSwitch = this.userProfile?.preferences.showComments ?? this.showCommentsSwitch;
234+
this.showSystemCommentsSwitch = this.userProfile?.preferences.showSystemComments ?? this.showSystemCommentsSwitch;
235+
this.showDocumentationSwitch = this.userProfile?.preferences.showDocumentation ?? this.showDocumentationSwitch;
236+
this.showHiddenAPISwitch = this.userProfile?.preferences.showHiddenApis ?? this.showHiddenAPISwitch;
237+
this.disableCodeLinesLazyLoading = this.userProfile?.preferences.disableCodeLinesLazyLoading ?? this.disableCodeLinesLazyLoading;
238+
this.showLineNumbersSwitch = (this.userProfile?.preferences.hideLineNumbers) ? false : this.showLineNumbersSwitch;
239+
this.showLeftNavigationSwitch = (this.userProfile?.preferences.hideLeftNavigation) ? false : this.showLeftNavigationSwitch;
240+
}
241+
244242
setAPIRevisionApprovalStates() {
245243
this.activeAPIRevisionIsApprovedByCurrentUser = this.activeAPIRevision?.approvers.includes(this.userProfile?.userName!)!;
246244
const isActiveAPIRevisionAhead = (!this.diffAPIRevision) ? true : ((new Date(this.activeAPIRevision?.createdOn!)) > (new Date(this.diffAPIRevision?.createdOn!)));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
(showLineNumbersEmitter)="handleShowLineNumbersEmitter($event)"
6161
(apiRevisionApprovalEmitter)="handleApiRevisionApprovalEmitter($event)"
6262
(reviewApprovalEmitter)="handleReviewApprovalEmitter($event)"
63-
(showHiddenAPIEmitter)="handleShowHiddenAPIEmitter($event)"></app-review-page-options>
63+
(showHiddenAPIEmitter)="handleShowHiddenAPIEmitter($event)"
64+
(disableCodeLinesLazyLoadingEmitter)="handleDisableCodeLinesLazyLoadingEmitter($event)"></app-review-page-options>
6465
</div>
6566
</ng-template>
6667
</p-splitter>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,17 @@ export class ReviewPageComponent implements OnInit {
398398
});
399399
}
400400

401+
handleDisableCodeLinesLazyLoadingEmitter(state: boolean) {
402+
let userPreferenceModel = this.userProfile?.preferences;
403+
userPreferenceModel!.disableCodeLinesLazyLoading = state;
404+
this.userProfileService.updateUserPrefernece(userPreferenceModel!).pipe(takeUntil(this.destroy$)).subscribe({
405+
next: () => {
406+
const currentParams = this.route.snapshot.queryParams;
407+
this.updateStateBasedOnQueryParams(currentParams);
408+
}
409+
});
410+
}
411+
401412
handleHasActiveConversationEmitter(value: boolean) {
402413
this.hasActiveConversation = value;
403414
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export class UserPreferenceModel {
1010
showComments: boolean
1111
showSystemComments: boolean
1212
useBetaIndexPage: boolean
13+
disableCodeLinesLazyLoading: boolean
14+
1315

1416
constructor() {
1517
this.userName = '';
@@ -20,8 +22,10 @@ export class UserPreferenceModel {
2022
this.hideLeftNavigation = false;
2123
this.showHiddenApis = false
2224
this.showDocumentation = false;
23-
this.showComments = false;
24-
this.showSystemComments = false;
25+
this.showComments = true;
26+
this.showSystemComments = true;
2527
this.useBetaIndexPage = false;
28+
this.disableCodeLinesLazyLoading = false;
29+
2630
}
2731
}

0 commit comments

Comments
 (0)