Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review requested widget now is customizable #440

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 4 additions & 49 deletions src/GitHubExtension/Widgets/GitHubReviewWidget.cs
Original file line number Diff line number Diff line change
@@ -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>() ?? 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)
Expand Down
6 changes: 4 additions & 2 deletions src/GitHubExtension/Widgets/GitHubUserWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,7 +117,7 @@ protected override void ResetWidgetInfoFromState()
try
{
dataObject ??= JsonNode.Parse(ConfigurationData);
ShowCategory = EnumHelper.StringToSearchCategory(dataObject!["showCategory"]?.GetValue<string>() ?? string.Empty);
ShowCategory = EnumHelper.StringToSearchCategory(dataObject!["showCategory"]?.GetValue<string>() ?? DefaultShowCategory);
DeveloperLoginId = dataObject!["account"]?.GetValue<string>() ?? string.Empty;
UpdateTitle(dataObject);
}
Expand Down Expand Up @@ -147,7 +149,7 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs)
return;
}

ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue<string>() ?? string.Empty);
ShowCategory = EnumHelper.StringToSearchCategory(dataObject["showCategory"]?.GetValue<string>() ?? DefaultShowCategory);
DeveloperLoginId = dataObject["account"]?.GetValue<string>() ?? string.Empty;
UpdateTitle(dataObject);

Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtensionServer/Package-Can.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</LightMode>
</ThemeResources>
</Definition>
<Definition Id="GitHub_Reviews" DisplayName="ms-resource:Widget_DisplayName_Reviews" Description="ms-resource:Widget_Description_Reviews" IsCustomizable="false">
<Definition Id="GitHub_Reviews" DisplayName="ms-resource:Widget_DisplayName_Reviews" Description="ms-resource:Widget_Description_Reviews" IsCustomizable="true">
<Capabilities>
<Capability>
<Size Name="medium" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtensionServer/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</LightMode>
</ThemeResources>
</Definition>
<Definition Id="GitHub_Reviews" DisplayName="ms-resource:Widget_DisplayName_Reviews" Description="ms-resource:Widget_Description_Reviews" IsCustomizable="false">
<Definition Id="GitHub_Reviews" DisplayName="ms-resource:Widget_DisplayName_Reviews" Description="ms-resource:Widget_Description_Reviews" IsCustomizable="true">
<Capabilities>
<Capability>
<Size Name="medium" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtensionServer/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</LightMode>
</ThemeResources>
</Definition>
<Definition Id="GitHub_Reviews" DisplayName="ms-resource:Widget_DisplayName_Reviews" Description="ms-resource:Widget_Description_Reviews" IsCustomizable="false">
<Definition Id="GitHub_Reviews" DisplayName="ms-resource:Widget_DisplayName_Reviews" Description="ms-resource:Widget_Description_Reviews" IsCustomizable="true">
<Capabilities>
<Capability>
<Size Name="medium" />
Expand Down
Loading