Skip to content

Commit

Permalink
Don't load languages list from server (#5579)
Browse files Browse the repository at this point in the history
* Don't load languages list from server

* Ensure tooltip is visible when approved button is disabled
  • Loading branch information
chidozieononiwu authored Mar 1, 2023
1 parent 632fd90 commit 8a7d0e5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 47 deletions.
24 changes: 1 addition & 23 deletions src/dotnet/APIView/APIViewWeb/Client/src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,9 @@ $(() => {
});
}

// Fetches data for populating dropdown options
function updateFilterDropDown(filter, query)
{
var uri = `?handler=reviews${query}`;
var urlParams = new URLSearchParams(location.search);
if (urlParams.has(query))
{
urlParams.getAll(query).forEach(function(value, index) {
uri = uri + `&selected${query}=` + encodeURIComponent(value);
});
}
$.ajax({
url: uri
}).done(function(partialViewResult) {
filter.html(partialViewResult);
(<any>filter).SumoSelect({
selectAll: true,
captionFormat: '{0} languages Selected'
});
});
}

// Fetch content of dropdown on page load
$(document).ready(function() {
updateFilterDropDown(languageFilter, "languages"); // Pulls languages data from DB
(<any>languageFilter).SumoSelect({ selectAll: true });
(<any>stateFilter).SumoSelect({ selectAll: true });
(<any>statusFilter).SumoSelect({ selectAll: true });
(<any>typeFilter).SumoSelect({ selectAll: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace APIViewWeb.Helpers
{
public class LanguageServiceHelpers
{
public static string[] SupportedLanguages = new string[] { "C", "C++", "C#", "Cadl", "Go", "Java", "JavaScript", "Json", "Kotlin", "Python", "Swagger", "Swift", "Xml" };
}
}
3 changes: 2 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Languages/LanguageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using APIViewWeb.Models;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights;
using APIViewWeb.Helpers;

namespace APIViewWeb
{
Expand All @@ -29,7 +30,7 @@ public abstract class LanguageService
Navigation = new NavigationItem[] { new NavigationItem() { Text = fileName } }
};

public static string[] SupportedLanguages = new string[] { "C", "C++", "C#", "Cadl", "Go", "Java", "JavaScript", "Json", "Kotlin", "Python", "Swagger", "Swift", "Xml" };
public static string[] SupportedLanguages = LanguageServiceHelpers.SupportedLanguages;

public virtual bool GeneratePipelineRunParams(ReviewGenPipelineParamModel param) => true;

Expand Down
31 changes: 14 additions & 17 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using APIViewWeb.Managers;
using Octokit;
using Microsoft.TeamFoundation.Common;
using APIViewWeb.Helpers;

namespace APIViewWeb.Pages.Assemblies
{
Expand Down Expand Up @@ -52,8 +53,12 @@ public async Task OnGetAsync(
state = userPreference.State;
status = userPreference.Status;
type = userPreference.FilterType.Select(x => x.ToString());
await RunGetRequest(search, languages, state, status, type, pageNo, pageSize, sortField, false);
}
else
{
await RunGetRequest(search, languages, state, status, type, pageNo, pageSize, sortField);
}
await RunGetRequest(search, languages, state, status, type, pageNo, pageSize, sortField);
}

public async Task<PartialViewResult> OnGetReviewsPartialAsync(
Expand All @@ -64,19 +69,6 @@ public async Task<PartialViewResult> OnGetReviewsPartialAsync(
return Partial("_ReviewsPartial", PagedResults);
}

public async Task<PartialViewResult> OnGetReviewsLanguagesAsync(IEnumerable<string> selectedLanguages)
{
if (!selectedLanguages.Any())
{
UserPreferenceModel userPreference = await _preferenceCache.GetUserPreferences(User);
selectedLanguages = userPreference.Language.ToList();
}
ReviewsProperties.Languages.All = await _manager.GetReviewPropertiesAsync("Revisions[0].Files[0].Language");
selectedLanguages = selectedLanguages.Select(x => HttpUtility.UrlDecode(x));
ReviewsProperties.Languages.Selected = selectedLanguages;
return Partial("_SelectPickerPartial", ReviewsProperties.Languages);
}

public async Task<IActionResult> OnPostUploadAsync()
{
if (!ModelState.IsValid)
Expand Down Expand Up @@ -104,15 +96,20 @@ public async Task<IActionResult> OnPostUploadAsync()
}

private async Task RunGetRequest(IEnumerable<string> search, IEnumerable<string> languages,
IEnumerable<string> state, IEnumerable<string> status, IEnumerable<string> type, int pageNo, int pageSize, string sortField)
IEnumerable<string> state, IEnumerable<string> status, IEnumerable<string> type, int pageNo, int pageSize, string sortField, bool fromUrl = true)
{
search = search.Select(x => HttpUtility.UrlDecode(x));
languages = languages.Select(x => HttpUtility.UrlDecode(x));
languages = (fromUrl)? languages.Select(x => HttpUtility.UrlDecode(x)) : languages;
state = state.Select(x => HttpUtility.UrlDecode(x));
status = status.Select(x => HttpUtility.UrlDecode(x));
type = type.Select(x => HttpUtility.UrlDecode(x));

// Update selected properties
if (languages.Any())
{
ReviewsProperties.Languages.Selected = languages;
}

if (state.Any())
{
ReviewsProperties.State.Selected = state;
Expand Down Expand Up @@ -180,7 +177,7 @@ private async Task RunGetRequest(IEnumerable<string> search, IEnumerable<string>

public class ReviewsProperties
{
public (IEnumerable<string> All, IEnumerable<string> Selected) Languages = (All: new List<string>(), Selected: new List<string>());
public (IEnumerable<string> All, IEnumerable<string> Selected) Languages = (All: LanguageServiceHelpers.SupportedLanguages, Selected: new List<string>());
public (IEnumerable<string> All, IEnumerable<string> Selected) State = (All: new List<string> { "Closed", "Open" }, Selected: new List<string> { "Open" });
public (IEnumerable<string> All, IEnumerable<string> Selected) Status = (All: new List<string> { "Approved", "Pending" }, Selected: new List<string>());
public (IEnumerable<string> All, IEnumerable<string> Selected) Type = (All: new List<string> { "Automatic", "Manual", "PullRequest" }, Selected: new List<string>());
Expand Down
12 changes: 6 additions & 6 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@
else
{
@if (Model.Revision.Approvers.Contains(User.GetGitHubLogin()))
{
<div class="d-grid gap-2">
<button type="submit" class="btn btn-outline-secondary" disabled data-bs-placement="bottom" data-bs-toggle="tooltip" title="API review cannot be approved when comparing against unapproved revision.">
{
<div class="d-grid gap-2" data-bs-placement="bottom" data-bs-toggle="tooltip" title="API review cannot be approved when comparing against unapproved revision.">
<button type="submit" class="btn btn-outline-secondary" disabled >
Revert API Approval
</button>
</div>
}
else
{
<div class="d-grid gap-2">
<button type="submit" class="btn btn-outline-secondary" disabled data-bs-placement="bottom" data-bs-toggle="tooltip" title="API review cannot be approved when comparing against unapproved revision.">
{
<div class="d-grid gap-2" data-bs-placement="bottom" data-bs-toggle="tooltip" title="API review cannot be approved when comparing against unapproved revision.">
<button type="submit" class="btn btn-outline-secondary" disabled>
Approve API
</button>
</div>
Expand Down

0 comments on commit 8a7d0e5

Please sign in to comment.