Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix/re enable revision DropDown #8181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/dotnet/APIView/APIViewWeb/Client/css/pages/review.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
@import "../shared/mixins.scss";

#review-info-bar {
font-size: small;
background-color: var(--base-fg-color);
#review-info-bar > .SumoSelect:nth-of-type(even) {
width: 20%;
}

#review-info-bar > .SumoSelect:nth-of-type(odd) {
width: 10%;
}

#revision-select ~ .optWrapper {
width: auto;
min-width: 250px;
}

#diff-select ~ .optWrapper {
width: auto;
min-width: 250px;
}

#revision-select {
width: 20%;
}

#diff-select {
width: 20%;
}

.breadcrumb .icon-language {
Expand All @@ -13,7 +34,7 @@
#review-left {
max-width: none;
min-width: 10px;
height: calc(100vh - 120px);
height: calc(100vh - 135px);
overflow: auto;
max-height: 100vh;
padding: 5px 0px 5px 10px;
Expand All @@ -27,7 +48,7 @@
#review-right {
max-width: 100%;
min-width: 100px;
height: calc(100vh - 120px);
height: calc(100vh - 135px);
padding: 0px;
overflow: auto;
background-color: var(--base-fg-color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
width: 31px;
display: inline-block;
vertical-align: middle;
padding-inline: 5px;
}

.java-variant {
Expand Down Expand Up @@ -165,67 +166,67 @@

.icon-csharp {
@extend .icon-language;
background: url(/icons/csharp-original.svg) center/contain no-repeat;
background: url(/icons/csharp-original.svg) center no-repeat;
}

.icon-javascript {
@extend .icon-language;
background: url(/icons/javascript-original.svg) center/contain no-repeat;
background: url(/icons/javascript-original.svg) center no-repeat;
}

.icon-python {
@extend .icon-language;
background: url(/icons/python-original.svg) center/contain no-repeat;
background: url(/icons/python-original.svg) center no-repeat;
}

.icon-c {
@extend .icon-language;
background: url(/icons/c-original.svg) center/contain no-repeat;
background: url(/icons/c-original.svg) center no-repeat;
}

.icon-cplusplus {
@extend .icon-language;
background: url(/icons/cplusplus-original.svg) center/contain no-repeat;
background: url(/icons/cplusplus-original.svg) center no-repeat;
}

.icon-go {
@extend .icon-language;
background: url(/icons/go-original.svg) center/contain no-repeat;
background: url(/icons/go-original.svg) center no-repeat;
}

.icon-java {
@extend .icon-language;
background: url(/icons/java-original.svg) center/contain no-repeat;
background: url(/icons/java-original.svg) center no-repeat;
}

.icon-java-spring {
@extend .icon-language;
background: url(/icons/java-spring-original.svg) center/contain no-repeat;
background: url(/icons/java-spring-original.svg) center no-repeat;
}

.icon-java-android {
@extend .icon-language;
background: url(/icons/java-android-original.svg) center/contain no-repeat;
background: url(/icons/java-android-original.svg) center no-repeat;
}

.icon-swift {
@extend .icon-language;
background: url(/icons/swift-original.svg) center/contain no-repeat;
background: url(/icons/swift-original.svg) center no-repeat;
}

.icon-kotlin {
@extend .icon-language;
background: url(/icons/kotlin-original.svg) center/contain no-repeat;
background: url(/icons/kotlin-original.svg) center no-repeat;
}

.icon-json {
@extend .icon-language;
background: url(/icons/json-original.svg) center/contain no-repeat;
background: url(/icons/json-original.svg) center no-repeat;
}

.icon-swagger {
@extend .icon-language;
background: url(/icons/swagger-original.svg) center/contain no-repeat;
background: url(/icons/swagger-original.svg) center no-repeat;
}

.icon-typespec {
Expand All @@ -241,9 +242,9 @@
}

.icon-chevron-right {
background: url(/icons/chevron-right.svg) center/contain no-repeat;
background: url(/icons/chevron-right.svg) center no-repeat;
}

.icon-chevron-up {
background: url(/icons/chevron-up.svg) center/contain no-repeat;
background: url(/icons/chevron-up.svg) center no-repeat;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
min-height: calc(100vh - 100px);
max-height: calc(100vh - 100px);
overflow-y: auto;
margin-top: 70px;
margin-top: 85px;
}

@mixin review-approval-border {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@
}
}

#review-right-offcanvas-toggle, #samples-right-offcanvas-toggle, #revisions-right-offcanvas-toggle {
+ .btn-sm {
padding: 0.05rem 0.4rem;
font-size: 0.775rem;
border-radius: 0.2rem;
}
}

#apiRevisions-context, #samplesRevisions-context {
@include offcanvas-context-large
}
Expand Down
14 changes: 14 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Client/src/pages/review.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,20 @@ export function addClickEventToClassesInSections() {
});
}

