Skip to content

Commit

Permalink
Don't load languages list from server
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Feb 28, 2023
1 parent 8f65722 commit f8b5a0c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 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

0 comments on commit f8b5a0c

Please sign in to comment.