Skip to content

Commit

Permalink
Merge pull request #1529 from riganti/fix/routelink-urlsuffix-unwrap
Browse files Browse the repository at this point in the history
Fix RouteLink.UrlSuffix={value: Property}
  • Loading branch information
exyi authored Dec 10, 2022
2 parents 97179c4 + 4e6daf3 commit 8e61050
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Framework/Controls/RouteLinkHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static string GenerateKnockoutHrefExpression(string routeName, RouteLink
{
var urlSuffixBase =
control.GetValueBinding(RouteLink.UrlSuffixProperty)
?.Apply(binding => binding.GetKnockoutBindingExpression(control))
?.Apply(binding => binding.GetKnockoutBindingExpression(control, unwrapped: true))
?? KnockoutHelper.MakeStringLiteral(control.UrlSuffix ?? "");
var queryParamsArray = control.QueryParameters.RawValues.ToArray();
Array.Sort(queryParamsArray, (a, b) => a.Key.CompareTo(b.Key)); // deterministic order of query params
Expand Down
11 changes: 8 additions & 3 deletions src/Tests/ControlTests/SimpleControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,32 @@ public async Task RouteLink()
<dot:RouteLink RenderSettings.Mode=Client RouteName=Simple Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix='#mySuffix' />
<!-- client rendering, no params, text binding -->
<dot:RouteLink RenderSettings.Mode=Client RouteName=Simple Text={value: Label} />
<!-- client rendering, dynamic suffix -->
<dot:RouteLink RenderSettings.Mode=Client RouteName=Simple Text='Click me' UrlSuffix={value: UrlSuffix} />
<!-- server rendering, no params -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=Simple Text='Click me' />
<!-- server rendering, no params, query and suffix -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=Simple Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix='#mySuffix' />
<!-- server rendering, no params, text binding -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=Simple Text={value: Label} />
<!-- server rendering, dynamic suffix -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=Simple Text='Click me' UrlSuffix={value: UrlSuffix} />
<!-- client rendering, static params -->
<dot:RouteLink RenderSettings.Mode=Client RouteName={resource: 'WithParams'} Param-A=A Param-B={resource: 1} Text='Click me' />
<!-- client rendering, static params, query and suffix -->
<dot:RouteLink RenderSettings.Mode=Client RouteName=WithParams Param-A=A Param-B={resource: 1} Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix='#mySuffix' />
<!-- client rendering, dynamic params, query and suffix -->
<dot:RouteLink RenderSettings.Mode=Client RouteName=WithParams Param-A={value: Label} Param-B={value: Integer} Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix='#mySuffix' />
<dot:RouteLink RenderSettings.Mode=Client RouteName=WithParams Param-A={value: Label} Param-B={value: Integer} Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix={value: UrlSuffix} />
<!-- client rendering, static params, text binding -->
<dot:RouteLink RenderSettings.Mode=Client RouteName=WithParams Param-A=A Param-B=1 Text={value: Label} />
<!-- server rendering, static params -->
<dot:RouteLink RenderSettings.Mode=Server RouteName={resource: 'WithParams'} Param-A=A Param-B={resource: 1} Text='Click me' />
<!-- server rendering, static params, query and suffix -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=WithParams Param-a=A Param-B={resource: 1} Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix='#mySuffix' />
<!-- server rendering, dynamic params, query and suffix -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=WithParams Param-A={value: Label} Param-b={value: Integer} Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix='#mySuffix' />
<dot:RouteLink RenderSettings.Mode=Server RouteName=WithParams Param-A={value: Label} Param-b={value: Integer} Text='Click me' Query-Binding={value: Integer} Query-Constant='c/y' UrlSuffix={value: UrlSuffix} />
<!-- server rendering, static params, text binding -->
<dot:RouteLink RenderSettings.Mode=Server RouteName=WithParams Param-A=A Param-B=1 Text={value: Label} />
"
Expand Down Expand Up @@ -458,6 +461,8 @@ public class BasicTestViewModel: DotvvmViewModelBase

public int[] IntArray { get; set; }

public string UrlSuffix { get; set; } = "#something";

public GridViewDataSet<CustomerData> Customers { get; set; } = new GridViewDataSet<CustomerData>() {
RowEditOptions = {
EditRowId = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<!-- client rendering, no params, text binding -->
<a data-bind="text: Label" href="/Simple" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">My Label</a>

<!-- client rendering, dynamic suffix -->
<a data-bind="attr: { href: '/' + &quot;Simple&quot; + UrlSuffix() }" href="/Simple#something" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- server rendering, no params -->
<a href="/Simple" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

Expand All @@ -20,14 +23,17 @@
<!-- server rendering, no params, text binding -->
<a data-bind="text: Label" href="/Simple" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">My Label</a>

<!-- server rendering, dynamic suffix -->
<a data-bind="attr: { href: '/' + &quot;Simple&quot; + UrlSuffix() }" href="/Simple#something" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- client rendering, static params -->
<a href="/WithParams/A-1" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- client rendering, static params, query and suffix -->
<a data-bind="attr: { href: '/' + dotvvm.buildRouteUrl(&quot;WithParams/{a}-{b}/{c}&quot;, {&quot;b&quot;: 1,&quot;a&quot;: &quot;A&quot;}) + dotvvm.buildUrlSuffix(&quot;#mySuffix&quot;, {&quot;Binding&quot;: int,&quot;Constant&quot;: &quot;c/y&quot;}) }" href="/WithParams/A-1?Binding=10000000&amp;Constant=c%2Fy#mySuffix" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- client rendering, dynamic params, query and suffix -->
<a data-bind="attr: { href: '/' + dotvvm.buildRouteUrl(&quot;WithParams/{a}-{b}/{c}&quot;, {&quot;b&quot;: int,&quot;a&quot;: Label}) + dotvvm.buildUrlSuffix(&quot;#mySuffix&quot;, {&quot;Binding&quot;: int,&quot;Constant&quot;: &quot;c/y&quot;}) }" href="/WithParams/My%20Label-10000000?Binding=10000000&amp;Constant=c%2Fy#mySuffix" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>
<a data-bind="attr: { href: '/' + dotvvm.buildRouteUrl(&quot;WithParams/{a}-{b}/{c}&quot;, {&quot;b&quot;: int,&quot;a&quot;: Label}) + dotvvm.buildUrlSuffix(UrlSuffix(), {&quot;Binding&quot;: int,&quot;Constant&quot;: &quot;c/y&quot;}) }" href="/WithParams/My%20Label-10000000?Binding=10000000&amp;Constant=c%2Fy#something" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- client rendering, static params, text binding -->
<a data-bind="text: Label" href="/WithParams/A-1" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">My Label</a>
Expand All @@ -39,7 +45,7 @@
<a data-bind="attr: { href: '/' + dotvvm.buildRouteUrl(&quot;WithParams/{a}-{b}/{c}&quot;, {&quot;b&quot;: 1,&quot;a&quot;: &quot;A&quot;}) + dotvvm.buildUrlSuffix(&quot;#mySuffix&quot;, {&quot;Binding&quot;: int,&quot;Constant&quot;: &quot;c/y&quot;}) }" href="/WithParams/A-1?Binding=10000000&amp;Constant=c%2Fy#mySuffix" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- server rendering, dynamic params, query and suffix -->
<a data-bind="attr: { href: '/' + dotvvm.buildRouteUrl(&quot;WithParams/{a}-{b}/{c}&quot;, {&quot;b&quot;: int,&quot;a&quot;: Label}) + dotvvm.buildUrlSuffix(&quot;#mySuffix&quot;, {&quot;Binding&quot;: int,&quot;Constant&quot;: &quot;c/y&quot;}) }" href="/WithParams/My%20Label-10000000?Binding=10000000&amp;Constant=c%2Fy#mySuffix" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>
<a data-bind="attr: { href: '/' + dotvvm.buildRouteUrl(&quot;WithParams/{a}-{b}/{c}&quot;, {&quot;b&quot;: int,&quot;a&quot;: Label}) + dotvvm.buildUrlSuffix(UrlSuffix(), {&quot;Binding&quot;: int,&quot;Constant&quot;: &quot;c/y&quot;}) }" href="/WithParams/My%20Label-10000000?Binding=10000000&amp;Constant=c%2Fy#something" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">Click me</a>

<!-- server rendering, static params, text binding -->
<a data-bind="text: Label" href="/WithParams/A-1" onclick="event.stopPropagation();return !this.hasAttribute('disabled');">My Label</a>
Expand Down

0 comments on commit 8e61050

Please sign in to comment.