/**
* Add Select Event Handlers to API Revision Select
*/
export function addSelectEventToAPIRevisionSelect() {
$('#revision-select, #diff-select').each(function (index, value) {
$(this).on('change', function () {
var url = $(this).find(":selected").val();
if (url) {
window.location.href = url as string;
}
});
});
}

/**
* Check if targetAnchor is present, if its not present, expand the section and scroll to the targetAnchor
* @param { String } uriHash the hash/id of the anchor we are looking for
Expand Down
45 changes: 44 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ $(() => {
rvM.hideCheckboxesIfNotApplicable();

// Run when document is ready
$(function() {
$(function () {
// Enable SumoSelect
(<any>$("#revision-select")).SumoSelect({ search: true, searchText: 'Search Revisions...' });
(<any>$("#diff-select")).SumoSelect({ search: true, searchText: 'Search Revisons for Diff...' });
(<any>$("#revision-type-select")).SumoSelect();
(<any>$("#diff-revision-type-select")).SumoSelect();

// Update codeLine Section state after page refresh
const shownSectionHeadingLineNumbers = sessionStorage.getItem("shownSectionHeadingLineNumbers");

Expand Down Expand Up @@ -141,6 +147,43 @@ $(() => {
$(this).get(0).scrollIntoView({ block: "center"});
});

/* DROPDOWN FILTER FOR REVIEW, REVISIONS AND DIFF (UPDATES REVIEW PAGE ON CHANGE)
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
rvM.addSelectEventToAPIRevisionSelect();

$('#revision-type-select, #diff-revision-type-select').each(function (index, value) {
$(this).on('change', function () {
const pageIds = hp.getReviewAndRevisionIdFromUrl(window.location.href);
const reviewId = pageIds["reviewId"];
const apiRevisionId = pageIds["revisionId"];

const select = (index == 0) ? $('#revision-select') : $('#diff-select');
const text = (index == 0) ? 'Revisions' : 'Revisions for Diff';

let uri = (index == 0) ? '?handler=APIRevisionsPartial' : '?handler=APIDiffRevisionsPartial';
uri = uri + `&reviewId=${reviewId}`;
uri = uri + `&apiRevisionId=${apiRevisionId}`;
uri = uri + '&apiRevisionType=' + $(this).find(":selected").val();

$.ajax({
url: uri
}).done(function (partialViewResult) {
const id = select.attr('id');
const selectUpdate = $(`<select placeholder="Select ${text}..." id="${id}" aria-label="${text} Select"></select>`);
selectUpdate.html(partialViewResult);
select.parent().replaceWith(selectUpdate);
(<any>$(`#${id}`)).SumoSelect({ placeholder: `Select ${text}...`, search: true, searchText: `Search ${text}...` })

// Disable Diff Revision Select until a revision is selected
if (index == 0) {
(<any>$('#diff-revision-type-select')[0]).sumo.disable();
(<any>$('#diff-select')[0]).sumo.disable();
}
rvM.addSelectEventToAPIRevisionSelect();
});
});
});


/* BUTTON FOR REQUEST REVIEW (CHANGES BETWEEN REQUEST ALL AND REQUEST SELECTED IN THE REQUEST APPROVAL SECTION)
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ public class ReviewContentModel
public ReviewContentModelDirective Directive { get; set; }
public Dictionary<string, ReviewContentModel> CrossLanguageViewContent { get; set; } = new Dictionary<string, ReviewContentModel>();
}

public class ReviewBadgeModel
{
public ReviewListItemModel Review { get; set; }
public IEnumerable<APIRevisionListItemModel> APIRevisions { get; set; }
public APIRevisionListItemModel ActiveAPIRevision { get; set; }
public APIRevisionListItemModel DiffAPIRevision { get; set; }
public UserPreferenceModel UserPreference { get; set; }
public bool? ShowDocumentation { get; set; }
public bool? ShowDiffOnly { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
}
<div class="container-fluid mx-0 px-0 sub-header-content">
<div class="row px-3 py-2 border-bottom" id="review-info-bar">
<partial name="Shared/_ReviewBadge" model="(Model.Review, default(APIRevisionListItemModel), default(APIRevisionListItemModel), default(UserPreferenceModel))" />
@{
var reviewBadgeModel = new ReviewBadgeModel();
reviewBadgeModel.Review = Model.Review;
}
<partial name="Shared/_ReviewBadge" model="reviewBadgeModel" />
</div>
</div>
@{
Expand Down
14 changes: 12 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,18 @@
</div>
</div>
<div class="container-fluid mx-0 px-0 sub-header-content">
<div class="row px-3 py-2 border-bottom" id="review-info-bar">
<partial name="Shared/_ReviewBadge" model="(Model.ReviewContent.Review, Model.ReviewContent.ActiveAPIRevision, Model.ReviewContent.DiffAPIRevision, Model.UserPreference)" />
<div class="row px-3 py-2 border-bottom">
@{
var reviewBadgeModel = new ReviewBadgeModel();
reviewBadgeModel.Review = Model.ReviewContent.Review;
reviewBadgeModel.APIRevisions = Model.ReviewContent.APIRevisions;
reviewBadgeModel.ActiveAPIRevision = Model.ReviewContent.ActiveAPIRevision;
reviewBadgeModel.DiffAPIRevision = Model.ReviewContent.DiffAPIRevision;
reviewBadgeModel.UserPreference = Model.UserPreference;
reviewBadgeModel.ShowDocumentation = Model.ShowDocumentation;
reviewBadgeModel.ShowDiffOnly = Model.ShowDiffOnly;
}
<partial name="Shared/_ReviewBadge" model="reviewBadgeModel" />
</div>
</div>

Expand Down
65 changes: 65 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,71 @@ public async Task<PartialViewResult> OnGetCodeLineSectionAsync(
return Partial("_CodeLinePartial", sectionKey);
}

/// <summary>
/// Get Revisions Partial
/// </summary>
/// <param name="reviewId"></param>
/// <param name="apiRevisionType"></param>
/// <param name="showDoc"></param>
/// <param name="showDiffOnly"></param>
/// <returns></returns>
public async Task<PartialViewResult> OnGetAPIRevisionsPartialAsync(string reviewId, APIRevisionType apiRevisionType, bool showDoc = false, bool showDiffOnly = false)
{
var revisions = await _apiRevisionsManager.GetAPIRevisionsAsync(reviewId);
revisions = revisions.Where(r => r.APIRevisionType == apiRevisionType).OrderByDescending(c => c.CreatedOn).ToList();
(IEnumerable<APIRevisionListItemModel> revisions, APIRevisionListItemModel activeRevision, APIRevisionListItemModel diffRevision, bool forDiff, bool showDocumentation, bool showDiffOnly) revisionSelectModel = (
revisions: revisions,
activeRevision: default(APIRevisionListItemModel),
diffRevision: default(APIRevisionListItemModel),
forDiff: false,
showDocumentation: showDoc,
showDiffOnly: showDiffOnly
);
return Partial("_RevisionSelectPickerPartial", revisionSelectModel);
}

/// <summary>
/// Get Diff Revisions Partial
/// </summary>
/// <param name="reviewId"></param>
/// <param name="apiRevisionId"></param>
/// <param name="apiRevisionType"></param>
/// <param name="showDoc"></param>
/// <param name="showDiffOnly"></param>
/// <returns></returns>
public async Task<PartialViewResult> OnGetAPIDiffRevisionsPartialAsync(string reviewId, string apiRevisionId, APIRevisionType apiRevisionType, bool showDoc = false, bool showDiffOnly = false)
{
var apiRevisions = await _apiRevisionsManager.GetAPIRevisionsAsync(reviewId);
if (apiRevisions.IsNullOrEmpty())
{
var notifcation = new NotificationModel() { Message = $"This review has no valid apiRevisons", Level = NotificatonLevel.Warning };
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
}

APIRevisionListItemModel activeRevision = default(APIRevisionListItemModel);

if (!Guid.TryParse(apiRevisionId, out _))
{
activeRevision = await _apiRevisionsManager.GetLatestAPIRevisionsAsync(reviewId, apiRevisions);
}
else
{
activeRevision = apiRevisions.FirstOrDefault(r => r.Id == apiRevisionId);
}

var revisionsForDiff = apiRevisions.Where(r => r.APIRevisionType == apiRevisionType && r.Id != activeRevision.Id).OrderByDescending(c => c.CreatedOn).ToList();

(IEnumerable<APIRevisionListItemModel> revisions, APIRevisionListItemModel activeRevision, APIRevisionListItemModel diffRevision, bool forDiff, bool showDocumentation, bool showDiffOnly) revisionSelectModel = (
revisions: revisionsForDiff,
activeRevision: activeRevision,
diffRevision: default(APIRevisionListItemModel),
forDiff: true,
showDocumentation: showDoc,
showDiffOnly: showDiffOnly
);
return Partial("_RevisionSelectPickerPartial", revisionSelectModel);
}

/// <summary>
/// Toggle Review State
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
}
<div class="container-fluid mx-0 px-0 sub-header-content">
<div class="row px-3 py-2 border-bottom" id="review-info-bar">
<partial name="Shared/_ReviewBadge" model="(Model.Review, default(APIRevisionListItemModel), default(APIRevisionListItemModel), default(UserPreferenceModel))" />
@{
var reviewBadgeModel = new ReviewBadgeModel();
reviewBadgeModel.Review = Model.Review;
}
<partial name="Shared/_ReviewBadge" model="reviewBadgeModel" />
</div>
</div>

Expand Down
Loading