From 4d54c2d238fa888fb5c919ba07dd8aba92746148 Mon Sep 17 00:00:00 2001 From: Felipe da Conceicao Guimaraes Date: Tue, 27 Aug 2024 17:59:57 -0700 Subject: [PATCH 1/4] Injecting in reiew code version --- .../Widgets/GitHubReviewWidget.cs | 38 ++++--------------- .../Widgets/GitHubUserWidget.cs | 37 ++++++++++-------- .../Package-Can.appxmanifest | 2 +- .../Package-Dev.appxmanifest | 2 +- .../Package.appxmanifest | 2 +- 5 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index 7a5c00a..f688141 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -11,11 +11,9 @@ namespace GitHubExtension.Widgets; internal sealed class GitHubReviewWidget : GitHubUserWidget { - public GitHubReviewWidget() - : base() + protected override string GetTitleIconData() { - // This widget does not allow customization, so this value will not change. - ShowCategory = SearchCategory.PullRequests; + return IconLoader.GetIconAsBase64("pulls.png"); } public override void RequestContentData() @@ -25,41 +23,21 @@ public override void RequestContentData() RequestContentData(request); } - 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) { + // This widget does not have the ShowCategory + // property for the user to input, + // so we always put it to PullRequest here. if (actionInvokedArgs.Verb == "Submit") { var data = actionInvokedArgs.Data; var dataObject = JsonNode.Parse(data); - if (dataObject == null) + if (dataObject != null) { - return; + dataObject["showCategory"] = "PullRequests"; + SubmitAction(dataObject.ToString()); } - - DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; - UpdateTitle(dataObject); - - ConfigurationData = data; - - // 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 { diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index ee8ee1b..336ae48 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -135,28 +135,33 @@ public override void OnCustomizationRequested(WidgetCustomizationRequestedArgs c base.OnCustomizationRequested(customizationRequestedArgs); } - public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) + protected void SubmitAction(string data) { - if (actionInvokedArgs.Verb == "Submit") + var dataObject = JsonNode.Parse(data); + + if (dataObject == null) { - var data = actionInvokedArgs.Data; - var dataObject = JsonNode.Parse(data); + return; + } - if (dataObject == null) - { - return; - } + ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? string.Empty); + DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; + UpdateTitle(dataObject); - ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? string.Empty); - DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; - UpdateTitle(dataObject); + ConfigurationData = data; - ConfigurationData = data; + // 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(); + } - // 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(); + public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) + { + if (actionInvokedArgs.Verb == "Submit") + { + var data = actionInvokedArgs.Data; + SubmitAction(data); } else { 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 @@ - + From fa476416a41ac6a8c1a73427dbdfd9778725ccd3 Mon Sep 17 00:00:00 2001 From: Felipe da Conceicao Guimaraes Date: Tue, 27 Aug 2024 18:06:07 -0700 Subject: [PATCH 2/4] Injecting in template version --- .../Widgets/GitHubReviewWidget.cs | 22 ------------------- .../GitHubReviewConfigurationTemplate.json | 13 +++++++++++ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index f688141..29eb512 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -23,28 +23,6 @@ public override void RequestContentData() RequestContentData(request); } - public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) - { - // This widget does not have the ShowCategory - // property for the user to input, - // so we always put it to PullRequest here. - if (actionInvokedArgs.Verb == "Submit") - { - var data = actionInvokedArgs.Data; - var dataObject = JsonNode.Parse(data); - - if (dataObject != null) - { - dataObject["showCategory"] = "PullRequests"; - SubmitAction(dataObject.ToString()); - } - } - else - { - base.OnActionInvoked(actionInvokedArgs); - } - } - public override string GetTemplatePath(WidgetPageState page) { return page switch diff --git a/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json b/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json index f2d150b..00fb626 100644 --- a/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json +++ b/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json @@ -23,6 +23,19 @@ "label": "%Widget_Template/WidgetTitleLabel%", "value": "${widgetTitle}" }, + { + "type": "Input.ChoiceSet", + "id": "showCategory", + "isMultiSelect": false, + "isVisible": false, + "value": "PullRequests", + "choices": [ + { + "title": "%Widget_Template/PullRequests%", + "value": "PullRequests" + } + ] + }, { "type": "ColumnSet", "columns": [ From bfb2a48ec0ac386c3d168b9571376f717ffe282e Mon Sep 17 00:00:00 2001 From: Felipe da Conceicao Guimaraes Date: Wed, 28 Aug 2024 09:33:52 -0700 Subject: [PATCH 3/4] Reverted change in UserWidget class --- .../Widgets/GitHubUserWidget.cs | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index 336ae48..ee8ee1b 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -135,33 +135,28 @@ public override void OnCustomizationRequested(WidgetCustomizationRequestedArgs c base.OnCustomizationRequested(customizationRequestedArgs); } - protected void SubmitAction(string data) + public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) { - var dataObject = JsonNode.Parse(data); - - if (dataObject == null) + if (actionInvokedArgs.Verb == "Submit") { - return; - } + var data = actionInvokedArgs.Data; + var dataObject = JsonNode.Parse(data); - ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? string.Empty); - DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; - UpdateTitle(dataObject); + if (dataObject == null) + { + return; + } - ConfigurationData = data; + ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue() ?? string.Empty); + DeveloperLoginId = dataObject["account"]?.GetValue() ?? string.Empty; + UpdateTitle(dataObject); - // 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(); - } + ConfigurationData = data; - public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) - { - if (actionInvokedArgs.Verb == "Submit") - { - var data = actionInvokedArgs.Data; - SubmitAction(data); + // 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 { From 920107ed462954d3d3224638bc5aa04493872551 Mon Sep 17 00:00:00 2001 From: Felipe da Conceicao Guimaraes Date: Wed, 28 Aug 2024 11:26:41 -0700 Subject: [PATCH 4/4] Better quality of code, no more hacks --- src/GitHubExtension/Widgets/GitHubReviewWidget.cs | 5 ++--- src/GitHubExtension/Widgets/GitHubUserWidget.cs | 6 ++++-- .../GitHubReviewConfigurationTemplate.json | 13 ------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index 29eb512..c0420ac 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -1,16 +1,15 @@ // 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 { + protected override string DefaultShowCategory => "PullRequests"; + protected override string GetTitleIconData() { return IconLoader.GetIconAsBase64("pulls.png"); diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index ee8ee1b..187e640 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 @@ -115,7 +117,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); } @@ -147,7 +149,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/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json b/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json index 00fb626..f2d150b 100644 --- a/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json +++ b/src/GitHubExtension/Widgets/Templates/GitHubReviewConfigurationTemplate.json @@ -23,19 +23,6 @@ "label": "%Widget_Template/WidgetTitleLabel%", "value": "${widgetTitle}" }, - { - "type": "Input.ChoiceSet", - "id": "showCategory", - "isMultiSelect": false, - "isVisible": false, - "value": "PullRequests", - "choices": [ - { - "title": "%Widget_Template/PullRequests%", - "value": "PullRequests" - } - ] - }, { "type": "ColumnSet", "columns": [