From 8a7d0e5fbd469430261ed9dc718d3adb482fc82a Mon Sep 17 00:00:00 2001 From: "Chidozie Ononiwu (His Righteousness)" <31145988+chidozieononiwu@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:47:02 -0800 Subject: [PATCH] Don't load languages list from server (#5579) * Don't load languages list from server * Ensure tooltip is visible when approved button is disabled --- .../APIViewWeb/Client/src/pages/index.ts | 24 +------------- .../Helpers/LanguageServiceHelpers.cs | 7 +++++ .../APIViewWeb/Languages/LanguageService.cs | 3 +- .../Pages/Assemblies/Index.cshtml.cs | 31 +++++++++---------- .../APIViewWeb/Pages/Assemblies/Review.cshtml | 12 +++---- 5 files changed, 30 insertions(+), 47 deletions(-) create mode 100644 src/dotnet/APIView/APIViewWeb/Helpers/LanguageServiceHelpers.cs diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/pages/index.ts b/src/dotnet/APIView/APIViewWeb/Client/src/pages/index.ts index df445fbbd8f..6d968151b5f 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/pages/index.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/pages/index.ts @@ -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); - (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 + (languageFilter).SumoSelect({ selectAll: true }); (stateFilter).SumoSelect({ selectAll: true }); (statusFilter).SumoSelect({ selectAll: true }); (typeFilter).SumoSelect({ selectAll: true }); diff --git a/src/dotnet/APIView/APIViewWeb/Helpers/LanguageServiceHelpers.cs b/src/dotnet/APIView/APIViewWeb/Helpers/LanguageServiceHelpers.cs new file mode 100644 index 00000000000..9bb811aa914 --- /dev/null +++ b/src/dotnet/APIView/APIViewWeb/Helpers/LanguageServiceHelpers.cs @@ -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" }; + } +} diff --git a/src/dotnet/APIView/APIViewWeb/Languages/LanguageService.cs b/src/dotnet/APIView/APIViewWeb/Languages/LanguageService.cs index 8a634825910..a10ad6bf2c7 100644 --- a/src/dotnet/APIView/APIViewWeb/Languages/LanguageService.cs +++ b/src/dotnet/APIView/APIViewWeb/Languages/LanguageService.cs @@ -7,6 +7,7 @@ using APIViewWeb.Models; using Microsoft.ApplicationInsights.Extensibility; using Microsoft.ApplicationInsights; +using APIViewWeb.Helpers; namespace APIViewWeb { @@ -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; diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs index bd7cce29ecc..f33f3eaeb73 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs @@ -12,6 +12,7 @@ using APIViewWeb.Managers; using Octokit; using Microsoft.TeamFoundation.Common; +using APIViewWeb.Helpers; namespace APIViewWeb.Pages.Assemblies { @@ -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 OnGetReviewsPartialAsync( @@ -64,19 +69,6 @@ public async Task OnGetReviewsPartialAsync( return Partial("_ReviewsPartial", PagedResults); } - public async Task OnGetReviewsLanguagesAsync(IEnumerable 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 OnPostUploadAsync() { if (!ModelState.IsValid) @@ -104,15 +96,20 @@ public async Task OnPostUploadAsync() } private async Task RunGetRequest(IEnumerable search, IEnumerable languages, - IEnumerable state, IEnumerable status, IEnumerable type, int pageNo, int pageSize, string sortField) + IEnumerable state, IEnumerable status, IEnumerable 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; @@ -180,7 +177,7 @@ private async Task RunGetRequest(IEnumerable search, IEnumerable public class ReviewsProperties { - public (IEnumerable All, IEnumerable Selected) Languages = (All: new List(), Selected: new List()); + public (IEnumerable All, IEnumerable Selected) Languages = (All: LanguageServiceHelpers.SupportedLanguages, Selected: new List()); public (IEnumerable All, IEnumerable Selected) State = (All: new List { "Closed", "Open" }, Selected: new List { "Open" }); public (IEnumerable All, IEnumerable Selected) Status = (All: new List { "Approved", "Pending" }, Selected: new List()); public (IEnumerable All, IEnumerable Selected) Type = (All: new List { "Automatic", "Manual", "PullRequest" }, Selected: new List()); diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index c0e64b2f837..c96f68d8eab 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -72,17 +72,17 @@ else { @if (Model.Revision.Approvers.Contains(User.GetGitHubLogin())) - { -
-
} else - { -
-