From 00b56ad3ce8bfb485c7999a2c133217e7b791341 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 14 Aug 2024 10:57:34 -0700 Subject: [PATCH 1/4] Simplifying Issues and Pull Requests Widgets customization (#424) * Removing check url and adding first version of dropdown * Fixing save bug and adding loop to get repos from RepositoryProvider * Adding changes on issues template * Removing known repos code * Cleaning up code --------- Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubRepositoryWidget.cs | 110 +++++++----------- .../GitHubIssuesConfigurationTemplate.json | 11 +- .../GitHubPullsConfigurationTemplate.json | 11 +- 3 files changed, 48 insertions(+), 84 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 067b36a..582ac2d 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -5,7 +5,6 @@ using System.Text.Json.Nodes; using GitHubExtension.Client; using GitHubExtension.DataManager; -using GitHubExtension.Helpers; using GitHubExtension.Widgets.Enums; using Microsoft.Windows.Widgets.Providers; @@ -15,6 +14,8 @@ public abstract class GitHubRepositoryWidget : GitHubWidget { protected string RepositoryUrl { get; set; } = string.Empty; + private string? _message; + public GitHubRepositoryWidget() : base() { @@ -66,14 +67,14 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) switch (verb) { - case WidgetAction.CheckUrl: - HandleCheckUrl(actionInvokedArgs); - break; - case WidgetAction.Save: - UpdateTitle(JsonNode.Parse(actionInvokedArgs.Data)); - base.OnActionInvoked(actionInvokedArgs); - CorrectUrl(); + if (HandleCheckUrl(actionInvokedArgs)) + { + UpdateTitle(JsonNode.Parse(actionInvokedArgs.Data)); + base.OnActionInvoked(actionInvokedArgs); + CorrectUrl(); + } + break; default: @@ -144,7 +145,14 @@ private void UpdateTitle(JsonNode? dataObj) GetTitleFromDataObject(dataObj); if (string.IsNullOrEmpty(WidgetTitle)) { - WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; + try + { + WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; + } + catch + { + WidgetTitle = string.Empty; + } } } @@ -207,7 +215,7 @@ public override void OnCustomizationRequested(WidgetCustomizationRequestedArgs c base.OnCustomizationRequested(customizationRequestedArgs); } - private void HandleCheckUrl(WidgetActionInvokedArgs args) + private bool HandleCheckUrl(WidgetActionInvokedArgs args) { // Set loading page while we fetch data from GitHub. Page = WidgetPageState.Loading; @@ -223,7 +231,19 @@ private void HandleCheckUrl(WidgetActionInvokedArgs args) RepositoryUrl = dataObject["url"]?.GetValue() ?? string.Empty; UpdateTitle(dataObject); - ConfigurationData = data; + var isGoodToSave = true; + + try + { + GetRepositoryFromUrl(RepositoryUrl); + ConfigurationData = data; + _message = null; + } + catch (Exception ex) + { + _message = ex.Message; + isGoodToSave = false; + } var updateRequestOptions = new WidgetUpdateRequestOptions(Id) { @@ -233,71 +253,29 @@ private void HandleCheckUrl(WidgetActionInvokedArgs args) }; WidgetManager.GetDefault().UpdateWidget(updateRequestOptions); + + // Already shown error message while updating above, + // can reset it to null here. + _message = null; + return isGoodToSave; } + + UpdateWidget(); + + return false; } public string GetConfiguration(string dataUrl) { var configurationData = new JsonObject { - { "submitIcon", IconLoader.GetIconAsBase64("arrow.png") }, { "widgetTitle", WidgetTitle }, + { "url", dataUrl }, + { "savedRepositoryUrl", SavedConfigurationData }, + { "errorMessage", _message }, }; - if (dataUrl == string.Empty) - { - configurationData.Add("hasConfiguration", false); - var repositoryData = new JsonObject - { - { "url", string.Empty }, - }; - - configurationData.Add("configuration", repositoryData); - configurationData.Add("savedRepositoryUrl", SavedConfigurationData); - configurationData.Add("saveEnabled", false); - - return configurationData.ToString(); - } - else - { - try - { - var repository = GetRepositoryFromUrl(dataUrl); - var repositoryData = new JsonObject - { - { "name", repository.FullName }, - { "label", repository.Name }, - { "owner", repository.Owner.Login }, - { "milestone", string.Empty }, - { "project", repository.Description }, - { "url", RepositoryUrl }, - { "query", GetUnescapedIssueQuery() }, - }; - - configurationData.Add("hasConfiguration", true); - configurationData.Add("configuration", repositoryData); - configurationData.Add("savedRepositoryUrl", SavedConfigurationData); - configurationData.Add("saveEnabled", true); - } - catch (Exception ex) - { - Log.Error(ex, $"Failed getting configuration information for input url: {dataUrl}"); - configurationData.Add("hasConfiguration", false); - - var repositoryData = new JsonObject - { - { "url", RepositoryUrl }, - }; - - configurationData.Add("errorMessage", ex.Message); - configurationData.Add("configuration", repositoryData); - configurationData.Add("saveEnabled", false); - - return configurationData.ToString(); - } - - return configurationData.ToJsonString(); - } + return configurationData.ToJsonString(); } public override string GetData(WidgetPageState page) diff --git a/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json b/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json index 0333c9a..3359318 100644 --- a/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json +++ b/src/GitHubExtension/Widgets/Templates/GitHubIssuesConfigurationTemplate.json @@ -7,16 +7,10 @@ "type": "Input.Text", "id": "url", "label": "%Widget_Template_Label/Url%", - "inlineAction": { - "type": "Action.Execute", - "tooltip": "%Widget_Template_Tooltip/Submit%", - "verb": "CheckUrl", - "iconUrl": "data:image/png;base64,${submitIcon}" - }, "spacing": "Medium", "style": "Url", "placeholder": "%Widget_Template_Input/UrlPlaceholder%", - "value": "${$root.configuration.url}" + "value": "${url}" }, { "type": "Input.Text", @@ -115,8 +109,7 @@ "type": "Action.Execute", "title": "%Widget_Template_Button/Save%", "verb": "Save", - "tooltip": "%Widget_Template_Tooltip/Save%", - "isEnabled": "${$root.saveEnabled}" + "tooltip": "%Widget_Template_Tooltip/Save%" }, { "type": "Action.Execute", diff --git a/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json b/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json index 881d356..15cbd87 100644 --- a/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json +++ b/src/GitHubExtension/Widgets/Templates/GitHubPullsConfigurationTemplate.json @@ -7,16 +7,10 @@ "type": "Input.Text", "id": "url", "label": "%Widget_Template_Label/Url%", - "inlineAction": { - "type": "Action.Execute", - "tooltip": "%Widget_Template_Tooltip/Submit%", - "verb": "CheckUrl", - "iconUrl": "data:image/png;base64,${submitIcon}" - }, "spacing": "Medium", "style": "Url", "placeholder": "%Widget_Template_Input/UrlPlaceholder%", - "value": "${$root.configuration.url}" + "value": "${url}" }, { "type": "Input.Text", @@ -100,8 +94,7 @@ "type": "Action.Execute", "title": "%Widget_Template_Button/Save%", "verb": "Save", - "tooltip": "%Widget_Template_Tooltip/Save%", - "isEnabled": "${saveEnabled}" + "tooltip": "%Widget_Template_Tooltip/Save%" }, { "type": "Action.Execute", From 0fbabbef70e6fc88321e5e6cf965ffaa03019281 Mon Sep 17 00:00:00 2001 From: Vineeth Thomas Alex Date: Fri, 16 Aug 2024 14:09:06 -0500 Subject: [PATCH 2/4] Add JsonSerializerIsReflectionEnabledByDefault to props file (#431) Co-authored-by: Vineeth Thomas Alex --- Directory.Build.props | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index c6c3307..3a872c8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -55,4 +55,8 @@ + + + true + \ No newline at end of file From 00d2e88c5806a7a39e7232d3a9240ec54b9c7238 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 28 Aug 2024 12:02:29 -0700 Subject: [PATCH 3/4] Making default titles not be saved in data (#439) Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubIssuesWidget.cs | 2 +- src/GitHubExtension/Widgets/GitHubPullsWidget.cs | 2 +- .../Widgets/GitHubReleasesWidget.cs | 2 +- .../Widgets/GitHubRepositoryWidget.cs | 16 +++++----------- src/GitHubExtension/Widgets/GitHubUserWidget.cs | 16 +++++++++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs index 7d895e6..355012e 100644 --- a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs @@ -152,7 +152,7 @@ public override void LoadContentData() issuesData.Add("issues", issuesArray); issuesData.Add("selected_repo", repository?.FullName ?? string.Empty); - issuesData.Add("widgetTitle", WidgetTitle); + issuesData.Add("widgetTitle", GetActualTitle()); issuesData.Add("is_loading_data", DataState == WidgetDataState.Unknown); issuesData.Add("issues_icon_data", _issuesIconData); diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs index fad9d23..54691b8 100644 --- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs @@ -123,7 +123,7 @@ public override void LoadContentData() pullsData.Add("pulls", pullsArray); pullsData.Add("selected_repo", repository?.FullName ?? string.Empty); - pullsData.Add("widgetTitle", WidgetTitle); + pullsData.Add("widgetTitle", GetActualTitle()); pullsData.Add("is_loading_data", DataState == WidgetDataState.Unknown); pullsData.Add("pulls_icon_data", _pullsIconData); diff --git a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs index 5b3d708..5358c8d 100644 --- a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs @@ -121,7 +121,7 @@ public override void LoadContentData() releasesData.Add("releases", releasesArray); releasesData.Add("selected_repo", repository?.FullName ?? string.Empty); - releasesData.Add("widgetTitle", WidgetTitle); + releasesData.Add("widgetTitle", GetActualTitle()); releasesData.Add("is_loading_data", DataState == WidgetDataState.Unknown); releasesData.Add("releases_icon_data", _releasesIconData); diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 582ac2d..2311b42 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -143,17 +143,11 @@ private void UpdateTitle(JsonNode? dataObj) } GetTitleFromDataObject(dataObj); - if (string.IsNullOrEmpty(WidgetTitle)) - { - try - { - WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; - } - catch - { - WidgetTitle = string.Empty; - } - } + } + + protected string GetActualTitle() + { + return string.IsNullOrEmpty(WidgetTitle) ? GetRepositoryFromUrl(RepositoryUrl).FullName : WidgetTitle; } protected override void ResetWidgetInfoFromState() diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index ee8ee1b..b83901c 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -57,11 +57,17 @@ public override void OnWidgetContextChanged(WidgetContextChangedArgs contextChan protected void UpdateTitle(JsonNode dataObj) { - GetTitleFromDataObject(dataObj); - if (string.IsNullOrEmpty(WidgetTitle)) + if (dataObj == null) { - WidgetTitle = UserName; + return; } + + GetTitleFromDataObject(dataObj); + } + + protected string GetActualTitle() + { + return string.IsNullOrEmpty(WidgetTitle) ? UserName : WidgetTitle; } protected override void ResetWidgetInfoFromState() @@ -249,7 +255,7 @@ public override void LoadContentData() { "openCount", 0 }, { "items", new JsonArray() }, { "userName", UserName }, - { "widgetTitle", WidgetTitle }, + { "widgetTitle", GetActualTitle() }, { "titleIconUrl", GetTitleIconData() }, { "is_loading_data", true }, }; @@ -302,7 +308,7 @@ public void LoadContentData(IEnumerable items) issuesData.Add("items", issuesArray); issuesData.Add("userName", UserName); issuesData.Add("titleIconUrl", GetTitleIconData()); - issuesData.Add("widgetTitle", WidgetTitle); + issuesData.Add("widgetTitle", GetActualTitle()); LastUpdated = DateTime.Now; ContentData = issuesData.ToJsonString(); From 0fb5d2348c60b75f25b311392775b548b8450593 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 28 Aug 2024 14:57:05 -0700 Subject: [PATCH 4/4] Review requested widget now is customizable (#440) * Injecting in reiew code version * Injecting in template version * Reverted change in UserWidget class * Better quality of code, no more hacks --------- Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubReviewWidget.cs | 53 ++----------------- .../Widgets/GitHubUserWidget.cs | 6 ++- .../Package-Can.appxmanifest | 2 +- .../Package-Dev.appxmanifest | 2 +- .../Package.appxmanifest | 2 +- 5 files changed, 11 insertions(+), 54 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index 7a5c00a..c0420ac 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -1,70 +1,25 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System.Text.Json.Nodes; -using GitHubExtension.DataManager; using GitHubExtension.Helpers; -using Microsoft.Windows.Widgets.Providers; using Octokit; namespace GitHubExtension.Widgets; internal sealed class GitHubReviewWidget : GitHubUserWidget { - public GitHubReviewWidget() - : base() - { - // This widget does not allow customization, so this value will not change. - ShowCategory = SearchCategory.PullRequests; - } - - public override void RequestContentData() - { - var request = new SearchIssuesRequest($"review-requested:{UserName}"); - - RequestContentData(request); - } + protected override string DefaultShowCategory => "PullRequests"; protected override string GetTitleIconData() { return IconLoader.GetIconAsBase64("pulls.png"); } - // This widget does not have "ShowCategory" as a variable. - // So we override this method to not care about this data. - protected override void ResetWidgetInfoFromState() - { - base.ResetWidgetInfoFromState(); - ShowCategory = SearchCategory.PullRequests; - } - - // Overriding this method because this widget only cares about the account. - public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) + public override void RequestContentData() { - if (actionInvokedArgs.Verb == "Submit") - { - var data = actionInvokedArgs.Data; - var dataObject = JsonNode.Parse(data); - - if (dataObject == null) - { - return; - } - - DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; - UpdateTitle(dataObject); - - ConfigurationData = data; + var request = new SearchIssuesRequest($"review-requested:{UserName}"); - // If we got here during the customization flow, we need to LoadContentData again - // so we can show the loading page rather than stale data. - LoadContentData(); - UpdateActivityState(); - } - else - { - base.OnActionInvoked(actionInvokedArgs); - } + RequestContentData(request); } public override string GetTemplatePath(WidgetPageState page) diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index b83901c..27e98de 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -19,6 +19,8 @@ internal abstract class GitHubUserWidget : GitHubWidget protected SearchCategory ShowCategory { get; set; } = SearchCategory.Unknown; + protected virtual string DefaultShowCategory => string.Empty; + private string _userName = string.Empty; protected string UserName @@ -121,7 +123,7 @@ protected override void ResetWidgetInfoFromState() try { dataObject ??= JsonNode.Parse(ConfigurationData); - ShowCategory = EnumHelper.StringToSearchCategory(dataObject!["showCategory"]?.GetValue() ?? string.Empty); + ShowCategory = EnumHelper.StringToSearchCategory(dataObject!["showCategory"]?.GetValue() ?? DefaultShowCategory); DeveloperLoginId = dataObject!["account"]?.GetValue() ?? string.Empty; UpdateTitle(dataObject); } @@ -153,7 +155,7 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) return; } - ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? string.Empty); + ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? DefaultShowCategory); DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; UpdateTitle(dataObject); diff --git a/src/GitHubExtensionServer/Package-Can.appxmanifest b/src/GitHubExtensionServer/Package-Can.appxmanifest index 6fb37d8..8f0db6d 100644 --- a/src/GitHubExtensionServer/Package-Can.appxmanifest +++ b/src/GitHubExtensionServer/Package-Can.appxmanifest @@ -212,7 +212,7 @@ - + diff --git a/src/GitHubExtensionServer/Package-Dev.appxmanifest b/src/GitHubExtensionServer/Package-Dev.appxmanifest index 92db75b..861e773 100644 --- a/src/GitHubExtensionServer/Package-Dev.appxmanifest +++ b/src/GitHubExtensionServer/Package-Dev.appxmanifest @@ -212,7 +212,7 @@ - + diff --git a/src/GitHubExtensionServer/Package.appxmanifest b/src/GitHubExtensionServer/Package.appxmanifest index 6895de1..785a937 100644 --- a/src/GitHubExtensionServer/Package.appxmanifest +++ b/src/GitHubExtensionServer/Package.appxmanifest @@ -212,7 +212,7 @@ - +