Skip to content

Commit

Permalink
Saving the entire URL on the Repository Widgets (#401)
Browse files Browse the repository at this point in the history
* Saving fill URL string on widget

* Saving the URL that is sure to be correct

* Saving the data in the widget service by updating the widget

---------

Co-authored-by: Felipe da Conceicao Guimaraes <[email protected]>
  • Loading branch information
guimafelipe and Felipe da Conceicao Guimaraes authored Jun 10, 2024
1 parent 3777d15 commit 6072955
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public string GetUnescapedIssueQuery()
return Uri.UnescapeDataString(GetIssueQuery()).Replace('+', ' ');
}

// If the user changed the URL after clicking submit and clicked
// saved just after, we change it back to what was before to not corrupt our saved data.
private void CorrectUrl()
{
var configurationData = JsonNode.Parse(ConfigurationData);
if (configurationData != null)
{
configurationData["url"] = RepositoryUrl;
ConfigurationData = configurationData.ToJsonString();
UpdateWidget();
}
}

public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs)
{
var verb = GetWidgetActionForVerb(actionInvokedArgs.Verb);
Expand All @@ -60,6 +73,7 @@ public override void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs)
case WidgetAction.Save:
UpdateTitle(JsonNode.Parse(actionInvokedArgs.Data));
base.OnActionInvoked(actionInvokedArgs);
CorrectUrl();
break;

default:
Expand Down Expand Up @@ -256,7 +270,7 @@ public string GetConfiguration(string dataUrl)
{ "owner", repository.Owner.Login },
{ "milestone", string.Empty },
{ "project", repository.Description },
{ "url", repository.HtmlUrl },
{ "url", RepositoryUrl },
{ "query", GetUnescapedIssueQuery() },
};

Expand Down

0 comments on commit 6072955

Please sign in to comment.